Class: RubyLsp::Requests::DocumentHighlight
- Defined in:
- lib/ruby_lsp/requests/document_highlight.rb
Overview
The [document highlight](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).
Instance Method Summary collapse
-
#initialize(global_state, document, position, dispatcher) ⇒ DocumentHighlight
constructor
: (GlobalState global_state, (RubyDocument | ERBDocument) document, Hash[Symbol, untyped] position, Prism::Dispatcher dispatcher) -> void.
-
#perform ⇒ Object
: -> Array.
Constructor Details
#initialize(global_state, document, position, dispatcher) ⇒ DocumentHighlight
: (GlobalState global_state, (RubyDocument | ERBDocument) document, Hash[Symbol, untyped] position, Prism::Dispatcher dispatcher) -> void
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ruby_lsp/requests/document_highlight.rb', line 17 def initialize(global_state, document, position, dispatcher) super() char_position, _ = document.find_index_by_position(position) delegate_request_if_needed!(global_state, document, char_position) node_context = RubyDocument.locate( document.ast, char_position, code_units_cache: document.code_units_cache, ) @response_builder = ResponseBuilders::CollectionResponseBuilder .new #: ResponseBuilders::CollectionResponseBuilder[Interface::DocumentHighlight] Listeners::DocumentHighlight.new( @response_builder, node_context.node, node_context.parent, dispatcher, position, ) end |
Instance Method Details
#perform ⇒ Object
: -> Array
41 42 43 |
# File 'lib/ruby_lsp/requests/document_highlight.rb', line 41 def perform @response_builder.response end |