Sha256: d7d6d730442d8482c29b5d64180f87f7f52db0b232726b59d15c5060e6a699a6

Contents?: true

Size: 2 KB

Versions: 8

Compression:

Stored size: 2 KB

Contents

# typed: strict
# frozen_string_literal: true

require "ruby_lsp/listeners/semantic_highlighting"

module RubyLsp
  module Requests
    # ![Semantic highlighting demo](../../semantic_highlighting.gif)
    #
    # The [semantic
    # highlighting](https://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
    # ```
    class SemanticHighlighting < Request
      extend T::Sig

      class << self
        extend T::Sig

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

      sig { params(dispatcher: Prism::Dispatcher, range: T.nilable(T::Range[Integer])).void }
      def initialize(dispatcher, range: nil)
        super()
        @response_builder = T.let(ResponseBuilders::SemanticHighlighting.new, ResponseBuilders::SemanticHighlighting)
        Listeners::SemanticHighlighting.new(dispatcher, @response_builder, range: range)

        Addon.addons.each do |addon|
          addon.create_semantic_highlighting_listener(@response_builder, dispatcher)
        end
      end

      sig { override.returns(Interface::SemanticTokens) }
      def perform
        @response_builder.response
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ruby-lsp-0.15.0 lib/ruby_lsp/requests/semantic_highlighting.rb
ruby-lsp-0.14.6 lib/ruby_lsp/requests/semantic_highlighting.rb
ruby-lsp-0.14.5 lib/ruby_lsp/requests/semantic_highlighting.rb
ruby-lsp-0.14.4 lib/ruby_lsp/requests/semantic_highlighting.rb
ruby-lsp-0.14.3 lib/ruby_lsp/requests/semantic_highlighting.rb
ruby-lsp-0.14.2 lib/ruby_lsp/requests/semantic_highlighting.rb
ruby-lsp-0.14.1 lib/ruby_lsp/requests/semantic_highlighting.rb
ruby-lsp-0.14.0 lib/ruby_lsp/requests/semantic_highlighting.rb