Skip to content
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

Do not try to generate test command for temporary files #945

Merged
merged 1 commit into from
Aug 29, 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
4 changes: 2 additions & 2 deletions lib/ruby_lsp/requests/code_lens.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def on_class(node)
class_name = node.constant.constant.value
@class_stack.push(class_name)

if class_name.end_with?("Test")
if @path && class_name.end_with?("Test")
add_test_code_lens(
node,
name: class_name,
Expand All @@ -89,7 +89,7 @@ def on_def(node)
visibility, _ = @visibility_stack.last
if visibility == "public"
method_name = node.name.value
if method_name.start_with?("test_")
if @path && method_name.start_with?("test_")
Copy link
Contributor

Choose a reason for hiding this comment

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

(nit) could this be be part of the return unless... guard above?

add_test_code_lens(
node,
name: method_name,
Expand Down
18 changes: 18 additions & 0 deletions test/requests/code_lens_expectations_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,24 @@ def test_bar; end
assert_empty(response)
end

def test_no_code_lens_for_unsaved_files
source = <<~RUBY
class FooTest < Test::Unit::TestCase
def test_bar; end
end
RUBY
uri = URI::Generic.build(scheme: "untitled", opaque: "Untitled-1")

document = RubyLsp::Document.new(source: source, version: 1, uri: uri)

emitter = RubyLsp::EventEmitter.new
listener = RubyLsp::Requests::CodeLens.new(uri, emitter, @message_queue, "minitest")
emitter.visit(document.tree)
response = listener.response

assert_empty(response)
end

def test_code_lens_extensions
message_queue = Thread::Queue.new
create_code_lens_extension
Expand Down
Loading