diff options
Diffstat (limited to 'cli/tests/integration/lsp_tests.rs')
-rw-r--r-- | cli/tests/integration/lsp_tests.rs | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/cli/tests/integration/lsp_tests.rs b/cli/tests/integration/lsp_tests.rs index 83ce5c98b..3de8802fa 100644 --- a/cli/tests/integration/lsp_tests.rs +++ b/cli/tests/integration/lsp_tests.rs @@ -4945,6 +4945,73 @@ fn lsp_cache_on_save() { client.shutdown(); } +// Regression test for https://github.com/denoland/deno/issues/22122. +#[test] +fn lsp_cache_then_definition() { + let context = TestContextBuilder::new() + .use_http_server() + .use_temp_cwd() + .build(); + let temp_dir = context.temp_dir(); + let mut client = context.new_lsp_command().build(); + client.initialize_default(); + client.did_open(json!({ + "textDocument": { + "uri": temp_dir.uri().join("file.ts").unwrap(), + "languageId": "typescript", + "version": 1, + "text": r#"import "http://localhost:4545/run/002_hello.ts";"#, + }, + })); + // Prior to the fix, this would cause a faulty memoization that maps the + // URL "http://localhost:4545/run/002_hello.ts" to itself, preventing it from + // being reverse-mapped to "deno:/http/localhost%3A4545/run/002_hello.ts" on + // "textDocument/definition" request. + client.write_request( + "workspace/executeCommand", + json!({ + "command": "deno.cache", + "arguments": [ + ["http://localhost:4545/run/002_hello.ts"], + temp_dir.uri().join("file.ts").unwrap(), + ], + }), + ); + let res = client.write_request( + "textDocument/definition", + json!({ + "textDocument": { "uri": temp_dir.uri().join("file.ts").unwrap() }, + "position": { "line": 0, "character": 8 }, + }), + ); + assert_eq!( + res, + json!([{ + "targetUri": "deno:/http/localhost%3A4545/run/002_hello.ts", + "targetRange": { + "start": { + "line": 0, + "character": 0, + }, + "end": { + "line": 1, + "character": 0, + }, + }, + "targetSelectionRange": { + "start": { + "line": 0, + "character": 0, + }, + "end": { + "line": 1, + "character": 0, + }, + }, + }]), + ); +} + #[test] fn lsp_code_actions_imports() { let context = TestContextBuilder::new().use_temp_cwd().build(); |