Skip to content

Commit a1b3a64

Browse files
st0012vinistock
andauthored
Code lens for full test discovery (#65)
* Bump ruby-lsp * Don't run CodeLens listener if full test discovery is enabled * Generate code lens through TestDiscovery when full test discovery is enabled This will allow RSpec code lens to work with full test discovery. Co-authored-by: Vinicius Stock <vinistock@users.noreply.github.com> --------- Co-authored-by: Vinicius Stock <vinistock@users.noreply.github.com>
1 parent dc59e80 commit a1b3a64

File tree

8 files changed

+529
-484
lines changed

8 files changed

+529
-484
lines changed

Gemfile.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ PATH
22
remote: .
33
specs:
44
ruby-lsp-rspec (0.1.22)
5-
ruby-lsp (~> 0.23.17)
5+
ruby-lsp (~> 0.23.19)
66

77
GEM
88
remote: https://rubygems.org/
@@ -21,7 +21,7 @@ GEM
2121
rdoc (>= 4.0.0)
2222
reline (>= 0.4.2)
2323
json (2.11.3)
24-
language_server-protocol (3.17.0.4)
24+
language_server-protocol (3.17.0.5)
2525
lint_roller (1.1.0)
2626
logger (1.7.0)
2727
netrc (0.11.0)
@@ -83,7 +83,7 @@ GEM
8383
rubocop (~> 1.62)
8484
rubocop-sorbet (0.10.0)
8585
rubocop (>= 1)
86-
ruby-lsp (0.23.17)
86+
ruby-lsp (0.23.19)
8787
language_server-protocol (~> 3.17.0)
8888
prism (>= 1.2, < 2.0)
8989
rbs (>= 3, < 4)

lib/ruby_lsp/ruby_lsp_rspec/addon.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def initialize
3131
#: (GlobalState, Thread::Queue) -> void
3232
def activate(global_state, message_queue)
3333
@index = global_state.index #: RubyIndexer::Index?
34+
@global_state = global_state #: GlobalState?
3435

3536
settings = global_state.settings_for_addon(name)
3637
@rspec_command = rspec_command(settings)
@@ -59,6 +60,7 @@ def version
5960
#: (ResponseBuilders::CollectionResponseBuilder[Interface::CodeLens], URI::Generic, Prism::Dispatcher) -> void
6061
def create_code_lens_listener(response_builder, uri, dispatcher)
6162
return unless uri.to_standardized_path&.end_with?("_test.rb") || uri.to_standardized_path&.end_with?("_spec.rb")
63+
return if @global_state&.enabled_feature?(:fullTestDiscovery)
6264

6365
CodeLens.new(
6466
response_builder,

lib/ruby_lsp/ruby_lsp_rspec/rspec_formatter.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ def example_started(notification)
2424
example = notification.example
2525
uri = uri_for(example)
2626
id = generate_id(example)
27-
RubyLsp::LspReporter.instance.start_test(id: id, uri: uri)
27+
line = example.location.split(":").last
28+
RubyLsp::LspReporter.instance.start_test(id: id, uri: uri, line: line)
2829
end
2930

3031
def example_passed(notification)

lib/ruby_lsp/ruby_lsp_rspec/test_discovery.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ def handle_describe(node)
8888
@response_builder.add(test_item)
8989
end
9090

91+
@response_builder.add_code_lens(test_item)
9192
@group_stack.push(test_item)
9293
end
9394

@@ -106,6 +107,7 @@ def handle_example(node)
106107
)
107108

108109
parent.add(test_item)
110+
@response_builder.add_code_lens(test_item)
109111
end
110112

111113
#: -> ::RubyLsp::Requests::Support::TestItem??

ruby-lsp-rspec.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,5 @@ Gem::Specification.new do |spec|
4141
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
4242
spec.require_paths = ["lib"]
4343

44-
spec.add_dependency "ruby-lsp", "~> 0.23.17"
44+
spec.add_dependency "ruby-lsp", "~> 0.23.19"
4545
end

0 commit comments

Comments
 (0)