diff options
author | Nayeem Rahman <nayeemrmn99@gmail.com> | 2024-10-11 07:40:17 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-11 07:40:17 +0100 |
commit | 94b588ce6624ae2f2ed648c7b1a479a10513542f (patch) | |
tree | e9aa7437950d7b8f21f409ec3ec09642145424a0 /tests/integration | |
parent | ccdbeb433b64fec409da2d541456ddf5a35ea4a4 (diff) |
fix(lsp): relative completions for bare import-mapped specifiers (#26137)
Diffstat (limited to 'tests/integration')
-rw-r--r-- | tests/integration/lsp_tests.rs | 82 |
1 files changed, 49 insertions, 33 deletions
diff --git a/tests/integration/lsp_tests.rs b/tests/integration/lsp_tests.rs index 19ea89a54..0f2d43755 100644 --- a/tests/integration/lsp_tests.rs +++ b/tests/integration/lsp_tests.rs @@ -1342,6 +1342,7 @@ fn lsp_import_map_import_completions() { "/#/": "./src/", "fs": "https://example.com/fs/index.js", "std/": "https://example.com/std@0.123.0/", + "lib/": "./lib/", }, "scopes": { "file:///": { @@ -1364,17 +1365,18 @@ fn lsp_import_map_import_completions() { "uri": uri, "languageId": "typescript", "version": 1, - "text": "import * as a from \"/~/b.ts\";\nimport * as b from \"\"" - } + "text": r#" + import * as b from ""; + import * as b from "/~/"; + import * as b from "lib/"; + "#, + }, })); let res = client.get_completion( &uri, - (1, 20), - json!({ - "triggerKind": 2, - "triggerCharacter": "\"" - }), + (1, 28), + json!({ "triggerKind": 2, "triggerCharacter": "\"" }), ); assert_eq!( json!(res), @@ -1410,6 +1412,13 @@ fn lsp_import_map_import_completions() { "insertText": "std", "commitCharacters": ["\"", "'"], }, { + "label": "lib", + "kind": 19, + "detail": "(import map)", + "sortText": "lib", + "insertText": "lib", + "commitCharacters": ["\"", "'"], + }, { "label": "fs", "kind": 17, "detail": "(import map)", @@ -1435,32 +1444,39 @@ fn lsp_import_map_import_completions() { }) ); - client.write_notification( - "textDocument/didChange", + let res = client.get_completion( + &uri, + (2, 31), + json!({ "triggerKind": 2, "triggerCharacter": "/" }), + ); + assert_eq!( + json!(res), json!({ - "textDocument": { - "uri": uri, - "version": 2 - }, - "contentChanges": [ + "isIncomplete": false, + "items": [ { - "range": { - "start": { "line": 1, "character": 20 }, - "end": { "line": 1, "character": 20 } + "label": "b.ts", + "kind": 17, + "detail": "(local)", + "sortText": "1", + "filterText": "/~/b.ts", + "textEdit": { + "range": { + "start": { "line": 2, "character": 28 }, + "end": { "line": 2, "character": 31 }, + }, + "newText": "/~/b.ts", }, - "text": "/~/" - } - ] + "commitCharacters": ["\"", "'"], + }, + ], }), ); let res = client.get_completion( - uri, - (1, 23), - json!({ - "triggerKind": 2, - "triggerCharacter": "/" - }), + &uri, + (3, 32), + json!({ "triggerKind": 2, "triggerCharacter": "/" }), ); assert_eq!( json!(res), @@ -1472,18 +1488,18 @@ fn lsp_import_map_import_completions() { "kind": 17, "detail": "(local)", "sortText": "1", - "filterText": "/~/b.ts", + "filterText": "lib/b.ts", "textEdit": { "range": { - "start": { "line": 1, "character": 20 }, - "end": { "line": 1, "character": 23 } + "start": { "line": 3, "character": 28 }, + "end": { "line": 3, "character": 32 }, }, - "newText": "/~/b.ts" + "newText": "lib/b.ts", }, "commitCharacters": ["\"", "'"], - } - ] - }) + }, + ], + }), ); client.shutdown(); |