summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKitson Kelly <me@kitsonkelly.com>2020-12-22 16:42:32 +1100
committerGitHub <noreply@github.com>2020-12-22 16:42:32 +1100
commitb091c6c8c9cf33cc27b25560feaeea1eb23dd345 (patch)
tree9d33aec21cd472f18909f9aa6751a37ffb5b687b
parent1e144ec022df4b824a6a1d8061e1420e57baccea (diff)
fix(lsp): respect enable flag for requests (#8850)
-rw-r--r--cli/lsp/language_server.rs38
-rw-r--r--cli/tests/lsp/initialize_request.json6
-rw-r--r--cli/tests/lsp/initialize_request_disabled.json29
3 files changed, 72 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;
+ }
}
diff --git a/cli/tests/lsp/initialize_request.json b/cli/tests/lsp/initialize_request.json
index 960420bfd..722a3c783 100644
--- a/cli/tests/lsp/initialize_request.json
+++ b/cli/tests/lsp/initialize_request.json
@@ -9,6 +9,12 @@
"version": "1.0.0"
},
"rootUri": null,
+ "initializationOptions": {
+ "enable": true,
+ "lint": true,
+ "importMap": null,
+ "unstable": false
+ },
"capabilities": {
"textDocument": {
"synchronization": {
diff --git a/cli/tests/lsp/initialize_request_disabled.json b/cli/tests/lsp/initialize_request_disabled.json
new file mode 100644
index 000000000..f763375f8
--- /dev/null
+++ b/cli/tests/lsp/initialize_request_disabled.json
@@ -0,0 +1,29 @@
+{
+ "jsonrpc": "2.0",
+ "id": 1,
+ "method": "initialize",
+ "params": {
+ "processId": 0,
+ "clientInfo": {
+ "name": "test-harness",
+ "version": "1.0.0"
+ },
+ "rootUri": null,
+ "initializationOptions": {
+ "enable": false,
+ "lint": true,
+ "importMap": null,
+ "unstable": false
+ },
+ "capabilities": {
+ "textDocument": {
+ "synchronization": {
+ "dynamicRegistration": true,
+ "willSave": true,
+ "willSaveWaitUntil": true,
+ "didSave": true
+ }
+ }
+ }
+ }
+}