mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-29 05:33:49 +00:00
zeta: Validate completion responses for markers (#22840)
Check for markers and how many there are to avoid markers showing up in completions. Release Notes: - N/A
This commit is contained in:
parent
9850bf8022
commit
a248981fca
1 changed files with 28 additions and 3 deletions
|
@ -582,9 +582,34 @@ and then another
|
||||||
cx.background_executor().spawn(async move {
|
cx.background_executor().spawn(async move {
|
||||||
let content = output_excerpt.replace(CURSOR_MARKER, "");
|
let content = output_excerpt.replace(CURSOR_MARKER, "");
|
||||||
|
|
||||||
let codefence_start = content
|
let start_markers = content
|
||||||
.find(EDITABLE_REGION_START_MARKER)
|
.match_indices(EDITABLE_REGION_START_MARKER)
|
||||||
.context("could not find start marker")?;
|
.collect::<Vec<_>>();
|
||||||
|
anyhow::ensure!(
|
||||||
|
start_markers.len() == 1,
|
||||||
|
"expected exactly one start marker, found {}",
|
||||||
|
start_markers.len()
|
||||||
|
);
|
||||||
|
|
||||||
|
let end_markers = content
|
||||||
|
.match_indices(EDITABLE_REGION_END_MARKER)
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
anyhow::ensure!(
|
||||||
|
end_markers.len() == 1,
|
||||||
|
"expected exactly one end marker, found {}",
|
||||||
|
end_markers.len()
|
||||||
|
);
|
||||||
|
|
||||||
|
let sof_markers = content
|
||||||
|
.match_indices(START_OF_FILE_MARKER)
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
anyhow::ensure!(
|
||||||
|
sof_markers.len() <= 1,
|
||||||
|
"expected at most one start-of-file marker, found {}",
|
||||||
|
sof_markers.len()
|
||||||
|
);
|
||||||
|
|
||||||
|
let codefence_start = start_markers[0].0;
|
||||||
let content = &content[codefence_start..];
|
let content = &content[codefence_start..];
|
||||||
|
|
||||||
let newline_ix = content.find('\n').context("could not find newline")?;
|
let newline_ix = content.find('\n').context("could not find newline")?;
|
||||||
|
|
Loading…
Reference in a new issue