Skip to content
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
5 changes: 3 additions & 2 deletions lib/ruby_lsp/requests/code_lens.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ def initialize(uri, emitter, message_queue, test_library)
def on_class(node)
@visibility_stack.push(["public", "public"])
class_name = node.constant.constant.value
@class_stack.push(class_name)

if class_name.end_with?("Test")
@class_stack.push(class_name)
add_test_code_lens(
node,
name: class_name,
Expand All @@ -82,7 +83,7 @@ def after_class(node)
sig { params(node: SyntaxTree::DefNode).void }
def on_def(node)
class_name = @class_stack.last
return unless class_name
return unless class_name&.end_with?("Test")

visibility, _ = @visibility_stack.last
if visibility == "public"
Expand Down
105 changes: 99 additions & 6 deletions test/expectations/code_lens/minitest_tests.exp.json
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@
"character": 0
},
"end": {
"line": 26,
"line": 32,
"character": 3
}
},
Expand All @@ -579,7 +579,7 @@
{
"start_line": 24,
"start_column": 0,
"end_line": 26,
"end_line": 32,
"end_column": 3
}
]
Expand All @@ -596,7 +596,7 @@
"character": 0
},
"end": {
"line": 26,
"line": 32,
"character": 3
}
},
Expand All @@ -610,7 +610,7 @@
{
"start_line": 24,
"start_column": 0,
"end_line": 26,
"end_line": 32,
"end_column": 3
}
]
Expand All @@ -627,7 +627,7 @@
"character": 0
},
"end": {
"line": 26,
"line": 32,
"character": 3
}
},
Expand All @@ -641,7 +641,7 @@
{
"start_line": 24,
"start_column": 0,
"end_line": 26,
"end_line": 32,
"end_column": 3
}
]
Expand Down Expand Up @@ -743,6 +743,99 @@
"type": "debug",
"kind": "example"
}
},
{
"range": {
"start": {
"line": 31,
"character": 2
},
"end": {
"line": 31,
"character": 24
}
},
"command": {
"title": "Run",
"command": "rubyLsp.runTest",
"arguments": [
"/fixtures/minitest_tests.rb",
"test_public_2",
"bundle exec ruby -Itest /fixtures/minitest_tests.rb --name /AnotherTest\\#test_public_2/",
{
"start_line": 31,
"start_column": 2,
"end_line": 31,
"end_column": 24
}
]
},
"data": {
"type": "test",
"kind": "example"
}
},
{
"range": {
"start": {
"line": 31,
"character": 2
},
"end": {
"line": 31,
"character": 24
}
},
"command": {
"title": "Run In Terminal",
"command": "rubyLsp.runTestInTerminal",
"arguments": [
"/fixtures/minitest_tests.rb",
"test_public_2",
"bundle exec ruby -Itest /fixtures/minitest_tests.rb --name /AnotherTest\\#test_public_2/",
{
"start_line": 31,
"start_column": 2,
"end_line": 31,
"end_column": 24
}
]
},
"data": {
"type": "test_in_terminal",
"kind": "example"
}
},
{
"range": {
"start": {
"line": 31,
"character": 2
},
"end": {
"line": 31,
"character": 24
}
},
"command": {
"title": "Debug",
"command": "rubyLsp.debugTest",
"arguments": [
"/fixtures/minitest_tests.rb",
"test_public_2",
"bundle exec ruby -Itest /fixtures/minitest_tests.rb --name /AnotherTest\\#test_public_2/",
{
"start_line": 31,
"start_column": 2,
"end_line": 31,
"end_column": 24
}
]
},
"data": {
"type": "debug",
"kind": "example"
}
}
],
"params": []
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/minitest_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ def test_with_q?; end

class AnotherTest < Minitest::Test
def test_public; end

# shouldn't block code lenses below
class Bar
end

def test_public_2; end
end

class Foo
Expand Down