diff options
author | HasanAlrimawi <141642411+HasanAlrimawi@users.noreply.github.com> | 2024-07-24 18:12:42 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-24 16:12:42 +0100 |
commit | fcd9bbe8eeec7d418b47544b6699e405c4d83826 (patch) | |
tree | 83ca484d97598cc2f427444fac4a85da801d2aa2 /tests/integration/lsp_tests.rs | |
parent | 199a8ca4c5a8c5b2a060ef6a8912766a6a98d0b7 (diff) |
fix: update lsp error message of 'relative import path' to 'use deno add' for npm/jsr packages (#24524)
Diffstat (limited to 'tests/integration/lsp_tests.rs')
-rw-r--r-- | tests/integration/lsp_tests.rs | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/tests/integration/lsp_tests.rs b/tests/integration/lsp_tests.rs index cfcf72ddc..e8904942d 100644 --- a/tests/integration/lsp_tests.rs +++ b/tests/integration/lsp_tests.rs @@ -172,6 +172,131 @@ fn lsp_triple_slash_types() { } #[test] +fn unadded_dependency_message_with_import_map() { + let context = TestContextBuilder::new() + .use_http_server() + .use_temp_cwd() + .build(); + let temp_dir = context.temp_dir(); + temp_dir.write( + "import_map.json", + json!({ + "imports": { + + } + }) + .to_string(), + ); + temp_dir.write( + "deno.json", + json!({ + "importMap": "import_map.json".to_string(), + }) + .to_string(), + ); + temp_dir.write( + "file.ts", + r#" + import * as x from "@std/fs"; + "#, + ); + let mut client = context.new_lsp_command().build(); + client.initialize_default(); + client.write_request( + "workspace/executeCommand", + json!({ + "command": "deno.cache", + "arguments": [[], temp_dir.uri().join("file.ts").unwrap()], + }), + ); + + 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"), + } + })); + // expected lsp_messages don't include the file path + let mut expected_lsp_messages = Vec::from(["`x` is never used\nIf this is intentional, prefix it with an underscore like `_x`", + "'x' is declared but its value is never read.", + "Relative import path \"@std/fs\" not prefixed with / or ./ or ../ and not in import map from \" Hint: Use [deno add @std/fs] to add the dependency."]); + expected_lsp_messages.sort(); + let all_diagnostics = diagnostics.all(); + let mut correct_lsp_messages = all_diagnostics + .iter() + .map(|d| d.message.as_str()) + .collect::<Vec<&str>>(); + correct_lsp_messages.sort(); + let part1 = correct_lsp_messages[1].split("file").collect::<Vec<_>>()[0]; + let part2 = correct_lsp_messages[1].split('\n').collect::<Vec<_>>()[1]; + let file_path_removed_from_message = format!("{} {}", part1, part2); + correct_lsp_messages[1] = file_path_removed_from_message.as_str(); + assert_eq!(correct_lsp_messages, expected_lsp_messages); + client.shutdown(); +} + +#[test] +fn unadded_dependency_message() { + let context = TestContextBuilder::new() + .use_http_server() + .use_temp_cwd() + .build(); + let temp_dir = context.temp_dir(); + temp_dir.write( + "deno.json", + json!({ + "imports": { + + } + }) + .to_string(), + ); + temp_dir.write( + "file.ts", + r#" + import * as x from "@std/fs"; + "#, + ); + let mut client = context.new_lsp_command().build(); + client.initialize_default(); + client.write_request( + "workspace/executeCommand", + json!({ + "command": "deno.cache", + "arguments": [[], temp_dir.uri().join("file.ts").unwrap()], + }), + ); + + 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"), + } + })); + // expected lsp_messages don't include the file path + let mut expected_lsp_messages = Vec::from(["`x` is never used\nIf this is intentional, prefix it with an underscore like `_x`", + "'x' is declared but its value is never read.", + "Relative import path \"@std/fs\" not prefixed with / or ./ or ../ and not in import map from \" Hint: Use [deno add @std/fs] to add the dependency."]); + expected_lsp_messages.sort(); + let all_diagnostics = diagnostics.all(); + let mut correct_lsp_messages = all_diagnostics + .iter() + .map(|d| d.message.as_str()) + .collect::<Vec<&str>>(); + correct_lsp_messages.sort(); + let part1 = correct_lsp_messages[1].split("file").collect::<Vec<_>>()[0]; + let part2 = correct_lsp_messages[1].split('\n').collect::<Vec<_>>()[1]; + let file_path_removed_from_message = format!("{} {}", part1, part2); + correct_lsp_messages[1] = file_path_removed_from_message.as_str(); + assert_eq!(correct_lsp_messages, expected_lsp_messages); + client.shutdown(); +} + +#[test] fn lsp_import_map() { let context = TestContextBuilder::new().use_temp_cwd().build(); let temp_dir = context.temp_dir(); |