diff options
author | Yoshiya Hinosawa <stibium121@gmail.com> | 2023-10-20 13:02:08 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-20 13:02:08 +0900 |
commit | fb73eb1e9dca3e93cc7efcf5c2244e0068733843 (patch) | |
tree | ef0d50f6a4f3ff14114cc4a5c544bb7f4dfd2cdf /cli/tests/integration/lsp_tests.rs | |
parent | 8d9fef3b8955eadfd4820455b422b5bec1cdad0a (diff) |
feat(unstable): allow bare specifier for builtin node module (#20728)
closes #20566
Diffstat (limited to 'cli/tests/integration/lsp_tests.rs')
-rw-r--r-- | cli/tests/integration/lsp_tests.rs | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/cli/tests/integration/lsp_tests.rs b/cli/tests/integration/lsp_tests.rs index 544164978..85e55ee81 100644 --- a/cli/tests/integration/lsp_tests.rs +++ b/cli/tests/integration/lsp_tests.rs @@ -10419,3 +10419,92 @@ fn lsp_vendor_dir() { client.shutdown(); } + +#[test] +fn lsp_import_unstable_bare_node_builtins_auto_discovered() { + let context = TestContextBuilder::new().use_temp_cwd().build(); + let temp_dir = context.temp_dir(); + + let contents = r#"import path from "path";"#; + temp_dir.write("main.ts", contents); + temp_dir.write("deno.json", r#"{ "unstable": ["bare-node-builtins"] }"#); + let main_script = temp_dir.uri().join("main.ts").unwrap(); + + let mut client = context.new_lsp_command().capture_stderr().build(); + client.initialize_default(); + let diagnostics = client.did_open(json!({ + "textDocument": { + "uri": main_script, + "languageId": "typescript", + "version": 1, + "text": contents, + } + })); + + let diagnostics = diagnostics + .messages_with_file_and_source(main_script.as_ref(), "deno") + .diagnostics + .into_iter() + .filter(|d| { + d.code + == Some(lsp::NumberOrString::String( + "import-node-prefix-missing".to_string(), + )) + }) + .collect::<Vec<_>>(); + + // get the quick fixes + let res = client.write_request( + "textDocument/codeAction", + json!({ + "textDocument": { + "uri": main_script + }, + "range": { + "start": { "line": 0, "character": 16 }, + "end": { "line": 0, "character": 18 }, + }, + "context": { + "diagnostics": json!(diagnostics), + "only": ["quickfix"] + } + }), + ); + assert_eq!( + res, + json!([{ + "title": "Update specifier to node:path", + "kind": "quickfix", + "diagnostics": [ + { + "range": { + "start": { "line": 0, "character": 17 }, + "end": { "line": 0, "character": 23 } + }, + "severity": 2, + "code": "import-node-prefix-missing", + "source": "deno", + "message": "\"path\" is resolved to \"node:path\". If you want to use a built-in Node module, add a \"node:\" prefix.", + "data": { + "specifier": "path" + }, + } + ], + "edit": { + "changes": { + main_script: [ + { + "range": { + "start": { "line": 0, "character": 17 }, + "end": { "line": 0, "character": 23 } + }, + "newText": "\"node:path\"" + } + ] + } + } + }]) + ); + + client.shutdown(); +} |