Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lsp_store: Do not associate a language server with the language for symbol highlighting #23401

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 15 additions & 39 deletions crates/project/src/lsp_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{
use anyhow::{anyhow, Context as _, Result};
use async_trait::async_trait;
use client::{proto, TypedEnvelope};
use collections::{btree_map, BTreeMap, HashMap, HashSet};
use collections::{btree_map, BTreeMap, BTreeSet, HashMap, HashSet};
use futures::{
future::{join_all, Shared},
select,
Expand Down Expand Up @@ -172,7 +172,6 @@ impl LocalLspStore {
worktree_handle: &Model<Worktree>,
delegate: Arc<LocalLspAdapterDelegate>,
adapter: Arc<CachedLspAdapter>,
language: LanguageName,
cx: &mut ModelContext<LspStore>,
) {
let worktree = worktree_handle.read(cx);
Expand Down Expand Up @@ -243,7 +242,6 @@ impl LocalLspStore {
let state = LanguageServerState::Starting({
let server_name = adapter.name.0.clone();
let delegate = delegate as Arc<dyn LspAdapterDelegate>;
let language = language.clone();
let key = key.clone();
let adapter = adapter.clone();

Expand Down Expand Up @@ -324,7 +322,6 @@ impl LocalLspStore {
Ok(server) => {
this.update(&mut cx, |this, mut cx| {
this.insert_newly_running_language_server(
language,
adapter,
server.clone(),
server_id,
Expand Down Expand Up @@ -416,7 +413,7 @@ impl LocalLspStore {
self.fs.clone(),
cx,
);
self.start_language_server(worktree, delegate, adapter.clone(), language.clone(), cx);
self.start_language_server(worktree, delegate, adapter.clone(), cx);
}

// After starting all the language servers, reorder them to reflect the desired order
Expand Down Expand Up @@ -4797,20 +4794,13 @@ impl LspStore {
.into_iter()
.filter_map(|symbol| Self::deserialize_symbol(symbol).log_err())
.collect::<Vec<_>>();
populate_labels_for_symbols(
core_symbols,
&language_registry,
None,
None,
&mut symbols,
)
.await;
populate_labels_for_symbols(core_symbols, &language_registry, None, &mut symbols)
.await;
Ok(symbols)
})
} else if let Some(local) = self.as_local() {
struct WorkspaceSymbolsResult {
lsp_adapter: Arc<CachedLspAdapter>,
language: LanguageName,
worktree: WeakModel<Worktree>,
worktree_abs_path: Arc<Path>,
lsp_symbols: Vec<(String, SymbolKind, lsp::Location)>,
Expand All @@ -4831,13 +4821,10 @@ impl LspStore {
}
let worktree_abs_path = worktree.abs_path().clone();

let (lsp_adapter, language, server) = match local.language_servers.get(server_id) {
let (lsp_adapter, server) = match local.language_servers.get(server_id) {
Some(LanguageServerState::Running {
adapter,
language,
server,
..
}) => (adapter.clone(), language.clone(), server),
adapter, server, ..
}) => (adapter.clone(), server),

_ => continue,
};
Expand Down Expand Up @@ -4874,7 +4861,7 @@ impl LspStore {

WorkspaceSymbolsResult {
lsp_adapter,
language,

worktree: worktree_handle.downgrade(),
worktree_abs_path,
lsp_symbols,
Expand Down Expand Up @@ -4935,7 +4922,6 @@ impl LspStore {
populate_labels_for_symbols(
core_symbols,
&language_registry,
Some(result.language),
Some(result.lsp_adapter),
&mut symbols,
)
Expand Down Expand Up @@ -7467,7 +7453,6 @@ impl LspStore {

fn insert_newly_running_language_server(
&mut self,
language: LanguageName,
adapter: Arc<CachedLspAdapter>,
language_server: Arc<LanguageServer>,
server_id: LanguageServerId,
Expand All @@ -7494,7 +7479,6 @@ impl LspStore {
server_id,
LanguageServerState::Running {
adapter: adapter.clone(),
language: language.clone(),
server: language_server.clone(),
simulate_disk_based_diagnostics_completion: None,
},
Expand Down Expand Up @@ -8298,7 +8282,6 @@ pub enum LanguageServerState {
Starting(Task<Option<Arc<LanguageServer>>>),

Running {
language: LanguageName,
adapter: Arc<CachedLspAdapter>,
server: Arc<LanguageServer>,
simulate_disk_based_diagnostics_completion: Option<Task<()>>,
Expand All @@ -8311,10 +8294,9 @@ impl std::fmt::Debug for LanguageServerState {
LanguageServerState::Starting(_) => {
f.debug_struct("LanguageServerState::Starting").finish()
}
LanguageServerState::Running { language, .. } => f
.debug_struct("LanguageServerState::Running")
.field("language", &language)
.finish(),
LanguageServerState::Running { .. } => {
f.debug_struct("LanguageServerState::Running").finish()
}
}
}
}
Expand Down Expand Up @@ -8654,35 +8636,29 @@ impl LspAdapterDelegate for LocalLspAdapterDelegate {
async fn populate_labels_for_symbols(
symbols: Vec<CoreSymbol>,
language_registry: &Arc<LanguageRegistry>,
default_language: Option<LanguageName>,
lsp_adapter: Option<Arc<CachedLspAdapter>>,
output: &mut Vec<Symbol>,
) {
#[allow(clippy::mutable_key_type)]
let mut symbols_by_language = HashMap::<Option<Arc<Language>>, Vec<CoreSymbol>>::default();

let mut unknown_path = None;
let mut unknown_paths = BTreeSet::new();
for symbol in symbols {
let language = language_registry
.language_for_file_path(&symbol.path.path)
.await
.ok()
.or_else(|| {
unknown_path.get_or_insert(symbol.path.path.clone());
default_language.as_ref().and_then(|name| {
language_registry
.language_for_name(&name.0)
.now_or_never()?
.ok()
})
unknown_paths.insert(symbol.path.path.clone());
None
});
symbols_by_language
.entry(language)
.or_default()
.push(symbol);
}

if let Some(unknown_path) = unknown_path {
for unknown_path in unknown_paths {
log::info!(
"no language found for symbol path {}",
unknown_path.display()
Expand Down
Loading