ZIm/crates/project/src
Kirill Bulatov b61171f152
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:


![image](https://github.com/user-attachments/assets/6161e87f-f4b4-4173-8bf9-30db5e94b1ce)

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 in


60cd01864a/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:

![image](https://github.com/user-attachments/assets/56950880-d387-48f9-b865-727f97b5633b)


Release Notes:

- Used `textDocument/codeLens` data in the actions menu when applicable
2025-03-15 09:50:32 +02:00
..
lsp_command Remove language::markdown (#25136) 2025-02-19 08:55:36 -07:00
lsp_store Use textDocument/codeLens data in the actions menu when applicable (#26811) 2025-03-15 09:50:32 +02:00
project_tree cx.background_executor().spawn(...) -> cx.background_spawn(...) (#25103) 2025-02-18 20:30:33 +00:00
buffer_store.rs Git on main thread (#26573) 2025-03-12 19:39:30 +00:00
color_extractor.rs Simplify static expression to a constant (#23193) 2025-01-15 19:31:21 +00:00
connection_manager.rs Remove more references to 'model' in GPUI APIs (#23693) 2025-01-27 04:00:27 +00:00
debounced_delay.rs Rename model based variable names to entity (#24198) 2025-02-04 10:24:35 -08:00
direnv.rs Environment loading fixes (#19144) 2024-10-16 12:14:40 +02:00
environment.rs Remove worktree and project notifies (#26244) 2025-03-07 10:51:46 -07:00
git.rs Git on main thread (#26573) 2025-03-12 19:39:30 +00:00
image_store.rs cx.background_executor().spawn(...) -> cx.background_spawn(...) (#25103) 2025-02-18 20:30:33 +00:00
lsp_command.rs Use textDocument/codeLens data in the actions menu when applicable (#26811) 2025-03-15 09:50:32 +02:00
lsp_store.rs Use textDocument/codeLens data in the actions menu when applicable (#26811) 2025-03-15 09:50:32 +02:00
prettier_store.rs cx.background_executor().spawn(...) -> cx.background_spawn(...) (#25103) 2025-02-18 20:30:33 +00:00
project.rs Use textDocument/codeLens data in the actions menu when applicable (#26811) 2025-03-15 09:50:32 +02:00
project_settings.rs git: Remove hunk style setting (#26504) 2025-03-12 00:35:34 -04:00
project_tests.rs Refine word completions (#26779) 2025-03-14 15:18:55 +00:00
project_tree.rs cx.background_executor().spawn(...) -> cx.background_spawn(...) (#25103) 2025-02-18 20:30:33 +00:00
search.rs Revert "Use multi-line regex for '\s'" (#25926) 2025-03-03 10:32:49 -05:00
search_history.rs project search: Persist search history across session (#9932) 2024-04-02 11:13:18 +02:00
task_inventory.rs Use active worktree's task sources (#25784) 2025-02-27 22:57:59 +00:00
task_store.rs Rename model based variable names to entity (#24198) 2025-02-04 10:24:35 -08:00
terminals.rs vim: Fix tab title when using !! and disable rerun button for terminal tasks (#26122) 2025-03-05 08:47:49 -07:00
toolchain_store.rs cx.background_executor().spawn(...) -> cx.background_spawn(...) (#25103) 2025-02-18 20:30:33 +00:00
worktree_store.rs Fix git branches in non-active repository (#26148) 2025-03-05 21:16:46 +00:00
yarn.rs Eliminate GPUI View, ViewContext, and WindowContext types (#22632) 2025-01-26 03:02:45 +00:00