Class: RubyLsp::Requests::SemanticHighlighting

Inherits:
Request
  • Object
show all
Extended by:
T::Generic, T::Sig
Defined in:
lib/ruby_lsp/requests/semantic_highlighting.rb

Overview

![Semantic highlighting demo](../../semantic_highlighting.gif)

The [semantic highlighting](microsoft.github.io/language-server-protocol/specification#textDocument_semanticTokens) request informs the editor of the correct token types to provide consistent and accurate highlighting for themes.

# Example

“‘ruby def foo

var = 1 # --> semantic highlighting: local variable
some_invocation # --> semantic highlighting: method invocation
var # --> semantic highlighting: local variable

end “‘

Constant Summary collapse

ResponseType =
type_member { { fixed: T::Array[Listeners::SemanticHighlighting::SemanticToken] } }

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dispatcher, range: nil) ⇒ SemanticHighlighting

Returns a new instance of SemanticHighlighting.



47
48
49
50
# File 'lib/ruby_lsp/requests/semantic_highlighting.rb', line 47

def initialize(dispatcher, range: nil)
  super()
  @listener = T.let(Listeners::SemanticHighlighting.new(dispatcher, range: range), Listener[ResponseType])
end

Class Method Details

.providerObject



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/ruby_lsp/requests/semantic_highlighting.rb', line 33

def provider
  Interface::SemanticTokensRegistrationOptions.new(
    document_selector: { scheme: "file", language: "ruby" },
    legend: Interface::SemanticTokensLegend.new(
      token_types: Listeners::SemanticHighlighting::TOKEN_TYPES.keys,
      token_modifiers: Listeners::SemanticHighlighting::TOKEN_MODIFIERS.keys,
    ),
    range: true,
    full: { delta: false },
  )
end

Instance Method Details

#performObject



53
54
55
# File 'lib/ruby_lsp/requests/semantic_highlighting.rb', line 53

def perform
  @listener.response
end