Run slash commands both on enter and on argument completion that requires it (#16283)

Release Notes:

- N/A
This commit is contained in:
Kirill Bulatov 2024-08-15 19:36:30 +03:00 committed by GitHub
parent 5a30e29848
commit c45adce2e3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 61 additions and 34 deletions

View file

@ -97,20 +97,25 @@ impl SlashCommandCompletionProvider {
let command = commands.command(&mat.string)?;
let mut new_text = mat.string.clone();
let requires_argument = command.requires_argument();
if requires_argument {
let accepts_arguments = command.accepts_arguments();
if requires_argument || accepts_arguments {
new_text.push(' ');
}
let confirm = editor.clone().zip(workspace.clone()).and_then(
|(editor, workspace)| {
(!requires_argument).then(|| {
let confirm =
editor
.clone()
.zip(workspace.clone())
.map(|(editor, workspace)| {
let command_name = mat.string.clone();
let command_range = command_range.clone();
let editor = editor.clone();
let workspace = workspace.clone();
Arc::new(
move |intent: CompletionIntent, cx: &mut WindowContext| {
if intent.is_complete() {
if !requires_argument
&& (!accepts_arguments || intent.is_complete())
{
editor
.update(cx, |editor, cx| {
editor.run_command(
@ -123,12 +128,13 @@ impl SlashCommandCompletionProvider {
);
})
.ok();
false
} else {
requires_argument || accepts_arguments
}
},
) as Arc<_>
})
},
);
});
Some(project::Completion {
old_range: name_range.clone(),
documentation: Some(Documentation::SingleLine(command.description())),
@ -136,7 +142,6 @@ impl SlashCommandCompletionProvider {
label: command.label(cx),
server_id: LanguageServerId(0),
lsp_completion: Default::default(),
show_new_completions_on_confirm: requires_argument,
confirm,
})
})
@ -175,7 +180,7 @@ impl SlashCommandCompletionProvider {
.await?
.into_iter()
.map(|new_argument| {
let confirm = if new_argument.run_command {
let confirm =
editor
.clone()
.zip(workspace.clone())
@ -192,7 +197,7 @@ impl SlashCommandCompletionProvider {
let command_range = command_range.clone();
let command_name = command_name.clone();
move |intent: CompletionIntent, cx: &mut WindowContext| {
if intent.is_complete() {
if new_argument.run_command || intent.is_complete() {
editor
.update(cx, |editor, cx| {
editor.run_command(
@ -205,13 +210,13 @@ impl SlashCommandCompletionProvider {
);
})
.ok();
false
} else {
!new_argument.run_command
}
}
}) as Arc<_>
})
} else {
None
};
});
let mut new_text = new_argument.new_text.clone();
if !new_argument.run_command {
@ -229,7 +234,6 @@ impl SlashCommandCompletionProvider {
documentation: None,
server_id: LanguageServerId(0),
lsp_completion: Default::default(),
show_new_completions_on_confirm: !new_argument.run_command,
confirm,
}
})