assistant: Improve /docs
argument completions (#13876)
This PR improves the completions for arguments in the `/docs` slash command. We achieved this by extending the `complete_argument` method on the `SlashCommand` trait to return a `Vec<ArgumentCompletion>` instead of a `Vec<String>`. In addition to the completion `label`, `ArgumentCompletion` has two new fields that are can be used to customize the completion behavior: - `new_text`: The actual text that will be inserted when the completion is accepted, which may be different from what is shown by the completion label. - `run_command`: Whether the command is run when the completion is accepted. This can be set to `false` to allow accepting a completion without running the command. Release Notes: - N/A --------- Co-authored-by: Antonio <antonio@zed.dev>
This commit is contained in:
parent
ca27f42a9d
commit
68accaeb00
15 changed files with 115 additions and 40 deletions
|
@ -1,6 +1,6 @@
|
|||
use super::{diagnostics_command::write_single_file_diagnostics, SlashCommand, SlashCommandOutput};
|
||||
use anyhow::{anyhow, Result};
|
||||
use assistant_slash_command::SlashCommandOutputSection;
|
||||
use assistant_slash_command::{ArgumentCompletion, SlashCommandOutputSection};
|
||||
use fuzzy::PathMatch;
|
||||
use gpui::{AppContext, Model, Task, View, WeakView};
|
||||
use language::{BufferSnapshot, LineEnding, LspAdapterDelegate};
|
||||
|
@ -105,7 +105,7 @@ impl SlashCommand for FileSlashCommand {
|
|||
cancellation_flag: Arc<AtomicBool>,
|
||||
workspace: Option<WeakView<Workspace>>,
|
||||
cx: &mut AppContext,
|
||||
) -> Task<Result<Vec<String>>> {
|
||||
) -> Task<Result<Vec<ArgumentCompletion>>> {
|
||||
let Some(workspace) = workspace.and_then(|workspace| workspace.upgrade()) else {
|
||||
return Task::ready(Err(anyhow!("workspace was dropped")));
|
||||
};
|
||||
|
@ -116,11 +116,17 @@ impl SlashCommand for FileSlashCommand {
|
|||
.await
|
||||
.into_iter()
|
||||
.map(|path_match| {
|
||||
format!(
|
||||
let text = format!(
|
||||
"{}{}",
|
||||
path_match.path_prefix,
|
||||
path_match.path.to_string_lossy()
|
||||
)
|
||||
);
|
||||
|
||||
ArgumentCompletion {
|
||||
label: text.clone(),
|
||||
new_text: text,
|
||||
run_command: true,
|
||||
}
|
||||
})
|
||||
.collect())
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue