diff options
author | Nayeem Rahman <nayeemrmn99@gmail.com> | 2024-10-07 18:20:45 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-07 18:20:45 +0100 |
commit | 053894b9e0899757f156b8cd956fd467e0e11a63 (patch) | |
tree | 87e2753abfd57994c1e94f3525e3f8168945efba /tests/integration | |
parent | 719b8dcfde074e2347f0305bd2dec170fd9c4b04 (diff) |
fix(lsp): exclude missing import quick fixes with bad resolutions (#26025)
Diffstat (limited to 'tests/integration')
-rw-r--r-- | tests/integration/lsp_tests.rs | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/tests/integration/lsp_tests.rs b/tests/integration/lsp_tests.rs index fc5437594..19ea89a54 100644 --- a/tests/integration/lsp_tests.rs +++ b/tests/integration/lsp_tests.rs @@ -8504,6 +8504,74 @@ fn lsp_completions_auto_import_and_quick_fix_with_import_map() { client.shutdown(); } +// Regression test for https://github.com/denoland/deno/issues/25775. +#[test] +fn lsp_quick_fix_missing_import_exclude_bare_node_builtins() { + let context = TestContextBuilder::new() + .use_http_server() + .use_temp_cwd() + .add_npm_env_vars() + .build(); + let temp_dir = context.temp_dir(); + temp_dir.write( + "package.json", + json!({ + "dependencies": { + "@types/node": "*", + }, + }) + .to_string(), + ); + context.run_npm("install"); + let mut client = context.new_lsp_command().build(); + client.initialize_default(); + let diagnostics = client.did_open(json!({ + "textDocument": { + "uri": temp_dir.url().join("file.ts").unwrap(), + "languageId": "typescript", + "version": 1, + // Include node:buffer import to ensure @types/node is in the dep graph. + "text": "import \"node:buffer\";\nassert();\n", + }, + })); + let diagnostic = diagnostics + .all() + .into_iter() + .find(|d| d.message == "Cannot find name 'assert'.") + .unwrap(); + let res = client.write_request( + "textDocument/codeAction", + json!({ + "textDocument": { + "uri": temp_dir.url().join("file.ts").unwrap(), + }, + "range": { + "start": { "line": 1, "character": 0 }, + "end": { "line": 1, "character": 6 }, + }, + "context": { + "diagnostics": [&diagnostic], + "only": ["quickfix"], + }, + }), + ); + let code_actions = + serde_json::from_value::<Vec<lsp::CodeAction>>(res).unwrap(); + let titles = code_actions + .iter() + .map(|a| a.title.clone()) + .collect::<Vec<_>>(); + assert_eq!( + json!(titles), + json!([ + "Add import from \"node:assert\"", + "Add import from \"node:console\"", + "Add missing function declaration 'assert'", + ]), + ); + client.shutdown(); +} + #[test] fn lsp_completions_snippet() { let context = TestContextBuilder::new().use_temp_cwd().build(); |