Skip to content

Commit be62645

Browse files
divybotlittledivy
andauthored
chore: cover same-dir import map auto-import alias (#34645)
Adds LSP regression coverage for auto-import completions when an import map alias points at the same directory as the referrer, such as `$src/`: `./src/`. The test verifies that resolving the completion inserts the import-map alias instead of regressing to only the relative path. Also removes an unused HTTP test server fixture from the adjacent passthrough import-map test so it does not depend on fixed test-server ports. Closes denoland/divybot#382 Co-authored-by: divybot <divybot@users.noreply.github.com> Co-authored-by: Divy Srivastava <me@littledivy.com>
1 parent 453eaf6 commit be62645

1 file changed

Lines changed: 54 additions & 4 deletions

File tree

tests/integration/lsp_tests.rs

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10569,10 +10569,7 @@ fn lsp_auto_import_local_dir_import_map_alias() {
1056910569

1057010570
#[test(timeout = 300)]
1057110571
fn lsp_auto_import_import_map_prefer_relative() {
10572-
let context = TestContextBuilder::new()
10573-
.use_http_server()
10574-
.use_temp_cwd()
10575-
.build();
10572+
let context = TestContextBuilder::new().use_temp_cwd().build();
1057610573
let temp_dir = context.temp_dir();
1057710574
temp_dir.write(
1057810575
"deno.json",
@@ -10622,6 +10619,59 @@ fn lsp_auto_import_import_map_prefer_relative() {
1062210619
client.shutdown();
1062310620
}
1062410621

10622+
#[test(timeout = 300)]
10623+
fn lsp_auto_import_same_dir_import_map_alias() {
10624+
let context = TestContextBuilder::new().use_temp_cwd().build();
10625+
let temp_dir = context.temp_dir();
10626+
temp_dir.write(
10627+
"deno.json",
10628+
json!({
10629+
"imports": {
10630+
"$src/": "./src/",
10631+
},
10632+
})
10633+
.to_string(),
10634+
);
10635+
temp_dir.create_dir_all("src");
10636+
temp_dir.write("src/b.ts", "export const b = 1;\n");
10637+
let file = temp_dir.source_file("src/a.ts", "b;\n");
10638+
let mut client = context.new_lsp_command().build();
10639+
client.initialize_default();
10640+
let list = client.get_completion_list(
10641+
file.uri().as_str(),
10642+
(0, 1),
10643+
json!({ "triggerKind": 1 }),
10644+
);
10645+
let items = list
10646+
.items
10647+
.iter()
10648+
.filter(|i| i.label == "b")
10649+
.map(|i| client.write_request("completionItem/resolve", json!(i)))
10650+
.collect::<Vec<_>>();
10651+
assert_eq!(
10652+
json!(items),
10653+
json!([
10654+
{
10655+
"label": "b",
10656+
"labelDetails": { "description": "$src/b.ts" },
10657+
"kind": 6,
10658+
"detail": "Add import from \"$src/b.ts\"\n\nconst b: 1",
10659+
"sortText": "\u{ffff}16_0",
10660+
"additionalTextEdits": [
10661+
{
10662+
"range": {
10663+
"start": { "line": 0, "character": 0 },
10664+
"end": { "line": 0, "character": 0 },
10665+
},
10666+
"newText": "import { b } from \"$src/b.ts\";\n\n",
10667+
},
10668+
],
10669+
},
10670+
]),
10671+
);
10672+
client.shutdown();
10673+
}
10674+
1062510675
#[test(timeout = 300)]
1062610676
fn lsp_completions_empty_tsx_react_jsx() {
1062710677
let context = TestContextBuilder::new().use_temp_cwd().build();

0 commit comments

Comments
 (0)