summaryrefslogtreecommitdiff
path: root/cli/tests/integration/lsp_tests.rs
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2023-09-02 16:36:04 +0100
committerGitHub <noreply@github.com>2023-09-02 16:36:04 +0100
commit12f6ad32c2108efb1492df6192a1f8cdd5eafa76 (patch)
tree8afd5f0a4890f62eba658850e294663540e949c4 /cli/tests/integration/lsp_tests.rs
parent83426be6eead06c680ae527468aeaf8723543ff2 (diff)
fix(lsp): properly handle disabled configuration requests (#20358)
Fixes #19802. Properly respect when clients do not have the `workspace/configuration` capability, a.k.a. when an editor cannot provide scoped settings on request from the LSP. - Fix one spot where we weren't checking for the capability before sending this request. - For `enablePaths`, fall back to the settings passed in the initialization options in more cases. - Respect the `workspace/configuration` capability in the test harness client. See: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_configuration.
Diffstat (limited to 'cli/tests/integration/lsp_tests.rs')
-rw-r--r--cli/tests/integration/lsp_tests.rs81
1 files changed, 81 insertions, 0 deletions
diff --git a/cli/tests/integration/lsp_tests.rs b/cli/tests/integration/lsp_tests.rs
index 218b1db40..19b968602 100644
--- a/cli/tests/integration/lsp_tests.rs
+++ b/cli/tests/integration/lsp_tests.rs
@@ -643,6 +643,87 @@ fn lsp_import_map_node_specifiers() {
client.shutdown();
}
+// Regression test for https://github.com/denoland/deno/issues/19802.
+// Disable the `workspace/configuration` capability. Ensure the LSP falls back
+// to using `enablePaths` from the `InitializationOptions`.
+#[test]
+fn lsp_workspace_enable_paths_no_workspace_configuration() {
+ let context = TestContextBuilder::new().use_temp_cwd().build();
+ let temp_dir = context.temp_dir();
+ temp_dir.write("main_disabled.ts", "Date.now()");
+ temp_dir.write("main_enabled.ts", "Date.now()");
+
+ let mut client = context.new_lsp_command().build();
+ client.initialize(|builder| {
+ builder.with_capabilities(|capabilities| {
+ capabilities.workspace.as_mut().unwrap().configuration = Some(false);
+ });
+ builder.set_workspace_folders(vec![lsp::WorkspaceFolder {
+ uri: temp_dir.uri(),
+ name: "project".to_string(),
+ }]);
+ builder.set_root_uri(temp_dir.uri());
+ builder.set_enable_paths(vec!["./main_enabled.ts".to_string()]);
+ });
+
+ client.did_open(json!({
+ "textDocument": {
+ "uri": temp_dir.uri().join("main_disabled.ts").unwrap(),
+ "languageId": "typescript",
+ "version": 1,
+ "text": temp_dir.read_to_string("main_disabled.ts"),
+ }
+ }));
+
+ client.did_open(json!({
+ "textDocument": {
+ "uri": temp_dir.uri().join("main_enabled.ts").unwrap(),
+ "languageId": "typescript",
+ "version": 1,
+ "text": temp_dir.read_to_string("main_enabled.ts"),
+ }
+ }));
+
+ let res = client.write_request(
+ "textDocument/hover",
+ json!({
+ "textDocument": {
+ "uri": temp_dir.uri().join("main_disabled.ts").unwrap(),
+ },
+ "position": { "line": 0, "character": 5 }
+ }),
+ );
+ assert_eq!(res, json!(null));
+
+ let res = client.write_request(
+ "textDocument/hover",
+ json!({
+ "textDocument": {
+ "uri": temp_dir.uri().join("main_enabled.ts").unwrap(),
+ },
+ "position": { "line": 0, "character": 5 }
+ }),
+ );
+ assert_eq!(
+ res,
+ json!({
+ "contents": [
+ {
+ "language": "typescript",
+ "value": "(method) DateConstructor.now(): number",
+ },
+ "Returns the number of milliseconds elapsed since midnight, January 1, 1970 Universal Coordinated Time (UTC)."
+ ],
+ "range": {
+ "start": { "line": 0, "character": 5, },
+ "end": { "line": 0, "character": 8, }
+ }
+ })
+ );
+
+ client.shutdown();
+}
+
#[test]
fn lsp_deno_task() {
let context = TestContextBuilder::new().use_temp_cwd().build();