Skip to content

Push test code lens to response builder on test discovery #605

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
26 changes: 13 additions & 13 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ PATH
remote: .
specs:
ruby-lsp-rails (0.4.2)
ruby-lsp (>= 0.23.16, < 0.24.0)
ruby-lsp (>= 0.23.18, < 0.24.0)

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -102,7 +102,7 @@ GEM
rdoc (>= 4.0.0)
reline (>= 0.4.2)
json (2.10.1)
language_server-protocol (3.17.0.4)
language_server-protocol (3.17.0.5)
lint_roller (1.1.0)
logger (1.7.0)
loofah (2.24.0)
Expand Down Expand Up @@ -199,7 +199,7 @@ GEM
rbi (0.2.4)
prism (~> 1.0)
sorbet-runtime (>= 0.5.9204)
rbs (3.9.2)
rbs (3.9.3)
logger
rdoc (6.12.0)
psych (>= 4.0.0)
Expand Down Expand Up @@ -230,23 +230,23 @@ GEM
rubocop (~> 1.62)
rubocop-sorbet (0.8.9)
rubocop (>= 1)
ruby-lsp (0.23.16)
ruby-lsp (0.23.18)
language_server-protocol (~> 3.17.0)
prism (>= 1.2, < 2.0)
rbs (>= 3, < 4)
sorbet-runtime (>= 0.5.10782)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
securerandom (0.4.1)
sorbet (0.5.12079)
sorbet-static (= 0.5.12079)
sorbet-runtime (0.5.12079)
sorbet-static (0.5.12079-aarch64-linux)
sorbet-static (0.5.12079-universal-darwin)
sorbet-static (0.5.12079-x86_64-linux)
sorbet-static-and-runtime (0.5.12079)
sorbet (= 0.5.12079)
sorbet-runtime (= 0.5.12079)
sorbet (0.5.12087)
sorbet-static (= 0.5.12087)
sorbet-runtime (0.5.12087)
sorbet-static (0.5.12087-aarch64-linux)
sorbet-static (0.5.12087-universal-darwin)
sorbet-static (0.5.12087-x86_64-linux)
sorbet-static-and-runtime (0.5.12087)
sorbet (= 0.5.12087)
sorbet-runtime (= 0.5.12087)
spoom (1.5.4)
erubi (>= 1.10.0)
prism (>= 0.28.0)
Expand Down
26 changes: 17 additions & 9 deletions lib/ruby_lsp/ruby_lsp_rails/code_lens.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class CodeLens
include Requests::Support::Common
include ActiveSupportTestCaseHelper

#: (RunnerClient client, GlobalState global_state, ResponseBuilders::CollectionResponseBuilder[Interface::CodeLens] response_builder, URI::Generic uri, Prism::Dispatcher dispatcher) -> void
#: (RunnerClient, GlobalState, ResponseBuilders::CollectionResponseBuilder[Interface::CodeLens], URI::Generic, Prism::Dispatcher) -> void
def initialize(client, global_state, response_builder, uri, dispatcher)
@client = client
@global_state = global_state
Expand All @@ -98,8 +98,10 @@ def initialize(client, global_state, response_builder, uri, dispatcher)

#: (Prism::CallNode node) -> void
def on_call_node_enter(node)
content = extract_test_case_name(node)
# Remove this method once the rollout is complete
return if @global_state.enabled_feature?(:fullTestDiscovery)

content = extract_test_case_name(node)
return unless content

line_number = node.location.start_line
Expand All @@ -110,12 +112,15 @@ def on_call_node_enter(node)
# Although uncommon, Rails tests can be written with the classic "def test_name" syntax.
#: (Prism::DefNode node) -> void
def on_def_node_enter(node)
method_name = node.name.to_s

if method_name.start_with?("test_")
line_number = node.location.start_line
command = "#{test_command} #{@path}:#{line_number}"
add_test_code_lens(node, name: method_name, command: command, kind: :example)
# Remove this entire unless block once the rollout is complete
unless @global_state.enabled_feature?(:fullTestDiscovery)
method_name = node.name.to_s

if method_name.start_with?("test_")
line_number = node.location.start_line
command = "#{test_command} #{@path}:#{line_number}"
add_test_code_lens(node, name: method_name, command: command, kind: :example)
end
end

if controller?
Expand All @@ -134,7 +139,8 @@ def on_class_node_enter(node)
# back in a controller context. This part is used in other places in the LSP
@constant_name_stack << [class_name, superclass_name]

if class_name.end_with?("Test")
# Remove this entire if block once the rollout is complete
if class_name.end_with?("Test") && !@global_state.enabled_feature?(:fullTestDiscovery)
fully_qualified_name = @constant_name_stack.map(&:first).join("::")
command = "#{test_command} #{@path} --name \"/#{Shellwords.escape(fully_qualified_name)}(#|::)/\""
add_test_code_lens(node, name: class_name, command: command, kind: :group)
Expand All @@ -155,6 +161,8 @@ def on_class_node_leave(node)
if class_name.end_with?("Test")
@group_id_stack.pop
end
# Remove everything but the `@constant_name_stack.pop` once the rollout is complete
return if @global_state.enabled_feature?(:fullTestDiscovery)

@constant_name_stack.pop
end
Expand Down
7 changes: 5 additions & 2 deletions lib/ruby_lsp/ruby_lsp_rails/rails_test_style.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def on_class_node_enter(node)
)

@response_builder.add(test_item)
@response_builder.add_code_lens(test_item)
end
end
end
Expand Down Expand Up @@ -127,13 +128,15 @@ def add_test_item(node, test_name)
test_item = group_test_item
return unless test_item

test_item.add(Requests::Support::TestItem.new(
example_item = Requests::Support::TestItem.new(
"#{test_item.id}##{test_name}",
test_name,
@uri,
range_from_node(node),
framework: :rails,
))
)
test_item.add(example_item)
@response_builder.add_code_lens(example_item)
end

#: -> Requests::Support::TestItem?
Expand Down
2 changes: 1 addition & 1 deletion ruby-lsp-rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ Gem::Specification.new do |spec|
Dir["lib/**/*", "LICENSE.txt", "Rakefile", "README.md"]
end

spec.add_dependency("ruby-lsp", ">= 0.23.16", "< 0.24.0")
spec.add_dependency("ruby-lsp", ">= 0.23.18", "< 0.24.0")
end
File renamed without changes.
Loading
Loading