Respect the language_servers
setting's order when determining the primary language server (#15624)
This PR updates how we determine the "primary" language server for a buffer to make it respect the order specified by the `language_servers` setting. Previously we were relying on the language servers to be registered in the right order in order to select the primary one effectively. However, in my testing I observed some cases where a native language server (e.g., `tailwindcss-language-server`) could end up first in the list of language servers despite not being first in the `language_servers` setting. While this wasn't a problem for the Tailwind or ESLint language servers on account of them being defined natively with the designation of "secondary" language servers, this could cause problems with extension-based language servers. To remedy this, every time we start up language servers we reorder the list of language servers for a given language to reflect the order in the `language_servers` setting. This ordering then allows us to treat the first language server in the list as the "primary" one. Related issues: - https://github.com/zed-industries/zed/issues/15023 - https://github.com/zed-industries/zed/issues/15279 Release Notes: - The ordering of language servers will now respect the order in the `language_servers` setting. - The first language server in this list will be used as the primary language server.
This commit is contained in:
parent
0b175ac66e
commit
3bd9a3f478
2 changed files with 62 additions and 5 deletions
|
@ -2999,9 +2999,18 @@ impl Project {
|
|||
.join(", ")
|
||||
);
|
||||
|
||||
for adapter in enabled_lsp_adapters {
|
||||
self.start_language_server(worktree, adapter, language.clone(), cx);
|
||||
for adapter in &enabled_lsp_adapters {
|
||||
self.start_language_server(worktree, adapter.clone(), language.clone(), cx);
|
||||
}
|
||||
|
||||
// After starting all the language servers, reorder them to reflect the desired order
|
||||
// based on the settings.
|
||||
//
|
||||
// This is done, in part, to ensure that language servers loaded at different points
|
||||
// (e.g., native vs extension) still end up in the right order at the end, rather than
|
||||
// it being based on which language server happened to be loaded in first.
|
||||
self.languages()
|
||||
.reorder_language_servers(&language, enabled_lsp_adapters);
|
||||
}
|
||||
|
||||
fn start_language_server(
|
||||
|
@ -10247,8 +10256,10 @@ impl Project {
|
|||
buffer: &Buffer,
|
||||
cx: &AppContext,
|
||||
) -> Option<(&Arc<CachedLspAdapter>, &Arc<LanguageServer>)> {
|
||||
self.language_servers_for_buffer(buffer, cx)
|
||||
.find(|s| s.0.is_primary)
|
||||
// The list of language servers is ordered based on the `language_servers` setting
|
||||
// for each language, thus we can consider the first one in the list to be the
|
||||
// primary one.
|
||||
self.language_servers_for_buffer(buffer, cx).next()
|
||||
}
|
||||
|
||||
pub fn language_server_for_buffer(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue