Skip to content

Commit

Permalink
Make test CodeLens request aware of test hierarchy (#1214)
Browse files Browse the repository at this point in the history
This is achieved by adding `group_id` (both group and example kinds) and
`id` (only example kind) attributes to the CodeLens data.

Co-authored-by: Vinicius Stock <vinistock@users.noreply.github.com>
  • Loading branch information
st0012 and vinistock authored Nov 24, 2023
1 parent 0a3bf4f commit d54eb2c
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 20 deletions.
15 changes: 12 additions & 3 deletions lib/ruby_lsp/requests/code_lens.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ def initialize(uri, dispatcher, message_queue)
# visibility_stack is a stack of [current_visibility, previous_visibility]
@visibility_stack = T.let([[:public, :public]], T::Array[T::Array[T.nilable(Symbol)]])
@class_stack = T.let([], T::Array[String])
@group_id = T.let(1, Integer)
@group_id_stack = T.let([], T::Array[Integer])

super(dispatcher, message_queue)

Expand Down Expand Up @@ -82,12 +84,16 @@ def on_class_node_enter(node)
kind: :group,
)
end

@group_id_stack.push(@group_id)
@group_id += 1
end

sig { params(node: Prism::ClassNode).void }
def on_class_node_leave(node)
@visibility_stack.pop
@class_stack.pop
@group_id_stack.pop
end

sig { params(node: Prism::DefNode).void }
Expand Down Expand Up @@ -174,28 +180,31 @@ def add_test_code_lens(node, name:, command:, kind:)
},
]

grouping_data = { group_id: @group_id_stack.last, kind: kind }
grouping_data[:id] = @group_id if kind == :group

@_response << create_code_lens(
node,
title: "Run",
command_name: "rubyLsp.runTest",
arguments: arguments,
data: { type: "test", kind: kind },
data: { type: "test", **grouping_data },
)

@_response << create_code_lens(
node,
title: "Run In Terminal",
command_name: "rubyLsp.runTestInTerminal",
arguments: arguments,
data: { type: "test_in_terminal", kind: kind },
data: { type: "test_in_terminal", **grouping_data },
)

@_response << create_code_lens(
node,
title: "Debug",
command_name: "rubyLsp.debugTest",
arguments: arguments,
data: { type: "debug", kind: kind },
data: { type: "debug", **grouping_data },
)
end

Expand Down
49 changes: 42 additions & 7 deletions test/expectations/code_lens/minitest_tests.exp.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
},
"data": {
"type": "test",
"kind": "group"
"group_id": null,
"kind": "group",
"id": 1
}
},
{
Expand Down Expand Up @@ -59,7 +61,9 @@
},
"data": {
"type": "test_in_terminal",
"kind": "group"
"group_id": null,
"kind": "group",
"id": 1
}
},
{
Expand Down Expand Up @@ -90,7 +94,9 @@
},
"data": {
"type": "debug",
"kind": "group"
"group_id": null,
"kind": "group",
"id": 1
}
},
{
Expand Down Expand Up @@ -121,6 +127,7 @@
},
"data": {
"type": "test",
"group_id": 1,
"kind": "example"
}
},
Expand Down Expand Up @@ -152,6 +159,7 @@
},
"data": {
"type": "test_in_terminal",
"group_id": 1,
"kind": "example"
}
},
Expand Down Expand Up @@ -183,6 +191,7 @@
},
"data": {
"type": "debug",
"group_id": 1,
"kind": "example"
}
},
Expand Down Expand Up @@ -214,6 +223,7 @@
},
"data": {
"type": "test",
"group_id": 1,
"kind": "example"
}
},
Expand Down Expand Up @@ -245,6 +255,7 @@
},
"data": {
"type": "test_in_terminal",
"group_id": 1,
"kind": "example"
}
},
Expand Down Expand Up @@ -276,6 +287,7 @@
},
"data": {
"type": "debug",
"group_id": 1,
"kind": "example"
}
},
Expand Down Expand Up @@ -307,6 +319,7 @@
},
"data": {
"type": "test",
"group_id": 1,
"kind": "example"
}
},
Expand Down Expand Up @@ -338,6 +351,7 @@
},
"data": {
"type": "test_in_terminal",
"group_id": 1,
"kind": "example"
}
},
Expand Down Expand Up @@ -369,6 +383,7 @@
},
"data": {
"type": "debug",
"group_id": 1,
"kind": "example"
}
},
Expand Down Expand Up @@ -400,6 +415,7 @@
},
"data": {
"type": "test",
"group_id": 1,
"kind": "example"
}
},
Expand Down Expand Up @@ -431,6 +447,7 @@
},
"data": {
"type": "test_in_terminal",
"group_id": 1,
"kind": "example"
}
},
Expand Down Expand Up @@ -462,6 +479,7 @@
},
"data": {
"type": "debug",
"group_id": 1,
"kind": "example"
}
},
Expand Down Expand Up @@ -493,6 +511,7 @@
},
"data": {
"type": "test",
"group_id": 1,
"kind": "example"
}
},
Expand Down Expand Up @@ -524,6 +543,7 @@
},
"data": {
"type": "test_in_terminal",
"group_id": 1,
"kind": "example"
}
},
Expand Down Expand Up @@ -555,6 +575,7 @@
},
"data": {
"type": "debug",
"group_id": 1,
"kind": "example"
}
},
Expand Down Expand Up @@ -586,7 +607,9 @@
},
"data": {
"type": "test",
"kind": "group"
"group_id": null,
"kind": "group",
"id": 2
}
},
{
Expand Down Expand Up @@ -617,7 +640,9 @@
},
"data": {
"type": "test_in_terminal",
"kind": "group"
"group_id": null,
"kind": "group",
"id": 2
}
},
{
Expand Down Expand Up @@ -648,7 +673,9 @@
},
"data": {
"type": "debug",
"kind": "group"
"group_id": null,
"kind": "group",
"id": 2
}
},
{
Expand Down Expand Up @@ -679,6 +706,7 @@
},
"data": {
"type": "test",
"group_id": 2,
"kind": "example"
}
},
Expand Down Expand Up @@ -710,6 +738,7 @@
},
"data": {
"type": "test_in_terminal",
"group_id": 2,
"kind": "example"
}
},
Expand Down Expand Up @@ -741,6 +770,7 @@
},
"data": {
"type": "debug",
"group_id": 2,
"kind": "example"
}
},
Expand Down Expand Up @@ -772,6 +802,7 @@
},
"data": {
"type": "test",
"group_id": 2,
"kind": "example"
}
},
Expand Down Expand Up @@ -803,6 +834,7 @@
},
"data": {
"type": "test_in_terminal",
"group_id": 2,
"kind": "example"
}
},
Expand Down Expand Up @@ -834,9 +866,12 @@
},
"data": {
"type": "debug",
"group_id": 2,
"kind": "example"
}
}
],
"params": []
"params": [

]
}
Loading

0 comments on commit d54eb2c

Please sign in to comment.