From 5dd010a4fbeb0602891ea537b98216b8ad7d27a7 Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Thu, 12 Oct 2023 16:07:27 +0100 Subject: feat(lsp): send "deno/didChangeDenoConfiguration" notifications (#20827) --- cli/tests/integration/lsp_tests.rs | 137 ++++++++++++++++++++++++++++++++++++- 1 file changed, 135 insertions(+), 2 deletions(-) (limited to 'cli/tests') diff --git a/cli/tests/integration/lsp_tests.rs b/cli/tests/integration/lsp_tests.rs index c13053db8..b5af78b11 100644 --- a/cli/tests/integration/lsp_tests.rs +++ b/cli/tests/integration/lsp_tests.rs @@ -837,6 +837,137 @@ fn lsp_workspace_enable_paths_no_workspace_configuration() { client.shutdown(); } +#[test] +fn lsp_did_change_deno_configuration_notification() { + let context = TestContextBuilder::new().use_temp_cwd().build(); + let temp_dir = context.temp_dir(); + let mut client = context.new_lsp_command().build(); + client.initialize_default(); + + temp_dir.write("deno.json", json!({}).to_string()); + client.did_change_watched_files(json!({ + "changes": [{ + "uri": temp_dir.uri().join("deno.json").unwrap(), + "type": 1, + }], + })); + let res = client + .read_notification_with_method::("deno/didChangeDenoConfiguration"); + assert_eq!( + res, + Some(json!({ + "changes": [{ + "uri": temp_dir.uri().join("deno.json").unwrap(), + "type": 1, + "configurationType": "denoJson" + }], + })) + ); + + temp_dir.write( + "deno.json", + json!({ "fmt": { "semiColons": false } }).to_string(), + ); + client.did_change_watched_files(json!({ + "changes": [{ + "uri": temp_dir.uri().join("deno.json").unwrap(), + "type": 2, + }], + })); + let res = client + .read_notification_with_method::("deno/didChangeDenoConfiguration"); + assert_eq!( + res, + Some(json!({ + "changes": [{ + "uri": temp_dir.uri().join("deno.json").unwrap(), + "type": 2, + "configurationType": "denoJson" + }], + })) + ); + + temp_dir.remove_file("deno.json"); + client.did_change_watched_files(json!({ + "changes": [{ + "uri": temp_dir.uri().join("deno.json").unwrap(), + "type": 3, + }], + })); + let res = client + .read_notification_with_method::("deno/didChangeDenoConfiguration"); + assert_eq!( + res, + Some(json!({ + "changes": [{ + "uri": temp_dir.uri().join("deno.json").unwrap(), + "type": 3, + "configurationType": "denoJson" + }], + })) + ); + + temp_dir.write("package.json", json!({}).to_string()); + client.did_change_watched_files(json!({ + "changes": [{ + "uri": temp_dir.uri().join("package.json").unwrap(), + "type": 1, + }], + })); + let res = client + .read_notification_with_method::("deno/didChangeDenoConfiguration"); + assert_eq!( + res, + Some(json!({ + "changes": [{ + "uri": temp_dir.uri().join("package.json").unwrap(), + "type": 1, + "configurationType": "packageJson" + }], + })) + ); + + temp_dir.write("package.json", json!({ "type": "module" }).to_string()); + client.did_change_watched_files(json!({ + "changes": [{ + "uri": temp_dir.uri().join("package.json").unwrap(), + "type": 2, + }], + })); + let res = client + .read_notification_with_method::("deno/didChangeDenoConfiguration"); + assert_eq!( + res, + Some(json!({ + "changes": [{ + "uri": temp_dir.uri().join("package.json").unwrap(), + "type": 2, + "configurationType": "packageJson" + }], + })) + ); + + temp_dir.remove_file("package.json"); + client.did_change_watched_files(json!({ + "changes": [{ + "uri": temp_dir.uri().join("package.json").unwrap(), + "type": 3, + }], + })); + let res = client + .read_notification_with_method::("deno/didChangeDenoConfiguration"); + assert_eq!( + res, + Some(json!({ + "changes": [{ + "uri": temp_dir.uri().join("package.json").unwrap(), + "type": 3, + "configurationType": "packageJson" + }], + })) + ); +} + #[test] fn lsp_deno_task() { let context = TestContextBuilder::new().use_temp_cwd().build(); @@ -863,10 +994,12 @@ fn lsp_deno_task() { json!([ { "name": "build", - "detail": "deno test" + "detail": "deno test", + "sourceUri": temp_dir.uri().join("deno.jsonc").unwrap(), }, { "name": "some:test", - "detail": "deno bundle mod.ts" + "detail": "deno bundle mod.ts", + "sourceUri": temp_dir.uri().join("deno.jsonc").unwrap(), } ]) ); -- cgit v1.2.3