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

Document highlight shouldn't include the block for a method invocation #2357

Merged
merged 1 commit into from
Jul 25, 2024
Merged
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
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
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 { }
andyw8 marked this conversation as resolved.
Show resolved Hide resolved

foo.
Loading