Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/typeprof/core/ast/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def initialize(sym, code_range, ret)
@ret = ret
end

attr_reader :lenv, :prev_node, :ret
attr_reader :lenv, :prev_node, :code_range, :ret

def boxes(_)
[]
Expand Down
19 changes: 7 additions & 12 deletions lib/typeprof/core/ast/method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,23 @@ module TypeProf::Core
class AST
def self.get_rbs_comment_before(raw_node, lenv)
comments = Fiber[:comments]
i = comments.bsearch_index {|comment| comment.location.start_line >= raw_node.location.start_line } || comments.size
lineno = raw_node.location.start_line
node_line = raw_node.location.start_line
last_comment_index = comments.bsearch_index {|c| c.location.start_line >= node_line } || comments.size
rbs_comments = []
while i > 0
i -= 1
lineno -= 1
expected_line = node_line - 1
(last_comment_index - 1).downto(0) do |i|
comment = comments[i]
break unless comment.location.start_line == expected_line && comment.location.slice.start_with?("#:")
comment_loc = comment.location
comment_text = comment_loc.slice
if comment_loc.start_line == lineno && comment_text.start_with?("#:")
rbs_comments[comment_loc.start_line] = " " * (comment_loc.start_column + 2) + comment_text[2..]
else
break
end
rbs_comments[comment_loc.start_line - 1] = " " * (comment_loc.start_column + 2) + comment_text[2..]
expected_line -= 1
end
return nil if rbs_comments.empty?
rbs_comments = rbs_comments.map {|line| line || "" }.join("\n")
method_type = RBS::Parser.parse_method_type(rbs_comments)
if method_type
AST.create_rbs_func_type(method_type, method_type.type_params, method_type.block, lenv)
else
nil
end
rescue RBS::ParsingError
# TODO: report the error
Expand Down
18 changes: 16 additions & 2 deletions scenario/rbs/inline-hover.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
## update: test.rb
#: (Integer) -> void
def check(var) # TODO: fix "??? no type ???"
def check(var)
var
end

## hover: test.rb:2:11
??? no type ???
Integer

## hover: test.rb:3:3
Integer

## update: test2.rb
class Foo
#: (String) -> void
def bar(x)
x
end
end

## hover: test2.rb:3:10
String

## hover: test2.rb:4:4
String