From 13c2021aef36751de2874bab561926e0816ae79d Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Mon, 22 Aug 2022 12:32:58 +0200 Subject: [PATCH] Default to language that started LSP when querying project symbols --- crates/project/src/project.rs | 53 +++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index 0f762f822f..dcab44e373 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -202,6 +202,7 @@ pub enum Event { pub enum LanguageServerState { Starting(Task>>), Running { + language: Arc, adapter: Arc, server: Arc, }, @@ -1969,7 +1970,7 @@ impl Project { uri: lsp::Url::from_file_path(abs_path).unwrap(), }; - for (_, server) in self.language_servers_for_worktree(worktree_id) { + for (_, _, server) in self.language_servers_for_worktree(worktree_id) { server .notify::( lsp::DidSaveTextDocumentParams { @@ -2004,15 +2005,18 @@ impl Project { fn language_servers_for_worktree( &self, worktree_id: WorktreeId, - ) -> impl Iterator, &Arc)> { + ) -> impl Iterator, &Arc, &Arc)> { self.language_server_ids .iter() .filter_map(move |((language_server_worktree_id, _), id)| { if *language_server_worktree_id == worktree_id { - if let Some(LanguageServerState::Running { adapter, server }) = - self.language_servers.get(id) + if let Some(LanguageServerState::Running { + adapter, + language, + server, + }) = self.language_servers.get(id) { - return Some((adapter, server)); + return Some((adapter, language, server)); } } None @@ -2282,6 +2286,7 @@ impl Project { server_id, LanguageServerState::Running { adapter: adapter.clone(), + language, server: language_server.clone(), }, ); @@ -3314,10 +3319,14 @@ impl Project { .worktree_for_id(worktree_id, cx) .and_then(|worktree| worktree.read(cx).as_local()) { - if let Some(LanguageServerState::Running { adapter, server }) = - self.language_servers.get(server_id) + if let Some(LanguageServerState::Running { + adapter, + language, + server, + }) = self.language_servers.get(server_id) { let adapter = adapter.clone(); + let language = language.clone(); let worktree_abs_path = worktree.abs_path().clone(); requests.push( server @@ -3331,6 +3340,7 @@ impl Project { .map(move |response| { ( adapter, + language, worktree_id, worktree_abs_path, response.unwrap_or_default(), @@ -3350,7 +3360,14 @@ impl Project { }; let symbols = this.read_with(&cx, |this, cx| { let mut symbols = Vec::new(); - for (adapter, source_worktree_id, worktree_abs_path, response) in responses { + for ( + adapter, + adapter_language, + source_worktree_id, + worktree_abs_path, + response, + ) in responses + { symbols.extend(response.into_iter().flatten().filter_map(|lsp_symbol| { let abs_path = lsp_symbol.location.uri.to_file_path().ok()?; let mut worktree_id = source_worktree_id; @@ -3369,16 +3386,15 @@ impl Project { path: path.into(), }; let signature = this.symbol_signature(&project_path); - let language = this.languages.select_language(&project_path.path); + let language = this + .languages + .select_language(&project_path.path) + .unwrap_or(adapter_language.clone()); let language_server_name = adapter.name.clone(); Some(async move { - let label = if let Some(language) = language { - language - .label_for_symbol(&lsp_symbol.name, lsp_symbol.kind) - .await - } else { - None - }; + let label = language + .label_for_symbol(&lsp_symbol.name, lsp_symbol.kind) + .await; Symbol { language_server_name, @@ -5940,8 +5956,9 @@ impl Project { let key = (worktree_id, name); if let Some(server_id) = self.language_server_ids.get(&key) { - if let Some(LanguageServerState::Running { adapter, server }) = - self.language_servers.get(server_id) + if let Some(LanguageServerState::Running { + adapter, server, .. + }) = self.language_servers.get(server_id) { return Some((adapter, server)); }