Class: RubyLsp::Requests::CodeLens
- Defined in:
- lib/ruby_lsp/requests/code_lens.rb
Overview
The [code lens](microsoft.github.io/language-server-protocol/specification#textDocument_codeLens) request informs the editor of runnable commands such as testing and debugging.
Class Method Summary collapse
-
.provider ⇒ Object
: -> Interface::CodeLensOptions.
Instance Method Summary collapse
-
#initialize(global_state, document, dispatcher) ⇒ CodeLens
constructor
: (GlobalState, RubyDocument | ERBDocument, Prism::Dispatcher) -> void.
-
#perform ⇒ Object
: -> Array.
Constructor Details
#initialize(global_state, document, dispatcher) ⇒ CodeLens
: (GlobalState, RubyDocument | ERBDocument, Prism::Dispatcher) -> void
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 |
# File 'lib/ruby_lsp/requests/code_lens.rb', line 22 def initialize(global_state, document, dispatcher) @response_builder = ResponseBuilders::CollectionResponseBuilder .new #: ResponseBuilders::CollectionResponseBuilder[Interface::CodeLens] super() @document = document @test_builder = ResponseBuilders::TestCollection.new #: ResponseBuilders::TestCollection uri = document.uri file_path = uri.full_path code_lens_config = global_state.feature_configuration(:codeLens) test_lenses_enabled = (!code_lens_config || code_lens_config.enabled?(:enableTestCodeLens)) && file_path && File.fnmatch?(TEST_PATH_PATTERN, file_path, File::FNM_PATHNAME | File::FNM_EXTGLOB) if global_state.enabled_feature?(:fullTestDiscovery) if test_lenses_enabled Listeners::TestStyle.new(@test_builder, global_state, dispatcher, uri) Listeners::SpecStyle.new(@test_builder, global_state, dispatcher, uri) end else Listeners::CodeLens.new(@response_builder, global_state, uri, dispatcher) end Addon.addons.each do |addon| addon.create_code_lens_listener(@response_builder, uri, dispatcher) if global_state.enabled_feature?(:fullTestDiscovery) && test_lenses_enabled addon.create_discover_tests_listener(@test_builder, dispatcher, uri) end end end |
Class Method Details
.provider ⇒ Object
: -> Interface::CodeLensOptions
16 17 18 |
# File 'lib/ruby_lsp/requests/code_lens.rb', line 16 def provider Interface::CodeLensOptions.new(resolve_provider: true) end |
Instance Method Details
#perform ⇒ Object
: -> Array
55 56 57 58 |
# File 'lib/ruby_lsp/requests/code_lens.rb', line 55 def perform @document.cache_set("rubyLsp/discoverTests", @test_builder.response) @response_builder.response + @test_builder.code_lens end |