From 33f84321b29f97c5757f019a72228c1c9631852e Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Sun, 24 Sep 2023 17:59:42 +0100 Subject: refactor(lsp): implement "deno.cacheOnSave" server-side (#20632) --- cli/tests/integration/lsp_tests.rs | 68 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 'cli/tests') diff --git a/cli/tests/integration/lsp_tests.rs b/cli/tests/integration/lsp_tests.rs index 567af5399..44a5df700 100644 --- a/cli/tests/integration/lsp_tests.rs +++ b/cli/tests/integration/lsp_tests.rs @@ -4455,6 +4455,74 @@ fn lsp_code_actions_deno_cache_npm() { client.shutdown(); } +#[test] +fn lsp_cache_on_save() { + let context = TestContextBuilder::new() + .use_http_server() + .use_temp_cwd() + .build(); + let temp_dir = context.temp_dir(); + temp_dir.write( + "file.ts", + r#" + import { printHello } from "http://localhost:4545/subdir/print_hello.ts"; + printHello(); + "#, + ); + let mut client = context.new_lsp_command().build(); + client.initialize_default(); + client.write_notification( + "workspace/didChangeConfiguration", + json!({ + "settings": {} + }), + ); + let settings = json!({ + "deno": { + "enable": true, + "cacheOnSave": true, + }, + }); + // one for the workspace + client.handle_configuration_request(&settings); + // one for the specifier + client.handle_configuration_request(&settings); + + let diagnostics = client.did_open(json!({ + "textDocument": { + "uri": temp_dir.uri().join("file.ts").unwrap(), + "languageId": "typescript", + "version": 1, + "text": temp_dir.read_to_string("file.ts"), + } + })); + assert_eq!( + diagnostics.messages_with_source("deno"), + serde_json::from_value(json!({ + "uri": temp_dir.uri().join("file.ts").unwrap(), + "diagnostics": [{ + "range": { + "start": { "line": 1, "character": 33 }, + "end": { "line": 1, "character": 78 } + }, + "severity": 1, + "code": "no-cache", + "source": "deno", + "message": "Uncached or missing remote URL: http://localhost:4545/subdir/print_hello.ts", + "data": { "specifier": "http://localhost:4545/subdir/print_hello.ts" } + }], + "version": 1 + })) + .unwrap() + ); + client.did_save(json!({ + "textDocument": { "uri": temp_dir.uri().join("file.ts").unwrap() }, + })); + assert_eq!(client.read_diagnostics().all(), vec![]); + + client.shutdown(); +} + #[test] fn lsp_code_actions_imports() { let context = TestContextBuilder::new().use_temp_cwd().build(); -- cgit v1.2.3