Skip to content

Commit

Permalink
Do not try to generate test command for temporary files (#945)
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock authored Aug 29, 2023
1 parent 51a73bd commit 7f26495
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
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_")
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

0 comments on commit 7f26495

Please sign in to comment.