Make applying of additional completion edits go through the CompletionProvider

This commit is contained in:
Max Brunsfeld 2024-01-19 16:56:28 -08:00
parent c8adde32de
commit 8fb0270b4a
2 changed files with 38 additions and 9 deletions

View file

@ -61,6 +61,16 @@ impl CompletionProvider for MessageEditorCompletionProvider {
) -> Task<anyhow::Result<bool>> {
Task::ready(Ok(false))
}
fn apply_additional_edits_for_completion(
&self,
_buffer: Model<Buffer>,
_completion: Completion,
_push_to_history: bool,
_cx: &mut ViewContext<Editor>,
) -> Task<Result<Option<language::Transaction>>> {
Task::ready(Ok(None))
}
}
impl MessageEditor {

View file

@ -3285,15 +3285,13 @@ impl Editor {
this.refresh_copilot_suggestions(true, cx);
});
let project = self.project.clone()?;
let apply_edits = project.update(cx, |project, cx| {
project.apply_additional_edits_for_completion(
buffer_handle,
completion.clone(),
true,
cx,
)
});
let provider = self.completion_provider.as_ref()?;
let apply_edits = provider.apply_additional_edits_for_completion(
buffer_handle,
completion.clone(),
true,
cx,
);
Some(cx.foreground_executor().spawn(async move {
apply_edits.await?;
Ok(())
@ -8912,12 +8910,21 @@ pub trait CompletionProvider {
buffer_position: text::Anchor,
cx: &mut ViewContext<Editor>,
) -> Task<Result<Vec<Completion>>>;
fn resolve_completions(
&self,
completion_indices: Vec<usize>,
completions: Arc<RwLock<Box<[Completion]>>>,
cx: &mut ViewContext<Editor>,
) -> Task<Result<bool>>;
fn apply_additional_edits_for_completion(
&self,
buffer: Model<Buffer>,
completion: Completion,
push_to_history: bool,
cx: &mut ViewContext<Editor>,
) -> Task<Result<Option<language::Transaction>>>;
}
impl CompletionProvider for Model<Project> {
@ -8942,6 +8949,18 @@ impl CompletionProvider for Model<Project> {
project.resolve_completions(completion_indices, completions, cx)
})
}
fn apply_additional_edits_for_completion(
&self,
buffer: Model<Buffer>,
completion: Completion,
push_to_history: bool,
cx: &mut ViewContext<Editor>,
) -> Task<Result<Option<language::Transaction>>> {
self.update(cx, |project, cx| {
project.apply_additional_edits_for_completion(buffer, completion, push_to_history, cx)
})
}
}
fn inlay_hint_settings(