Skip to content

Fix Code Lens heredoc handling #101

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 1 commit into from
Jul 5, 2023
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
3 changes: 3 additions & 0 deletions lib/ruby_lsp/ruby_lsp_rails/code_lens.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ def on_command(node)
# The test name may be a blank string while the code is being typed
return if first_argument.parts.empty?

# We can't handle interpolation yet
return unless first_argument.parts.all? { |part| part.is_a?(SyntaxTree::TStringContent) }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(an interpolated string is represented as an array of SyntaxTree::StringEmbExpr and SyntaxTree::TStringContent)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe better written as:

return if first_argument.parts.any? { |part| part.is_a?(SyntaxTree::TStringContent) }


test_name = first_argument.parts.first.value
return unless test_name

Expand Down
19 changes: 19 additions & 0 deletions test/ruby_lsp_rails/code_lens_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,25 @@ class Test < ActiveSupport::TestCase
assert_equal(3, response.size)
end

test "ignores tests with interpolation in their names" do
# Note that we need to quote the heredoc RUBY marker to prevent interpolation when defining the test.
@store.set(uri: "file:///fake.rb", source: <<~'RUBY', version: 1)
class Test < ActiveSupport::TestCase
test "before #{1 + 1} after" do
# test body
end
end
RUBY

response = RubyLsp::Executor.new(@store, @message_queue).execute({
method: "textDocument/codeLens",
params: { textDocument: { uri: "file:///fake.rb" }, position: { line: 0, character: 0 } },
}).response

# The 3 responses are for the test class, none for the test declaration.
assert_equal(3, response.size)
end

test "ignores tests with a non-string name argument" do
@store.set(uri: "file:///fake.rb", source: <<~RUBY, version: 1)
class Test < ActiveSupport::TestCase
Expand Down