diff options
author | Kitson Kelly <me@kitsonkelly.com> | 2020-12-22 16:42:32 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-22 16:42:32 +1100 |
commit | b091c6c8c9cf33cc27b25560feaeea1eb23dd345 (patch) | |
tree | 9d33aec21cd472f18909f9aa6751a37ffb5b687b /cli/lsp/language_server.rs | |
parent | 1e144ec022df4b824a6a1d8061e1420e57baccea (diff) |
fix(lsp): respect enable flag for requests (#8850)
Diffstat (limited to 'cli/lsp/language_server.rs')
-rw-r--r-- | cli/lsp/language_server.rs | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs index c1e3ac8d5..0a9d81bf3 100644 --- a/cli/lsp/language_server.rs +++ b/cli/lsp/language_server.rs @@ -84,6 +84,11 @@ impl LanguageServer { } } + fn enabled(&self) -> bool { + let config = self.config.read().unwrap(); + config.settings.enable + } + pub async fn update_import_map(&self) -> Result<(), AnyError> { let (maybe_import_map, maybe_root_uri) = { let config = self.config.read().unwrap(); @@ -217,7 +222,7 @@ impl LanguageServer { } else { vec![] }; - if settings.enable { + if self.enabled() { diagnostics.extend( diagnostics_collection .diagnostics_for(file_id, DiagnosticSource::TypeScript) @@ -570,6 +575,9 @@ impl lspower::LanguageServer for LanguageServer { } async fn hover(&self, params: HoverParams) -> LSPResult<Option<Hover>> { + if !self.enabled() { + return Ok(None); + } let specifier = utils::normalize_url( params.text_document_position_params.text_document.uri, ); @@ -598,6 +606,9 @@ impl lspower::LanguageServer for LanguageServer { &self, params: DocumentHighlightParams, ) -> LSPResult<Option<Vec<DocumentHighlight>>> { + if !self.enabled() { + return Ok(None); + } let specifier = utils::normalize_url( params.text_document_position_params.text_document.uri, ); @@ -635,6 +646,9 @@ impl lspower::LanguageServer for LanguageServer { &self, params: ReferenceParams, ) -> LSPResult<Option<Vec<Location>>> { + if !self.enabled() { + return Ok(None); + } let specifier = utils::normalize_url(params.text_document_position.text_document.uri); // TODO(lucacasonato): handle error correctly @@ -673,6 +687,9 @@ impl lspower::LanguageServer for LanguageServer { &self, params: GotoDefinitionParams, ) -> LSPResult<Option<GotoDefinitionResponse>> { + if !self.enabled() { + return Ok(None); + } let specifier = utils::normalize_url( params.text_document_position_params.text_document.uri, ); @@ -706,6 +723,9 @@ impl lspower::LanguageServer for LanguageServer { &self, params: CompletionParams, ) -> LSPResult<Option<CompletionResponse>> { + if !self.enabled() { + return Ok(None); + } let specifier = utils::normalize_url(params.text_document_position.text_document.uri); // TODO(lucacasonato): handle error correctly @@ -978,4 +998,20 @@ mod tests { ]); harness.run().await; } + + #[tokio::test] + async fn test_hover_disabled() { + let mut harness = LspTestHarness::new(vec![ + ("initialize_request_disabled.json", LspResponse::RequestAny), + ("initialized_notification.json", LspResponse::None), + ("did_open_notification.json", LspResponse::None), + ("hover_request.json", LspResponse::Request(2, json!(null))), + ( + "shutdown_request.json", + LspResponse::Request(3, json!(null)), + ), + ("exit_notification.json", LspResponse::None), + ]); + harness.run().await; + } } |