Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Interface::Builder #1081

Merged
merged 10 commits into from
Mar 21, 2024
18 changes: 11 additions & 7 deletions lib/steep.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,19 @@ def self.log_output=(output)
@ui_logger = nil
self.log_output = STDERR

def self.measure(message, level: :warn)
def self.measure(message, level: :warn, threshold: 0.0)
start = Time.now
yield
ensure
time = Time.now - start
if level.is_a?(Symbol)
level = Logger.const_get(level.to_s.upcase)
begin
yield
ensure
time = Time.now - start
if level.is_a?(Symbol)
level = Logger.const_get(level.to_s.upcase)
end
if time > threshold
self.logger.log(level) { "#{message} took #{time} seconds" }
end
end
self.logger.log(level) { "#{message} took #{time} seconds" }
end

def self.log_error(exn, message: "Unexpected error: #{exn.inspect}")
Expand Down
4 changes: 4 additions & 0 deletions lib/steep/ast/types/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ def each_child(&block)
enum_for :each_child
end
end

def map_type
self
end
end
end
end
Expand Down
7 changes: 7 additions & 0 deletions lib/steep/ast/types/intersection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ def each_child(&block)
end
end

def map_type(&block)
self.class.build(
types: each_child.map(&block),
location: location
)
end

def level
[0] + level_of_children(types)
end
Expand Down
7 changes: 7 additions & 0 deletions lib/steep/ast/types/record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ def each_child(&block)
end
end

def map_type(&block)
self.class.new(
elements: elements.transform_values(&block),
location: location
)
end

def level
[0] + level_of_children(elements.values)
end
Expand Down
7 changes: 7 additions & 0 deletions lib/steep/ast/types/tuple.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ def each_child(&block)
end
end

def map_type(&block)
Tuple.new(
types: types.map(&block),
location: location
)
end

def level
[0] + level_of_children(types)
end
Expand Down
7 changes: 7 additions & 0 deletions lib/steep/ast/types/union.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ def each_child(&block)
end
end

def map_type(&block)
Union.build(
types: types.map(&block),
location: location
)
end

include Helper::ChildrenLevel

def level
Expand Down
4 changes: 2 additions & 2 deletions lib/steep/drivers/stats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def print(stats_result)
end
end

table = Terminal::Table.new(
table = Terminal::Table.new( # steep:ignore UnknownConstant
headings: ["Target", "File", "Status", "Typed calls", "Untyped calls", "All calls", "Typed %"],
rows: rows
)
Expand Down Expand Up @@ -166,7 +166,7 @@ def run
{
id: stats_id,
method: "workspace/executeCommand",
params: { command: "steep/stats", arguments: [] }
params: { command: "steep/stats", arguments: _ = [] }
})

stats_response = wait_for_response_id(reader: client_reader, id: stats_id)
Expand Down
6 changes: 4 additions & 2 deletions lib/steep/drivers/validate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ def run
if buffer
printer = DiagnosticPrinter.new(stdout: stdout, buffer: buffer)
ds.each do |d|
printer.print(d)
stdout.puts
if d
printer.print(_ = d)
stdout.puts
end
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/steep/expectations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def self.from_hash(hash)
:information
when "HINT"
:hint
end #: Diagnostic::LSPFormatter::severity
end #: Steep::Diagnostic::LSPFormatter::severity

Diagnostic.new(
start_position: start_position,
Expand Down Expand Up @@ -56,7 +56,7 @@ def self.from_lsp(diagnostic)
:hint
else
:error
end #: Diagnostic::LSPFormatter::severity
end #: Steep::Diagnostic::LSPFormatter::severity

Diagnostic.new(
start_position: start_position,
Expand Down
Loading