summaryrefslogtreecommitdiff
path: root/cli/tests/integration/lsp_tests.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tests/integration/lsp_tests.rs')
-rw-r--r--cli/tests/integration/lsp_tests.rs112
1 files changed, 112 insertions, 0 deletions
diff --git a/cli/tests/integration/lsp_tests.rs b/cli/tests/integration/lsp_tests.rs
index 22463b58a..261c98b52 100644
--- a/cli/tests/integration/lsp_tests.rs
+++ b/cli/tests/integration/lsp_tests.rs
@@ -433,6 +433,118 @@ fn lsp_import_map_embedded_in_config_file_after_initialize() {
}
#[test]
+fn lsp_import_map_config_file_auto_discovered() {
+ let context = TestContextBuilder::new().use_temp_cwd().build();
+ let temp_dir = context.temp_dir();
+ temp_dir.create_dir_all("lib");
+ temp_dir.write("lib/b.ts", r#"export const b = "b";"#);
+
+ let mut client = context.new_lsp_command().capture_stderr().build();
+ client.initialize_default();
+
+ // add the deno.json
+ temp_dir.write("deno.jsonc", r#"{ "imports": { "/~/": "./lib/" } }"#);
+ client.did_change_watched_files(json!({
+ "changes": [{
+ "uri": temp_dir.uri().join("deno.jsonc").unwrap(),
+ "type": 2
+ }]
+ }));
+ client.wait_until_stderr_line(|line| {
+ line.contains("Auto-resolved configuration file:")
+ });
+
+ let uri = temp_dir.uri().join("a.ts").unwrap();
+
+ let diagnostics = client.did_open(json!({
+ "textDocument": {
+ "uri": uri,
+ "languageId": "typescript",
+ "version": 1,
+ "text": "import { b } from \"/~/b.ts\";\n\nconsole.log(b);\n"
+ }
+ }));
+
+ assert_eq!(diagnostics.all().len(), 0);
+
+ let res = client.write_request(
+ "textDocument/hover",
+ json!({
+ "textDocument": {
+ "uri": uri
+ },
+ "position": { "line": 2, "character": 12 }
+ }),
+ );
+ assert_eq!(
+ res,
+ json!({
+ "contents": [
+ {
+ "language": "typescript",
+ "value":"(alias) const b: \"b\"\nimport b"
+ },
+ ""
+ ],
+ "range": {
+ "start": { "line": 2, "character": 12 },
+ "end": { "line": 2, "character": 13 }
+ }
+ })
+ );
+
+ // now cause a syntax error
+ temp_dir.write("deno.jsonc", r#",,#,#,,"#);
+ client.did_change_watched_files(json!({
+ "changes": [{
+ "uri": temp_dir.uri().join("deno.jsonc").unwrap(),
+ "type": 2
+ }]
+ }));
+ assert_eq!(client.read_diagnostics().all().len(), 1);
+
+ // now fix it, and things should work again
+ temp_dir.write("deno.jsonc", r#"{ "imports": { "/~/": "./lib/" } }"#);
+ client.did_change_watched_files(json!({
+ "changes": [{
+ "uri": temp_dir.uri().join("deno.jsonc").unwrap(),
+ "type": 2
+ }]
+ }));
+ client.wait_until_stderr_line(|line| {
+ line.contains("Auto-resolved configuration file:")
+ });
+ let res = client.write_request(
+ "textDocument/hover",
+ json!({
+ "textDocument": {
+ "uri": uri
+ },
+ "position": { "line": 2, "character": 12 }
+ }),
+ );
+ assert_eq!(
+ res,
+ json!({
+ "contents": [
+ {
+ "language": "typescript",
+ "value":"(alias) const b: \"b\"\nimport b"
+ },
+ ""
+ ],
+ "range": {
+ "start": { "line": 2, "character": 12 },
+ "end": { "line": 2, "character": 13 }
+ }
+ })
+ );
+ assert_eq!(client.read_diagnostics().all().len(), 0);
+
+ client.shutdown();
+}
+
+#[test]
fn lsp_deno_task() {
let context = TestContextBuilder::new().use_temp_cwd().build();
let temp_dir = context.temp_dir();