summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/integration/lsp_tests.rs190
-rw-r--r--cli/tests/testdata/lsp/import-map-completions.json7
2 files changed, 197 insertions, 0 deletions
diff --git a/cli/tests/integration/lsp_tests.rs b/cli/tests/integration/lsp_tests.rs
index 7607582c8..d45b90955 100644
--- a/cli/tests/integration/lsp_tests.rs
+++ b/cli/tests/integration/lsp_tests.rs
@@ -548,6 +548,196 @@ fn lsp_import_assertions() {
}
#[test]
+fn lsp_import_map_import_completions() {
+ let temp_dir = TempDir::new().expect("could not create temp dir");
+ let mut params: lsp::InitializeParams =
+ serde_json::from_value(load_fixture("initialize_params.json")).unwrap();
+ let import_map =
+ serde_json::to_vec_pretty(&load_fixture("import-map-completions.json"))
+ .unwrap();
+ fs::write(temp_dir.path().join("import-map.json"), import_map).unwrap();
+ fs::create_dir(temp_dir.path().join("lib")).unwrap();
+ fs::write(
+ temp_dir.path().join("lib").join("b.ts"),
+ r#"export const b = "b";"#,
+ )
+ .unwrap();
+
+ params.root_uri = Some(Url::from_file_path(temp_dir.path()).unwrap());
+ if let Some(Value::Object(mut map)) = params.initialization_options {
+ map.insert("importMap".to_string(), json!("import-map.json"));
+ params.initialization_options = Some(Value::Object(map));
+ }
+
+ let deno_exe = deno_exe_path();
+ let mut client = LspClient::new(&deno_exe).unwrap();
+ client
+ .write_request::<_, _, Value>("initialize", params)
+ .unwrap();
+
+ client.write_notification("initialized", json!({})).unwrap();
+ let uri = Url::from_file_path(temp_dir.path().join("a.ts")).unwrap();
+
+ did_open(
+ &mut client,
+ json!({
+ "textDocument": {
+ "uri": uri,
+ "languageId": "typescript",
+ "version": 1,
+ "text": "import * as a from \"/~/b.ts\";\nimport * as b from \"\""
+ }
+ }),
+ );
+
+ let (maybe_res, maybe_err) = client
+ .write_request(
+ "textDocument/completion",
+ json!({
+ "textDocument": {
+ "uri": uri
+ },
+ "position": {
+ "line": 1,
+ "character": 20
+ },
+ "context": {
+ "triggerKind": 2,
+ "triggerCharacter": "\""
+ }
+ }),
+ )
+ .unwrap();
+ assert!(maybe_err.is_none());
+ assert_eq!(
+ maybe_res,
+ Some(json!({
+ "isIncomplete": false,
+ "items": [
+ {
+ "label": ".",
+ "kind": 19,
+ "detail": "(local)",
+ "sortText": "1",
+ "insertText": "."
+ },
+ {
+ "label": "..",
+ "kind": 19,
+ "detail": "(local)",
+ "sortText": "1",
+ "insertText": ".."
+ },
+ {
+ "label": "std",
+ "kind": 19,
+ "detail": "(import map)",
+ "sortText": "std",
+ "insertText": "std"
+ },
+ {
+ "label": "fs",
+ "kind": 17,
+ "detail": "(import map)",
+ "sortText": "fs",
+ "insertText": "fs"
+ },
+ {
+ "label": "/~",
+ "kind": 19,
+ "detail": "(import map)",
+ "sortText": "/~",
+ "insertText": "/~"
+ }
+ ]
+ }))
+ );
+
+ client
+ .write_notification(
+ "textDocument/didChange",
+ json!({
+ "textDocument": {
+ "uri": uri,
+ "version": 2
+ },
+ "contentChanges": [
+ {
+ "range": {
+ "start": {
+ "line": 1,
+ "character": 20
+ },
+ "end": {
+ "line": 1,
+ "character": 20
+ }
+ },
+ "text": "/~/"
+ }
+ ]
+ }),
+ )
+ .unwrap();
+ let (method, _) = client.read_notification::<Value>().unwrap();
+ assert_eq!(method, "textDocument/publishDiagnostics");
+ let (method, _) = client.read_notification::<Value>().unwrap();
+ assert_eq!(method, "textDocument/publishDiagnostics");
+ let (method, _) = client.read_notification::<Value>().unwrap();
+ assert_eq!(method, "textDocument/publishDiagnostics");
+
+ let (maybe_res, maybe_err) = client
+ .write_request(
+ "textDocument/completion",
+ json!({
+ "textDocument": {
+ "uri": uri
+ },
+ "position": {
+ "line": 1,
+ "character": 23
+ },
+ "context": {
+ "triggerKind": 2,
+ "triggerCharacter": "/"
+ }
+ }),
+ )
+ .unwrap();
+ assert!(maybe_err.is_none());
+ assert_eq!(
+ maybe_res,
+ Some(json!({
+ "isIncomplete": false,
+ "items": [
+ {
+ "label": "b.ts",
+ "kind": 9,
+ "detail": "(import map)",
+ "sortText": "1",
+ "filterText": "/~/b.ts",
+ "textEdit": {
+ "range": {
+ "start": {
+ "line": 1,
+ "character": 20
+ },
+ "end": {
+ "line": 1,
+ "character": 23
+ }
+ },
+ "newText": "/~/b.ts"
+ }
+ }
+ ]
+ }))
+ );
+
+ shutdown(&mut client);
+}
+
+#[test]
fn lsp_hover() {
let mut client = init("initialize_params.json");
did_open(
diff --git a/cli/tests/testdata/lsp/import-map-completions.json b/cli/tests/testdata/lsp/import-map-completions.json
new file mode 100644
index 000000000..f2275222a
--- /dev/null
+++ b/cli/tests/testdata/lsp/import-map-completions.json
@@ -0,0 +1,7 @@
+{
+ "imports": {
+ "/~/": "./lib/",
+ "fs": "https://example.com/fs/index.js",
+ "std/": "https://example.com/std@0.123.0/"
+ }
+}