assistant: Include diagnostics in slash commands by default (#13359)

Include error diagnostics by default for the following slash commands:
`/file`, `/tabs`, `/active`

Release Notes:

- N/A
This commit is contained in:
Bennet Bo Fenner
2024-06-21 14:28:12 +02:00
committed by GitHub
parent 9bdb154a9b
commit abb46473c9
4 changed files with 117 additions and 84 deletions
@@ -1,4 +1,5 @@
use super::{
diagnostics_command::write_single_file_diagnostics,
file_command::{build_entry_output_section, codeblock_fence_for_path},
SlashCommand, SlashCommandOutput,
};
@@ -60,24 +61,28 @@ impl SlashCommand for ActiveSlashCommand {
let snapshot = buffer.read(cx).snapshot();
let path = snapshot.resolve_file_path(cx, true);
let text = cx.background_executor().spawn({
let task = cx.background_executor().spawn({
let path = path.clone();
async move {
let mut output = String::new();
output.push_str(&codeblock_fence_for_path(path.as_deref(), None));
output.push('\n');
for chunk in snapshot.as_rope().chunks() {
output.push_str(chunk);
}
if !output.ends_with('\n') {
output.push('\n');
}
output.push_str("```");
output
output.push_str("```\n");
let has_diagnostics =
write_single_file_diagnostics(&mut output, path.as_deref(), &snapshot);
if output.ends_with('\n') {
output.pop();
}
(output, has_diagnostics)
}
});
cx.foreground_executor().spawn(async move {
let text = text.await;
let (text, has_diagnostics) = task.await;
let range = 0..text.len();
Ok(SlashCommandOutput {
text,
@@ -87,7 +92,7 @@ impl SlashCommand for ActiveSlashCommand {
false,
None,
)],
run_commands_in_text: false,
run_commands_in_text: has_diagnostics,
})
})
});