Use textDocument/codeLens
data in the actions menu when applicable (#26811)
Similar to how tasks are fetched via LSP, also queries for document's code lens and filters the ones with the commands, supported in server capabilities. Whatever's left and applicable to the range given, is added to the actions menu:  This way, Zed can get more actions to run, albeit neither r-a nor vtsls seem to provide anything by default. Currently, there are no plans to render code lens the way as in VSCode, it's just the extra actions that are show in the menu. ------------------ As part of the attempts to use rust-analyzer LSP data about the runnables, I've explored a way to get this data via standard LSP. When particular experimental client capabilities are enabled (similar to how clangd does this now), r-a starts to send back code lens with the data needed to run a cargo command: ``` {"jsonrpc":"2.0","id":48,"result":{"range":{"start":{"line":0,"character":0},"end":{"line":98,"character":0}},"command":{"title":"▶︎ Run Tests","command":"rust-analyzer.runSingle","arguments":[{"label":"test-mod tests::ecparser","location":{"targetUri":"file:///Users/someonetoignore/work/ec4rs/src/tests/ecparser.rs","targetRange":{"start":{"line":0,"character":0},"end":{"line":98,"character":0}},"targetSelectionRange":{"start":{"line":0,"character":0},"end":{"line":98,"character":0}}},"kind":"cargo","args":{"environment":{"RUSTC_TOOLCHAIN":"/Users/someonetoignore/.rustup/toolchains/1.85-aarch64-apple-darwin"},"cwd":"/Users/someonetoignore/work/ec4rs","overrideCargo":null,"workspaceRoot":"/Users/someonetoignore/work/ec4rs","cargoArgs":["test","--package","ec4rs","--lib"],"executableArgs":["tests::ecparser","--show-output"]}}]}}} ``` This data is passed as is to VSCode task processor, registered in60cd01864a/editors/code/src/main.ts (L195)
where it gets eventually executed as a VSCode's task, all handled by the r-a's extension code. rust-analyzer does not declare server capabilities for such tasks, and has no `workspace/executeCommand` handle, and Zed needs an interactive terminal output during the test runs, so we cannot ask rust-analyzer more than these descriptions. Given that Zed needs experimental capabilities set to get these lens:60cd01864a/editors/code/src/client.ts (L318-L327)
and that the lens may contain other odd tasks (e.g. docs opening or references lookup), a protocol extension to get runnables looks more preferred than lens: https://rust-analyzer.github.io/book/contributing/lsp-extensions.html#runnables This PR does not include any work on this direction, limiting to the general code lens support. As a proof of concept, it's possible to get the lens and even attempt to run it, to no avail:  Release Notes: - Used `textDocument/codeLens` data in the actions menu when applicable
This commit is contained in:
parent
0b492c11de
commit
b61171f152
13 changed files with 618 additions and 19 deletions
|
@ -346,7 +346,12 @@ message Envelope {
|
|||
GitDiff git_diff = 319;
|
||||
GitDiffResponse git_diff_response = 320;
|
||||
|
||||
GitInit git_init = 321; // current max
|
||||
GitInit git_init = 321;
|
||||
|
||||
CodeLens code_lens = 322;
|
||||
GetCodeLens get_code_lens = 323;
|
||||
GetCodeLensResponse get_code_lens_response = 324;
|
||||
RefreshCodeLens refresh_code_lens = 325; // current max
|
||||
}
|
||||
|
||||
reserved 87 to 88;
|
||||
|
@ -1263,6 +1268,25 @@ message RefreshInlayHints {
|
|||
uint64 project_id = 1;
|
||||
}
|
||||
|
||||
message CodeLens {
|
||||
bytes lsp_lens = 1;
|
||||
}
|
||||
|
||||
message GetCodeLens {
|
||||
uint64 project_id = 1;
|
||||
uint64 buffer_id = 2;
|
||||
repeated VectorClockEntry version = 3;
|
||||
}
|
||||
|
||||
message GetCodeLensResponse {
|
||||
repeated CodeAction lens_actions = 1;
|
||||
repeated VectorClockEntry version = 2;
|
||||
}
|
||||
|
||||
message RefreshCodeLens {
|
||||
uint64 project_id = 1;
|
||||
}
|
||||
|
||||
message MarkupContent {
|
||||
bool is_markdown = 1;
|
||||
string value = 2;
|
||||
|
@ -1298,9 +1322,11 @@ message CodeAction {
|
|||
Anchor end = 3;
|
||||
bytes lsp_action = 4;
|
||||
Kind kind = 5;
|
||||
bool resolved = 6;
|
||||
enum Kind {
|
||||
Action = 0;
|
||||
Command = 1;
|
||||
CodeLens = 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2346,6 +2372,7 @@ message MultiLspQuery {
|
|||
GetHover get_hover = 5;
|
||||
GetCodeActions get_code_actions = 6;
|
||||
GetSignatureHelp get_signature_help = 7;
|
||||
GetCodeLens get_code_lens = 8;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2365,6 +2392,7 @@ message LspResponse {
|
|||
GetHoverResponse get_hover_response = 1;
|
||||
GetCodeActionsResponse get_code_actions_response = 2;
|
||||
GetSignatureHelpResponse get_signature_help_response = 3;
|
||||
GetCodeLensResponse get_code_lens_response = 4;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -340,6 +340,9 @@ messages!(
|
|||
(ResolveCompletionDocumentationResponse, Background),
|
||||
(ResolveInlayHint, Background),
|
||||
(ResolveInlayHintResponse, Background),
|
||||
(RefreshCodeLens, Background),
|
||||
(GetCodeLens, Background),
|
||||
(GetCodeLensResponse, Background),
|
||||
(RespondToChannelInvite, Foreground),
|
||||
(RespondToContactRequest, Foreground),
|
||||
(RoomUpdated, Foreground),
|
||||
|
@ -513,6 +516,7 @@ request_messages!(
|
|||
(GetUsers, UsersResponse),
|
||||
(IncomingCall, Ack),
|
||||
(InlayHints, InlayHintsResponse),
|
||||
(GetCodeLens, GetCodeLensResponse),
|
||||
(InviteChannelMember, Ack),
|
||||
(JoinChannel, JoinRoomResponse),
|
||||
(JoinChannelBuffer, JoinChannelBufferResponse),
|
||||
|
@ -534,6 +538,7 @@ request_messages!(
|
|||
(PrepareRename, PrepareRenameResponse),
|
||||
(CountLanguageModelTokens, CountLanguageModelTokensResponse),
|
||||
(RefreshInlayHints, Ack),
|
||||
(RefreshCodeLens, Ack),
|
||||
(RejoinChannelBuffers, RejoinChannelBuffersResponse),
|
||||
(RejoinRoom, RejoinRoomResponse),
|
||||
(ReloadBuffers, ReloadBuffersResponse),
|
||||
|
@ -632,6 +637,7 @@ entity_messages!(
|
|||
ApplyCodeActionKind,
|
||||
FormatBuffers,
|
||||
GetCodeActions,
|
||||
GetCodeLens,
|
||||
GetCompletions,
|
||||
GetDefinition,
|
||||
GetDeclaration,
|
||||
|
@ -659,6 +665,7 @@ entity_messages!(
|
|||
PerformRename,
|
||||
PrepareRename,
|
||||
RefreshInlayHints,
|
||||
RefreshCodeLens,
|
||||
ReloadBuffers,
|
||||
RemoveProjectCollaborator,
|
||||
RenameProjectEntry,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue