zed-industries / zed

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
https://zed.dev
Other
49.18k stars 2.98k forks source link

Add assistant command /selection, for action assistant: quote selection #18868

Open AndydeCleyre opened 3 weeks ago

AndydeCleyre commented 3 weeks ago

Check for existing issues

Describe the feature

I finally found the assistant: quote selection action and corresponding shortcut, which is great!

But I'd assumed it wasn't possible, because I expected such an action to be in the same place as the assistant slash-commands /file and /tab.

So I'm requesting an additional slash-command for the assistant, maybe /selection but the name doesn't matter much, that has the same effect as the existing action assistant: quote selection.

If applicable, add mockups / screenshots to help present your vision of the feature

No response

counterleft commented 1 day ago

👋 I have a draft of this feature ongoing.

I made a SelectionCommand slash command that basically copies the logic from quote_selection(). Instead of opening assistant_panel and creating Crease's, I create sections (SlashCommandOutputSection) for each text selection. Those sections are added to the the resulting SlashCommandOutput.

Here's a video of the outcome:

https://github.com/user-attachments/assets/e56ed552-e831-438a-886e-572ce1a57351

The 'no selections found' error case is inspired by the diagnostics_command.

This approach does duplicate much of quote_selection(). I could extract a method that takes the current editor selections and returns a list of tuples of the text required for both methods (label, text, selection ranges), though I don't know which file such a method would want to live.

Also, the end of the word selection is cut off in the slash-command autocomplete. I didn't know where to adjust that. I tried messing with slash_command_picker#render_match() but that didn't seem like the right spot 😅 .

counterleft commented 1 day ago

I just saw https://github.com/zed-industries/zed/pull/19988/files so my WIP may be moot. ¯_(ツ)_/¯