diff --git a/lib/ruby_lsp/listeners/document_highlight.rb b/lib/ruby_lsp/listeners/document_highlight.rb index 89ddb59e8..3757bb743 100644 --- a/lib/ruby_lsp/listeners/document_highlight.rb +++ b/lib/ruby_lsp/listeners/document_highlight.rb @@ -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 } diff --git a/test/expectations/document_highlight/multiple_invocations.exp.json b/test/expectations/document_highlight/multiple_invocations.exp.json new file mode 100644 index 000000000..e7fc3793d --- /dev/null +++ b/test/expectations/document_highlight/multiple_invocations.exp.json @@ -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 + } + ] +} diff --git a/test/fixtures/multiple_invocations.rb b/test/fixtures/multiple_invocations.rb new file mode 100644 index 000000000..97173d322 --- /dev/null +++ b/test/fixtures/multiple_invocations.rb @@ -0,0 +1,10 @@ +foo() + +foo + +foo do +end + +foo { } + +foo.