mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-03 15:22:13 +00:00
Avoid bailing out of Project::symbols when one LSP request fails
This commit is contained in:
parent
e9214dc05d
commit
ae9f71cc07
1 changed files with 65 additions and 70 deletions
|
@ -2270,44 +2270,45 @@ impl Project {
|
||||||
|
|
||||||
pub fn symbols(&self, query: &str, cx: &mut ModelContext<Self>) -> Task<Result<Vec<Symbol>>> {
|
pub fn symbols(&self, query: &str, cx: &mut ModelContext<Self>) -> Task<Result<Vec<Symbol>>> {
|
||||||
if self.is_local() {
|
if self.is_local() {
|
||||||
let mut language_servers = HashMap::default();
|
let mut requests = Vec::new();
|
||||||
for ((worktree_id, _), (lsp_adapter, language_server)) in self.language_servers.iter() {
|
for ((worktree_id, _), (lsp_adapter, language_server)) in self.language_servers.iter() {
|
||||||
|
let worktree_id = *worktree_id;
|
||||||
if let Some(worktree) = self
|
if let Some(worktree) = self
|
||||||
.worktree_for_id(*worktree_id, cx)
|
.worktree_for_id(worktree_id, cx)
|
||||||
.and_then(|worktree| worktree.read(cx).as_local())
|
.and_then(|worktree| worktree.read(cx).as_local())
|
||||||
{
|
{
|
||||||
language_servers
|
let lsp_adapter = lsp_adapter.clone();
|
||||||
.entry(Arc::as_ptr(language_server))
|
let worktree_abs_path = worktree.abs_path().clone();
|
||||||
.or_insert((
|
requests.push(
|
||||||
lsp_adapter.clone(),
|
language_server
|
||||||
language_server.clone(),
|
.request::<lsp::request::WorkspaceSymbol>(lsp::WorkspaceSymbolParams {
|
||||||
*worktree_id,
|
|
||||||
worktree.abs_path().clone(),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut requests = Vec::new();
|
|
||||||
for (_, language_server, _, _) in language_servers.values() {
|
|
||||||
requests.push(language_server.request::<lsp::request::WorkspaceSymbol>(
|
|
||||||
lsp::WorkspaceSymbolParams {
|
|
||||||
query: query.to_string(),
|
query: query.to_string(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
})
|
||||||
));
|
.log_err()
|
||||||
|
.map(move |response| {
|
||||||
|
(
|
||||||
|
lsp_adapter,
|
||||||
|
worktree_id,
|
||||||
|
worktree_abs_path,
|
||||||
|
response.unwrap_or_default(),
|
||||||
|
)
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cx.spawn_weak(|this, cx| async move {
|
cx.spawn_weak(|this, cx| async move {
|
||||||
let responses = futures::future::try_join_all(requests).await?;
|
let responses = futures::future::join_all(requests).await;
|
||||||
|
let this = if let Some(this) = this.upgrade(&cx) {
|
||||||
let mut symbols = Vec::new();
|
this
|
||||||
if let Some(this) = this.upgrade(&cx) {
|
} else {
|
||||||
|
return Ok(Default::default());
|
||||||
|
};
|
||||||
this.read_with(&cx, |this, cx| {
|
this.read_with(&cx, |this, cx| {
|
||||||
for ((adapter, _, source_worktree_id, worktree_abs_path), lsp_symbols) in
|
let mut symbols = Vec::new();
|
||||||
language_servers.into_values().zip(responses)
|
for (adapter, source_worktree_id, worktree_abs_path, response) in responses {
|
||||||
{
|
symbols.extend(response.into_iter().flatten().filter_map(|lsp_symbol| {
|
||||||
symbols.extend(lsp_symbols.into_iter().flatten().filter_map(
|
|
||||||
|lsp_symbol| {
|
|
||||||
let abs_path = lsp_symbol.location.uri.to_file_path().ok()?;
|
let abs_path = lsp_symbol.location.uri.to_file_path().ok()?;
|
||||||
let mut worktree_id = source_worktree_id;
|
let mut worktree_id = source_worktree_id;
|
||||||
let path;
|
let path;
|
||||||
|
@ -2324,12 +2325,9 @@ impl Project {
|
||||||
.languages
|
.languages
|
||||||
.select_language(&path)
|
.select_language(&path)
|
||||||
.and_then(|language| {
|
.and_then(|language| {
|
||||||
language
|
language.label_for_symbol(&lsp_symbol.name, lsp_symbol.kind)
|
||||||
.label_for_symbol(&lsp_symbol.name, lsp_symbol.kind)
|
|
||||||
})
|
})
|
||||||
.unwrap_or_else(|| {
|
.unwrap_or_else(|| CodeLabel::plain(lsp_symbol.name.clone(), None));
|
||||||
CodeLabel::plain(lsp_symbol.name.clone(), None)
|
|
||||||
});
|
|
||||||
let signature = this.symbol_signature(worktree_id, &path);
|
let signature = this.symbol_signature(worktree_id, &path);
|
||||||
|
|
||||||
Some(Symbol {
|
Some(Symbol {
|
||||||
|
@ -2343,14 +2341,11 @@ impl Project {
|
||||||
range: range_from_lsp(lsp_symbol.location.range),
|
range: range_from_lsp(lsp_symbol.location.range),
|
||||||
signature,
|
signature,
|
||||||
})
|
})
|
||||||
},
|
}));
|
||||||
));
|
|
||||||
}
|
}
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(symbols)
|
Ok(symbols)
|
||||||
})
|
})
|
||||||
|
})
|
||||||
} else if let Some(project_id) = self.remote_id() {
|
} else if let Some(project_id) = self.remote_id() {
|
||||||
let request = self.client.request(proto::GetProjectSymbols {
|
let request = self.client.request(proto::GetProjectSymbols {
|
||||||
project_id,
|
project_id,
|
||||||
|
|
Loading…
Reference in a new issue