diff options
author | Kitson Kelly <me@kitsonkelly.com> | 2021-11-23 11:08:56 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-23 11:08:56 +1100 |
commit | bf5657cd590a0624d614a09ff6fc3538f94643da (patch) | |
tree | 26420625430f9b043d8406ed21039fb962b7a502 /cli/lsp/language_server.rs | |
parent | 3abe31252e02c3488727c7aa15a4d3a301d96531 (diff) |
feat(lsp): add workspace symbol provider (#12787)
Diffstat (limited to 'cli/lsp/language_server.rs')
-rw-r--r-- | cli/lsp/language_server.rs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs index 29138c762..fb2b04214 100644 --- a/cli/lsp/language_server.rs +++ b/cli/lsp/language_server.rs @@ -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(¶ms)); + + 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 |