From 46ecc744d832defa003b96d9c617afea1b3d4972 Mon Sep 17 00:00:00 2001 From: whtsht Date: Sun, 15 Feb 2026 21:40:50 +0900 Subject: [PATCH 1/3] Fix hover on method parameters with inline RBS annotations --- lib/typeprof/core/ast/base.rb | 2 +- lib/typeprof/core/ast/method.rb | 2 +- scenario/rbs/inline-hover.rb | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/typeprof/core/ast/base.rb b/lib/typeprof/core/ast/base.rb index c23eefc8..2d4f0d4e 100644 --- a/lib/typeprof/core/ast/base.rb +++ b/lib/typeprof/core/ast/base.rb @@ -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(_) [] diff --git a/lib/typeprof/core/ast/method.rb b/lib/typeprof/core/ast/method.rb index d57b0208..7406e464 100644 --- a/lib/typeprof/core/ast/method.rb +++ b/lib/typeprof/core/ast/method.rb @@ -12,7 +12,7 @@ def self.get_rbs_comment_before(raw_node, lenv) 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..] + rbs_comments[comment_loc.start_line - 1] = " " * (comment_loc.start_column + 2) + comment_text[2..] else break end diff --git a/scenario/rbs/inline-hover.rb b/scenario/rbs/inline-hover.rb index bb9a5dad..53131c72 100644 --- a/scenario/rbs/inline-hover.rb +++ b/scenario/rbs/inline-hover.rb @@ -1,11 +1,11 @@ ## 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 From 93ea24693ad8f1fd1edbe0f5fc824ddd0cb3d247 Mon Sep 17 00:00:00 2001 From: whtsht Date: Sun, 15 Feb 2026 22:38:26 +0900 Subject: [PATCH 2/3] Add new rbs-inline hover scenario --- scenario/rbs/inline-hover.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/scenario/rbs/inline-hover.rb b/scenario/rbs/inline-hover.rb index 53131c72..41ba7b6c 100644 --- a/scenario/rbs/inline-hover.rb +++ b/scenario/rbs/inline-hover.rb @@ -9,3 +9,17 @@ def check(var) ## 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 From 39cd6309dcb73351842208557ed430cd76507dac Mon Sep 17 00:00:00 2001 From: whtsht Date: Sun, 15 Feb 2026 23:30:23 +0900 Subject: [PATCH 3/3] Refactor comment collection in get_rbs_comment_before --- lib/typeprof/core/ast/method.rb | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/lib/typeprof/core/ast/method.rb b/lib/typeprof/core/ast/method.rb index 7406e464..636a19ca 100644 --- a/lib/typeprof/core/ast/method.rb +++ b/lib/typeprof/core/ast/method.rb @@ -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 - 1] = " " * (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