Skip to content

Commit

Permalink
Document highlight shouldn't include the block for a method
Browse files Browse the repository at this point in the history
  • Loading branch information
andyw8 committed Jul 25, 2024
1 parent 77de05f commit 67494f4
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/ruby_lsp/listeners/document_highlight.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,11 @@ def initialize(response_builder, target, parent, dispatcher)
def on_call_node_enter(node)
return unless matches?(node, [Prism::CallNode, Prism::DefNode])

add_highlight(Constant::DocumentHighlightKind::READ, node.location)
loc = node.message_loc
# if we have `foo.` it's a call node but there is no message yet.
return unless loc

add_highlight(Constant::DocumentHighlightKind::READ, loc)
end

sig { params(node: Prism::DefNode).void }
Expand Down
75 changes: 75 additions & 0 deletions test/expectations/document_highlight/multiple_invocations.exp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"result": [
{
"range": {
"start": {
"line": 0,
"character": 0
},
"end": {
"line": 0,
"character": 3
}
},
"kind": 2
},
{
"range": {
"start": {
"line": 2,
"character": 0
},
"end": {
"line": 2,
"character": 3
}
},
"kind": 2
},
{
"range": {
"start": {
"line": 4,
"character": 0
},
"end": {
"line": 4,
"character": 3
}
},
"kind": 2
},
{
"range": {
"start": {
"line": 7,
"character": 0
},
"end": {
"line": 7,
"character": 3
}
},
"kind": 2
},
{
"range": {
"start": {
"line": 9,
"character": 0
},
"end": {
"line": 9,
"character": 3
}
},
"kind": 2
}
],
"params": [
{
"line": 0,
"character": 2
}
]
}
10 changes: 10 additions & 0 deletions test/fixtures/multiple_invocations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
foo()

foo

foo do
end

foo { }

foo.

0 comments on commit 67494f4

Please sign in to comment.