Always wait for completion resolve before applying the completion edits (#18907)

After https://github.com/rust-lang/rust-analyzer/pull/18167 and certain
people who type and complete rapidly, it turned out that we have not
waited for `completionItem/resolve` to finish before applying the
completion results.

Release Notes:

- Fixed completion items applied improperly on fast typing
This commit is contained in:
Kirill Bulatov 2024-10-09 17:18:20 +03:00 committed by GitHub
parent f50bca7630
commit a62a2fa8f7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 144 additions and 63 deletions

View file

@ -7996,7 +7996,7 @@ async fn test_completion(cx: &mut gpui::TestAppContext) {
.unwrap()
});
cx.assert_editor_state(indoc! {"
one.second_completionˇ
one.ˇ
two
three
"});
@ -8029,9 +8029,9 @@ async fn test_completion(cx: &mut gpui::TestAppContext) {
cx.assert_editor_state(indoc! {"
one.second_completionˇ
two
three
additional edit
"});
thoverlapping additional editree
additional edit"});
cx.set_state(indoc! {"
one.second_completion
@ -8091,8 +8091,8 @@ async fn test_completion(cx: &mut gpui::TestAppContext) {
});
cx.assert_editor_state(indoc! {"
one.second_completion
two sixth_completionˇ
three sixth_completionˇ
two siˇ
three siˇ
additional edit
"});
@ -8133,9 +8133,11 @@ async fn test_completion(cx: &mut gpui::TestAppContext) {
.confirm_completion(&ConfirmCompletion::default(), cx)
.unwrap()
});
cx.assert_editor_state("editor.closeˇ");
cx.assert_editor_state("editor.cloˇ");
handle_resolve_completion_request(&mut cx, None).await;
apply_additional_edits.await.unwrap();
cx.assert_editor_state(indoc! {"
editor.closeˇ"});
}
#[gpui::test]
@ -10140,7 +10142,7 @@ async fn test_completions_with_additional_edits(cx: &mut gpui::TestAppContext) {
.confirm_completion(&ConfirmCompletion::default(), cx)
.unwrap()
});
cx.assert_editor_state(indoc! {"fn main() { let a = 2.Some(2)ˇ; }"});
cx.assert_editor_state(indoc! {"fn main() { let a = 2.ˇ; }"});
cx.handle_request::<lsp::request::ResolveCompletionItem, _, _>(move |_, _, _| {
let task_completion_item = completion_item.clone();