context_servers: Normalize the line endings of context servers (#17112)
Context servers might return CR characters, which are not acceptable in Zed and cause ranges to be invalidated. We need to normalize them. Closes #17109 Release Notes: - context_servers: Fixed an issue where context servers returning a carriage return character would result in a panic.
This commit is contained in:
parent
5bae6eb493
commit
449e744c14
1 changed files with 7 additions and 2 deletions
|
@ -12,6 +12,7 @@ use gpui::{Task, WeakView, WindowContext};
|
||||||
use language::{CodeLabel, LspAdapterDelegate};
|
use language::{CodeLabel, LspAdapterDelegate};
|
||||||
use std::sync::atomic::AtomicBool;
|
use std::sync::atomic::AtomicBool;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use text::LineEnding;
|
||||||
use ui::{IconName, SharedString};
|
use ui::{IconName, SharedString};
|
||||||
use workspace::Workspace;
|
use workspace::Workspace;
|
||||||
|
|
||||||
|
@ -127,10 +128,14 @@ impl SlashCommand for ContextServerSlashCommand {
|
||||||
return Err(anyhow!("Context server not initialized"));
|
return Err(anyhow!("Context server not initialized"));
|
||||||
};
|
};
|
||||||
let result = protocol.run_prompt(&prompt_name, prompt_args).await?;
|
let result = protocol.run_prompt(&prompt_name, prompt_args).await?;
|
||||||
|
let mut prompt = result.prompt;
|
||||||
|
|
||||||
|
// We must normalize the line endings here, since servers might return CR characters.
|
||||||
|
LineEnding::normalize(&mut prompt);
|
||||||
|
|
||||||
Ok(SlashCommandOutput {
|
Ok(SlashCommandOutput {
|
||||||
sections: vec![SlashCommandOutputSection {
|
sections: vec![SlashCommandOutputSection {
|
||||||
range: 0..(result.prompt.len()),
|
range: 0..(prompt.len()),
|
||||||
icon: IconName::ZedAssistant,
|
icon: IconName::ZedAssistant,
|
||||||
label: SharedString::from(
|
label: SharedString::from(
|
||||||
result
|
result
|
||||||
|
@ -138,7 +143,7 @@ impl SlashCommand for ContextServerSlashCommand {
|
||||||
.unwrap_or(format!("Result from {}", prompt_name)),
|
.unwrap_or(format!("Result from {}", prompt_name)),
|
||||||
),
|
),
|
||||||
}],
|
}],
|
||||||
text: result.prompt,
|
text: prompt,
|
||||||
run_commands_in_text: false,
|
run_commands_in_text: false,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue