Skip to content

Commit 889235d

Browse files
authored
Merge pull request #101 from Shopify/andyw8/fix-code-lens-heredoc-handling
Fix Code Lens heredoc handling
2 parents 3a50717 + bd80171 commit 889235d

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

lib/ruby_lsp/ruby_lsp_rails/code_lens.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ def on_command(node)
6464
# The test name may be a blank string while the code is being typed
6565
return if first_argument.parts.empty?
6666

67+
# We can't handle interpolation yet
68+
return unless first_argument.parts.all? { |part| part.is_a?(SyntaxTree::TStringContent) }
69+
6770
test_name = first_argument.parts.first.value
6871
return unless test_name
6972

test/ruby_lsp_rails/code_lens_test.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,25 @@ class Test < ActiveSupport::TestCase
5656
assert_equal(3, response.size)
5757
end
5858

59+
test "ignores tests with interpolation in their names" do
60+
# Note that we need to quote the heredoc RUBY marker to prevent interpolation when defining the test.
61+
@store.set(uri: "file:///fake.rb", source: <<~'RUBY', version: 1)
62+
class Test < ActiveSupport::TestCase
63+
test "before #{1 + 1} after" do
64+
# test body
65+
end
66+
end
67+
RUBY
68+
69+
response = RubyLsp::Executor.new(@store, @message_queue).execute({
70+
method: "textDocument/codeLens",
71+
params: { textDocument: { uri: "file:///fake.rb" }, position: { line: 0, character: 0 } },
72+
}).response
73+
74+
# The 3 responses are for the test class, none for the test declaration.
75+
assert_equal(3, response.size)
76+
end
77+
5978
test "ignores tests with a non-string name argument" do
6079
@store.set(uri: "file:///fake.rb", source: <<~RUBY, version: 1)
6180
class Test < ActiveSupport::TestCase

0 commit comments

Comments
 (0)