Protect against solargraph LSP violations (#66157)

Closes https://github.com/zed-industries/zed/issues/65974

Upstream issue for the context:
https://github.com/castwide/solargraph/issues/1455

Release Notes:

- Fixed solargraph completions causing Zed to panic in certain cases
This commit is contained in:
Kirill Bulatov authored and GitHub committed 2026-10-27 14:32:31 +00:00
1 parent 24a2823456
commit 37faef81f7
2 files changed
+61 -2

No files matched your search

+4 -2
View File
@@ -1009,8 +1009,10 @@ impl CompletionsMenu {
label_match.string == completion.label.filter_text()
})
.or_else(|| {
(completion.filter_text() == completion.label.filter_text())
.then_some(mat)
// Some servers change labels during resolve despite our advertised capabilities.
// Match offsets index mat.string: the candidate text, not the user's query.
// Reuse those offsets only if that text equals the displayed label's filter slice.
(mat.string == completion.label.filter_text()).then_some(mat)
})
.into_iter()
.flat_map(|string_match| {
+57
View File
@@ -29736,6 +29736,63 @@ async fn test_completions_with_additional_edits_and_multiple_cursors(cx: &mut Te
);
}
#[gpui::test]
async fn test_completions_resolve_shortens_label(cx: &mut TestAppContext) {
init_test(cx, |_| {});
let mut cx = EditorLspTestContext::new_with_adapter(
Arc::into_inner(rust_lang()).expect("Rust language should have a single owner"),
FakeLspAdapter {
capabilities: lsp::ServerCapabilities {
completion_provider: Some(lsp::CompletionOptions {
resolve_provider: Some(true),
..lsp::CompletionOptions::default()
}),
..lsp::ServerCapabilities::default()
},
initializer: Some(Box::new(|server| {
server.set_request_handler::<lsp::request::Completion, _, _>(|_, _| async move {
Ok(Some(lsp::CompletionResponse::Array(vec![
lsp::CompletionItem {
label: "long_keyword_argument_name:".to_string(),
detail: Some("=> Symbol".to_string()),
..lsp::CompletionItem::default()
},
])))
});
server.set_request_handler::<lsp::request::ResolveCompletionItem, _, _>(
|mut item, _| async move {
item.label.clear();
item.detail = Some("=> Class<>".to_string());
Ok(item)
},
);
})),
..FakeLspAdapter::default()
},
cx,
)
.await;
cx.set_state("long_keyword_argˇ");
cx.dispatch_action(ShowCompletions);
cx.condition(|editor, _| {
let context_menu = editor.context_menu.borrow();
let Some(CodeContextMenu::Completions(menu)) = context_menu.as_ref() else {
return false;
};
menu.completions
.borrow()
.iter()
.any(|completion| completion.label.text() == " => Class<>")
})
.await;
cx.update(|window, cx| {
window.refresh();
let _ = window.draw(cx);
});
}
#[gpui::test]
async fn test_completions_resolve_updates_labels_if_filter_text_matches(cx: &mut TestAppContext) {
init_test(cx, |_| {});