feat(lsp): add workspace symbol provider (#12787)

This commit is contained in:
Kitson Kelly 2021-11-23 11:08:56 +11:00 committed by GitHub
parent 3abe31252e
commit bf5657cd59
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 303 additions and 24 deletions

View file

@ -2270,6 +2270,44 @@ impl Inner {
Ok(None)
}
}
async fn symbol(
&mut self,
params: WorkspaceSymbolParams,
) -> LspResult<Option<Vec<SymbolInformation>>> {
let mark = self.performance.mark("symbol", Some(&params));
let req = tsc::RequestMethod::GetNavigateToItems {
search: params.query,
// this matches vscode's hard coded result count
max_result_count: Some(256),
file: None,
};
let navigate_to_items: Vec<tsc::NavigateToItem> = self
.ts_server
.request(self.snapshot()?, req)
.await
.map_err(|err| {
error!("Failed request to tsserver: {}", err);
LspError::invalid_request()
})?;
let maybe_symbol_information = if navigate_to_items.is_empty() {
None
} else {
let mut symbol_information = Vec::new();
for item in navigate_to_items {
if let Some(info) = item.to_symbol_information(self).await {
symbol_information.push(info);
}
}
Some(symbol_information)
};
self.performance.measure(mark);
Ok(maybe_symbol_information)
}
}
#[lspower::async_trait]
@ -2481,6 +2519,13 @@ impl lspower::LanguageServer for LanguageServer {
) -> LspResult<Option<SignatureHelp>> {
self.0.lock().await.signature_help(params).await
}
async fn symbol(
&self,
params: WorkspaceSymbolParams,
) -> LspResult<Option<Vec<SymbolInformation>>> {
self.0.lock().await.symbol(params).await
}
}
// These are implementations of custom commands supported by the LSP