lsp: Track completion triggers for each language separately (#20471)
This PR improves how we handle completions in buffers with multiple LSPs. Context: while working on https://github.com/zed-industries/zed/issues/19777 with @mgsloan we noticed that completion triggers coming from language servers are not tracked properly. Namely, each buffer has `completion_triggers` field which is read from the configuration of a language server. The problem is, there can be multiple language servers for a single buffer, in which case we'd just stick to the one that was registered last. This PR makes the tracking a bit more fine-grained. We now track not only what the completion triggers are, but also their origin server id. Whenever completion triggers are updated, we recreate the completion triggers set. Release Notes: - Fixed completions not triggering when multiple language servers are used for a single file.
This commit is contained in:
@@ -481,7 +481,11 @@ async fn test_managing_language_servers(cx: &mut gpui::TestAppContext) {
|
||||
// The buffer is configured based on the language server's capabilities.
|
||||
rust_buffer.update(cx, |buffer, _| {
|
||||
assert_eq!(
|
||||
buffer.completion_triggers(),
|
||||
buffer
|
||||
.completion_triggers()
|
||||
.into_iter()
|
||||
.cloned()
|
||||
.collect::<Vec<_>>(),
|
||||
&[".".to_string(), "::".to_string()]
|
||||
);
|
||||
});
|
||||
@@ -528,7 +532,14 @@ async fn test_managing_language_servers(cx: &mut gpui::TestAppContext) {
|
||||
// This buffer is configured based on the second language server's
|
||||
// capabilities.
|
||||
json_buffer.update(cx, |buffer, _| {
|
||||
assert_eq!(buffer.completion_triggers(), &[":".to_string()]);
|
||||
assert_eq!(
|
||||
buffer
|
||||
.completion_triggers()
|
||||
.into_iter()
|
||||
.cloned()
|
||||
.collect::<Vec<_>>(),
|
||||
&[":".to_string()]
|
||||
);
|
||||
});
|
||||
|
||||
// When opening another buffer whose language server is already running,
|
||||
@@ -541,7 +552,11 @@ async fn test_managing_language_servers(cx: &mut gpui::TestAppContext) {
|
||||
.unwrap();
|
||||
rust_buffer2.update(cx, |buffer, _| {
|
||||
assert_eq!(
|
||||
buffer.completion_triggers(),
|
||||
buffer
|
||||
.completion_triggers()
|
||||
.into_iter()
|
||||
.cloned()
|
||||
.collect::<Vec<_>>(),
|
||||
&[".".to_string(), "::".to_string()]
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user