mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-10 14:06:11 +03:00
Restore main version of Project::symbols and convert to async
This commit is contained in:
parent
0600157c38
commit
bc94d0d1a9
@ -3312,27 +3312,11 @@ impl Project {
|
|||||||
} else {
|
} else {
|
||||||
return Ok(Default::default());
|
return Ok(Default::default());
|
||||||
};
|
};
|
||||||
|
let symbols = this.read_with(&cx, |this, cx| {
|
||||||
struct PartialSymbol {
|
let mut symbols = Vec::new();
|
||||||
source_worktree_id: WorktreeId,
|
|
||||||
worktree_id: WorktreeId,
|
|
||||||
language_server_name: LanguageServerName,
|
|
||||||
path: PathBuf,
|
|
||||||
language: Option<Arc<Language>>,
|
|
||||||
name: String,
|
|
||||||
kind: lsp::SymbolKind,
|
|
||||||
range: Range<PointUtf16>,
|
|
||||||
signature: [u8; 32],
|
|
||||||
}
|
|
||||||
|
|
||||||
let partial_symbols = this.read_with(&cx, |this, cx| {
|
|
||||||
let mut partial_symbols = Vec::new();
|
|
||||||
for (adapter, source_worktree_id, worktree_abs_path, response) in responses {
|
for (adapter, source_worktree_id, worktree_abs_path, response) in responses {
|
||||||
for lsp_symbol in response.into_iter().flatten() {
|
symbols.extend(response.into_iter().flatten().filter_map(|lsp_symbol| {
|
||||||
let abs_path = match lsp_symbol.location.uri.to_file_path().ok() {
|
let abs_path = lsp_symbol.location.uri.to_file_path().ok()?;
|
||||||
Some(abs_path) => abs_path,
|
|
||||||
None => continue,
|
|
||||||
};
|
|
||||||
let mut worktree_id = source_worktree_id;
|
let mut worktree_id = source_worktree_id;
|
||||||
let path;
|
let path;
|
||||||
if let Some((worktree, rel_path)) =
|
if let Some((worktree, rel_path)) =
|
||||||
@ -3344,49 +3328,37 @@ impl Project {
|
|||||||
path = relativize_path(&worktree_abs_path, &abs_path);
|
path = relativize_path(&worktree_abs_path, &abs_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
let language = this.languages.select_language(&path).clone();
|
|
||||||
let signature = this.symbol_signature(worktree_id, &path);
|
let signature = this.symbol_signature(worktree_id, &path);
|
||||||
|
let language = this.languages.select_language(&path);
|
||||||
|
let language_server_name = adapter.name.clone();
|
||||||
|
|
||||||
partial_symbols.push(PartialSymbol {
|
Some(async move {
|
||||||
|
let label = if let Some(language) = language {
|
||||||
|
language
|
||||||
|
.label_for_symbol(&lsp_symbol.name, lsp_symbol.kind)
|
||||||
|
.await
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
|
Symbol {
|
||||||
source_worktree_id,
|
source_worktree_id,
|
||||||
worktree_id,
|
worktree_id,
|
||||||
language_server_name: adapter.name.clone(),
|
language_server_name,
|
||||||
name: lsp_symbol.name,
|
label: label.unwrap_or_else(|| {
|
||||||
|
CodeLabel::plain(lsp_symbol.name.clone(), None)
|
||||||
|
}),
|
||||||
kind: lsp_symbol.kind,
|
kind: lsp_symbol.kind,
|
||||||
language,
|
name: lsp_symbol.name,
|
||||||
path,
|
path,
|
||||||
range: range_from_lsp(lsp_symbol.location.range),
|
range: range_from_lsp(lsp_symbol.location.range),
|
||||||
signature,
|
signature,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
symbols
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
partial_symbols
|
|
||||||
});
|
|
||||||
|
|
||||||
let mut symbols = Vec::new();
|
|
||||||
for ps in partial_symbols.into_iter() {
|
|
||||||
symbols.push(async move {
|
|
||||||
let label = match ps.language {
|
|
||||||
Some(language) => language.label_for_symbol(&ps.name, ps.kind).await,
|
|
||||||
None => None,
|
|
||||||
}
|
|
||||||
.unwrap_or_else(|| CodeLabel::plain(ps.name.clone(), None));
|
|
||||||
|
|
||||||
Symbol {
|
|
||||||
source_worktree_id: ps.source_worktree_id,
|
|
||||||
worktree_id: ps.worktree_id,
|
|
||||||
language_server_name: ps.language_server_name,
|
|
||||||
name: ps.name,
|
|
||||||
kind: ps.kind,
|
|
||||||
label,
|
|
||||||
path: ps.path,
|
|
||||||
range: ps.range,
|
|
||||||
signature: ps.signature,
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(futures::future::join_all(symbols).await)
|
Ok(futures::future::join_all(symbols).await)
|
||||||
})
|
})
|
||||||
} else if let Some(project_id) = self.remote_id() {
|
} else if let Some(project_id) = self.remote_id() {
|
||||||
@ -3399,16 +3371,16 @@ impl Project {
|
|||||||
let mut symbols = Vec::new();
|
let mut symbols = Vec::new();
|
||||||
if let Some(this) = this.upgrade(&cx) {
|
if let Some(this) = this.upgrade(&cx) {
|
||||||
let new_symbols = this.read_with(&cx, |this, _| {
|
let new_symbols = this.read_with(&cx, |this, _| {
|
||||||
let mut new_symbols = Vec::new();
|
response
|
||||||
for symbol in response.symbols.into_iter() {
|
.symbols
|
||||||
new_symbols.push(this.deserialize_symbol(symbol));
|
.into_iter()
|
||||||
}
|
.map(|symbol| this.deserialize_symbol(symbol))
|
||||||
new_symbols
|
.collect::<Vec<_>>()
|
||||||
});
|
});
|
||||||
symbols = futures::future::join_all(new_symbols.into_iter())
|
symbols = futures::future::join_all(new_symbols)
|
||||||
.await
|
.await
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|symbol| symbol.ok())
|
.filter_map(|symbol| symbol.log_err())
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
}
|
}
|
||||||
Ok(symbols)
|
Ok(symbols)
|
||||||
|
Loading…
Reference in New Issue
Block a user