-
Notifications
You must be signed in to change notification settings - Fork 183
/
Copy pathdocument_highlight.rb
53 lines (49 loc) · 1.81 KB
/
document_highlight.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# typed: strict
# frozen_string_literal: true
require "ruby_lsp/listeners/document_highlight"
module RubyLsp
module Requests
# 
#
# The [document highlight](https://microsoft.github.io/language-server-protocol/specification#textDocument_documentHighlight)
# informs the editor all relevant elements of the currently pointed item for highlighting. For example, when
# the cursor is on the `F` of the constant `FOO`, the editor should identify other occurrences of `FOO`
# and highlight them.
#
# For writable elements like constants or variables, their read/write occurrences should be highlighted differently.
# This is achieved by sending different "kind" attributes to the editor (2 for read and 3 for write).
#
# # Example
#
# ```ruby
# FOO = 1 # should be highlighted as "write"
#
# def foo
# FOO # should be highlighted as "read"
# end
# ```
class DocumentHighlight < Request
extend T::Sig
sig do
params(
document: T.any(RubyDocument, ERBDocument),
position: T::Hash[Symbol, T.untyped],
dispatcher: Prism::Dispatcher,
).void
end
def initialize(document, position, dispatcher)
super()
node_context = document.locate_node(position)
@response_builder = T.let(
ResponseBuilders::CollectionResponseBuilder[Interface::DocumentHighlight].new,
ResponseBuilders::CollectionResponseBuilder[Interface::DocumentHighlight],
)
Listeners::DocumentHighlight.new(@response_builder, node_context.node, node_context.parent, dispatcher)
end
sig { override.returns(T::Array[Interface::DocumentHighlight]) }
def perform
@response_builder.response
end
end
end
end