Skip to content

Code lens for full test discovery #65

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ PATH
remote: .
specs:
ruby-lsp-rspec (0.1.22)
ruby-lsp (~> 0.23.17)
ruby-lsp (~> 0.23.19)

GEM
remote: https://rubygems.org/
Expand All @@ -21,7 +21,7 @@ GEM
rdoc (>= 4.0.0)
reline (>= 0.4.2)
json (2.11.3)
language_server-protocol (3.17.0.4)
language_server-protocol (3.17.0.5)
lint_roller (1.1.0)
logger (1.7.0)
netrc (0.11.0)
Expand Down Expand Up @@ -83,7 +83,7 @@ GEM
rubocop (~> 1.62)
rubocop-sorbet (0.10.0)
rubocop (>= 1)
ruby-lsp (0.23.17)
ruby-lsp (0.23.19)
language_server-protocol (~> 3.17.0)
prism (>= 1.2, < 2.0)
rbs (>= 3, < 4)
Expand Down
2 changes: 2 additions & 0 deletions lib/ruby_lsp/ruby_lsp_rspec/addon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def initialize
#: (GlobalState, Thread::Queue) -> void
def activate(global_state, message_queue)
@index = global_state.index #: RubyIndexer::Index?
@global_state = global_state #: GlobalState?

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

CodeLens.new(
response_builder,
Expand Down
3 changes: 2 additions & 1 deletion lib/ruby_lsp/ruby_lsp_rspec/rspec_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ def example_started(notification)
example = notification.example
uri = uri_for(example)
id = generate_id(example)
RubyLsp::LspReporter.instance.start_test(id: id, uri: uri)
line = example.location.split(":").last
RubyLsp::LspReporter.instance.start_test(id: id, uri: uri, line: line)
end

def example_passed(notification)
Expand Down
2 changes: 2 additions & 0 deletions lib/ruby_lsp/ruby_lsp_rspec/test_discovery.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def handle_describe(node)
@response_builder.add(test_item)
end

@response_builder.add_code_lens(test_item)
@group_stack.push(test_item)
end

Expand All @@ -106,6 +107,7 @@ def handle_example(node)
)

parent.add(test_item)
@response_builder.add_code_lens(test_item)
end

#: -> ::RubyLsp::Requests::Support::TestItem??
Expand Down
2 changes: 1 addition & 1 deletion ruby-lsp-rspec.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_dependency "ruby-lsp", "~> 0.23.17"
spec.add_dependency "ruby-lsp", "~> 0.23.19"
end
Loading
Loading