Add label_for_symbol to extension API (#10179)

This PR adds `label_for_symbol` to the extension API.

As a motivating example, we implemented `label_for_symbol` for the
Haskell extension.

Release Notes:

- N/A

Co-authored-by: Max <max@zed.dev>
This commit is contained in:
Marshall Bowers 2024-04-04 15:38:38 -04:00 committed by GitHub
parent 5d88d9c0d7
commit 4a325614f0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 238 additions and 43 deletions

View file

@ -224,8 +224,11 @@ impl CachedLspAdapter {
&self,
symbols: &[(String, lsp::SymbolKind)],
language: &Arc<Language>,
) -> Vec<Option<CodeLabel>> {
self.adapter.labels_for_symbols(symbols, language).await
) -> Result<Vec<Option<CodeLabel>>> {
self.adapter
.clone()
.labels_for_symbols(symbols, language)
.await
}
#[cfg(any(test, feature = "test-support"))]
@ -410,10 +413,10 @@ pub trait LspAdapter: 'static + Send + Sync {
}
async fn labels_for_symbols(
&self,
self: Arc<Self>,
symbols: &[(String, lsp::SymbolKind)],
language: &Arc<Language>,
) -> Vec<Option<CodeLabel>> {
) -> Result<Vec<Option<CodeLabel>>> {
let mut labels = Vec::new();
for (ix, (name, kind)) in symbols.into_iter().enumerate() {
let label = self.label_for_symbol(name, *kind, language).await;
@ -422,7 +425,7 @@ pub trait LspAdapter: 'static + Send + Sync {
*labels.last_mut().unwrap() = Some(label);
}
}
labels
Ok(labels)
}
async fn label_for_symbol(