From 6bc9b93f11355957f294b3cc43a68d0773167403 Mon Sep 17 00:00:00 2001 From: Andy Waite <13400+andyw8@users.noreply.github.com> Date: Thu, 25 Jul 2024 10:55:28 -0400 Subject: [PATCH] Document highlight shouldn't include the block for a method --- lib/ruby_lsp/listeners/document_highlight.rb | 6 +- .../multiple_invocations.exp.json | 62 +++++++++++++++++++ test/fixtures/multiple_invocations.rb | 8 +++ 3 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 test/expectations/document_highlight/multiple_invocations.exp.json create mode 100644 test/fixtures/multiple_invocations.rb diff --git a/lib/ruby_lsp/listeners/document_highlight.rb b/lib/ruby_lsp/listeners/document_highlight.rb index 89ddb59e8c..3757bb743e 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 0000000000..30fcd6c3d5 --- /dev/null +++ b/test/expectations/document_highlight/multiple_invocations.exp.json @@ -0,0 +1,62 @@ +{ + "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 + } + ], + "params": [ + { + "line": 0, + "character": 2 + } + ] +} diff --git a/test/fixtures/multiple_invocations.rb b/test/fixtures/multiple_invocations.rb new file mode 100644 index 0000000000..989075a7d3 --- /dev/null +++ b/test/fixtures/multiple_invocations.rb @@ -0,0 +1,8 @@ +foo() + +foo + +foo do +end + +foo { }