Skip to content
Open
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
8 changes: 8 additions & 0 deletions lib/ruby_lsp/listeners/code_lens.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,14 @@ def add_test_code_lens(node, name:, command:, kind:, id: name)
arguments: arguments,
data: { type: "debug", **grouping_data },
)

@response_builder << create_code_lens(
node,
title: "🔎 Reveal In Explorer",
command_name: "rubyLsp.revealInExplorer",
arguments: arguments,
data: { type: "reveal_in_explorer", **grouping_data },
)
end

#: (?group_stack: Array[String], ?spec_name: String?, ?method_name: String?) -> String
Expand Down
5 changes: 5 additions & 0 deletions lib/ruby_lsp/response_builders/test_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ def add_code_lens(item)
range: range,
data: { arguments: arguments, kind: "debug_test" },
)

@code_lens << Interface::CodeLens.new(
range: range,
data: { arguments: arguments, kind: "reveal_in_explorer" },
)
end

#: (String id) -> ResponseType?
Expand Down
25 changes: 17 additions & 8 deletions lib/ruby_lsp/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ class Server < BaseServer
Bundler::Dsl::DSLError,
].freeze #: Array[singleton(StandardError)]

CODE_LENS_COMMANDS = {
"run_test" => { title: "▶ Run", command: "rubyLsp.runTest" },
"run_test_in_terminal" => { title: "▶ Run in terminal", command: "rubyLsp.runTestInTerminal" },
"debug_test" => { title: "⚙ Debug", command: "rubyLsp.debugTest" },
"reveal_in_explorer" => {
title: "🔎 Reveal In Explorer",
command: "rubyLsp.revealInExplorer",
},
}.freeze

# Only for testing
#: GlobalState
attr_reader :global_state
Expand Down Expand Up @@ -1523,14 +1533,13 @@ def code_lens_resolve(message)
code_lens = message[:params]
args = code_lens.dig(:data, :arguments)

case code_lens.dig(:data, :kind)
when "run_test"
code_lens[:command] = Interface::Command.new(title: "▶ Run", command: "rubyLsp.runTest", arguments: args)
when "run_test_in_terminal"
code_lens[:command] =
Interface::Command.new(title: "▶ Run in terminal", command: "rubyLsp.runTestInTerminal", arguments: args)
when "debug_test"
code_lens[:command] = Interface::Command.new(title: "⚙ Debug", command: "rubyLsp.debugTest", arguments: args)
command_data = CODE_LENS_COMMANDS[code_lens.dig(:data, :kind)]
if command_data
code_lens[:command] = Interface::Command.new(
title: command_data[:title],
command: command_data[:command],
arguments: args,
)
end

send_message(Result.new(
Expand Down
Loading
Loading