summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2024-06-10 17:03:17 +0100
committerGitHub <noreply@github.com>2024-06-10 17:03:17 +0100
commit7c5dbd5d54770dba5e56442b633e9597403ef5da (patch)
tree3837f975b8d6a6615c91fd5c1e37ac2732a8aaf5 /tests
parent4fd3d5a86e45c4dcbaaa277cfb7f1087ddebfa48 (diff)
feat(lsp): workspace jsr resolution (#24121)
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/lsp_tests.rs137
1 files changed, 97 insertions, 40 deletions
diff --git a/tests/integration/lsp_tests.rs b/tests/integration/lsp_tests.rs
index 581d436bb..25fb695b4 100644
--- a/tests/integration/lsp_tests.rs
+++ b/tests/integration/lsp_tests.rs
@@ -11974,22 +11974,22 @@ fn lsp_vendor_dir() {
client.shutdown();
}
#[test]
-fn lsp_deno_json_scopes_fmt_config() {
+fn lsp_deno_json_workspace_fmt_config() {
let context = TestContextBuilder::new().use_temp_cwd().build();
let temp_dir = context.temp_dir();
- temp_dir.create_dir_all("project1");
temp_dir.write(
- "project1/deno.json",
+ "deno.json",
json!({
+ "workspaces": ["project1", "project2"],
"fmt": {
"semiColons": false,
},
})
.to_string(),
);
- temp_dir.create_dir_all("project2");
+ temp_dir.create_dir_all("project1");
temp_dir.write(
- "project2/deno.json",
+ "project1/deno.json",
json!({
"fmt": {
"singleQuote": true,
@@ -11997,13 +11997,13 @@ fn lsp_deno_json_scopes_fmt_config() {
})
.to_string(),
);
- temp_dir.create_dir_all("project2/project3");
- temp_dir.write("project2/project3/deno.json", json!({}).to_string());
+ temp_dir.create_dir_all("project2");
+ temp_dir.write("project2/deno.json", json!({}).to_string());
let mut client = context.new_lsp_command().build();
client.initialize_default();
client.did_open(json!({
"textDocument": {
- "uri": temp_dir.uri().join("project1/file.ts").unwrap(),
+ "uri": temp_dir.uri().join("file.ts").unwrap(),
"languageId": "typescript",
"version": 1,
"text": "console.log(\"\");\n",
@@ -12013,7 +12013,7 @@ fn lsp_deno_json_scopes_fmt_config() {
"textDocument/formatting",
json!({
"textDocument": {
- "uri": temp_dir.uri().join("project1/file.ts").unwrap(),
+ "uri": temp_dir.uri().join("file.ts").unwrap(),
},
"options": {
"tabSize": 2,
@@ -12033,7 +12033,7 @@ fn lsp_deno_json_scopes_fmt_config() {
);
client.did_open(json!({
"textDocument": {
- "uri": temp_dir.uri().join("project2/file.ts").unwrap(),
+ "uri": temp_dir.uri().join("project1/file.ts").unwrap(),
"languageId": "typescript",
"version": 1,
"text": "console.log(\"\");\n",
@@ -12043,7 +12043,7 @@ fn lsp_deno_json_scopes_fmt_config() {
"textDocument/formatting",
json!({
"textDocument": {
- "uri": temp_dir.uri().join("project2/file.ts").unwrap(),
+ "uri": temp_dir.uri().join("project1/file.ts").unwrap(),
},
"options": {
"tabSize": 2,
@@ -12061,11 +12061,11 @@ fn lsp_deno_json_scopes_fmt_config() {
"newText": "''",
}])
);
- // `project2/project3/file.ts` should use the fmt settings from
- // `project2/deno.json`, since `project2/project3/deno.json` has no fmt field.
+ // `project2/file.ts` should use the fmt settings from `deno.json`, since it
+ // has no fmt field.
client.did_open(json!({
"textDocument": {
- "uri": temp_dir.uri().join("project2/project3/file.ts").unwrap(),
+ "uri": temp_dir.uri().join("project2/file.ts").unwrap(),
"languageId": "typescript",
"version": 1,
"text": "console.log(\"\");\n",
@@ -12075,7 +12075,7 @@ fn lsp_deno_json_scopes_fmt_config() {
"textDocument/formatting",
json!({
"textDocument": {
- "uri": temp_dir.uri().join("project2/project3/file.ts").unwrap(),
+ "uri": temp_dir.uri().join("project2/file.ts").unwrap(),
},
"options": {
"tabSize": 2,
@@ -12087,23 +12087,23 @@ fn lsp_deno_json_scopes_fmt_config() {
res,
json!([{
"range": {
- "start": { "line": 0, "character": 12 },
- "end": { "line": 0, "character": 14 },
+ "start": { "line": 0, "character": 15 },
+ "end": { "line": 0, "character": 16 },
},
- "newText": "''",
+ "newText": "",
}])
);
client.shutdown();
}
#[test]
-fn lsp_deno_json_scopes_lint_config() {
+fn lsp_deno_json_workspace_lint_config() {
let context = TestContextBuilder::new().use_temp_cwd().build();
let temp_dir = context.temp_dir();
- temp_dir.create_dir_all("project1");
temp_dir.write(
- "project1/deno.json",
+ "deno.json",
json!({
+ "workspaces": ["project1", "project2"],
"lint": {
"rules": {
"include": ["camelcase"],
@@ -12112,9 +12112,9 @@ fn lsp_deno_json_scopes_lint_config() {
})
.to_string(),
);
- temp_dir.create_dir_all("project2");
+ temp_dir.create_dir_all("project1");
temp_dir.write(
- "project2/deno.json",
+ "project1/deno.json",
json!({
"lint": {
"rules": {
@@ -12124,13 +12124,13 @@ fn lsp_deno_json_scopes_lint_config() {
})
.to_string(),
);
- temp_dir.create_dir_all("project2/project3");
- temp_dir.write("project2/project3/deno.json", json!({}).to_string());
+ temp_dir.create_dir_all("project2");
+ temp_dir.write("project2/deno.json", json!({}).to_string());
let mut client = context.new_lsp_command().build();
client.initialize_default();
let diagnostics = client.did_open(json!({
"textDocument": {
- "uri": temp_dir.uri().join("project1/file.ts").unwrap(),
+ "uri": temp_dir.uri().join("file.ts").unwrap(),
"languageId": "typescript",
"version": 1,
"text": r#"
@@ -12143,7 +12143,7 @@ fn lsp_deno_json_scopes_lint_config() {
assert_eq!(
json!(diagnostics.messages_with_source("deno-lint")),
json!({
- "uri": temp_dir.uri().join("project1/file.ts").unwrap(),
+ "uri": temp_dir.uri().join("file.ts").unwrap(),
"diagnostics": [{
"range": {
"start": { "line": 2, "character": 14 },
@@ -12161,13 +12161,13 @@ fn lsp_deno_json_scopes_lint_config() {
"textDocument/didClose",
json!({
"textDocument": {
- "uri": temp_dir.uri().join("project1/file.ts").unwrap(),
+ "uri": temp_dir.uri().join("file.ts").unwrap(),
},
}),
);
let diagnostics = client.did_open(json!({
"textDocument": {
- "uri": temp_dir.uri().join("project2/file.ts").unwrap(),
+ "uri": temp_dir.uri().join("project1/file.ts").unwrap(),
"languageId": "typescript",
"version": 1,
"text": r#"
@@ -12180,7 +12180,7 @@ fn lsp_deno_json_scopes_lint_config() {
assert_eq!(
json!(diagnostics.messages_with_source("deno-lint")),
json!({
- "uri": temp_dir.uri().join("project2/file.ts").unwrap(),
+ "uri": temp_dir.uri().join("project1/file.ts").unwrap(),
"diagnostics": [{
"range": {
"start": { "line": 1, "character": 8 },
@@ -12198,16 +12198,15 @@ fn lsp_deno_json_scopes_lint_config() {
"textDocument/didClose",
json!({
"textDocument": {
- "uri": temp_dir.uri().join("project2/file.ts").unwrap(),
+ "uri": temp_dir.uri().join("project1/file.ts").unwrap(),
},
}),
);
- // `project2/project3/file.ts` should use the lint settings from
- // `project2/deno.json`, since `project2/project3/deno.json` has no lint
- // field.
+ // `project2/file.ts` should use the lint settings from `deno.json`, since it
+ // has no lint field.
let diagnostics = client.did_open(json!({
"textDocument": {
- "uri": temp_dir.uri().join("project2/project3/file.ts").unwrap(),
+ "uri": temp_dir.uri().join("project2/file.ts").unwrap(),
"languageId": "typescript",
"version": 1,
"text": r#"
@@ -12220,16 +12219,16 @@ fn lsp_deno_json_scopes_lint_config() {
assert_eq!(
json!(diagnostics.messages_with_source("deno-lint")),
json!({
- "uri": temp_dir.uri().join("project2/project3/file.ts").unwrap(),
+ "uri": temp_dir.uri().join("project2/file.ts").unwrap(),
"diagnostics": [{
"range": {
- "start": { "line": 1, "character": 8 },
- "end": { "line": 1, "character": 27 },
+ "start": { "line": 2, "character": 14 },
+ "end": { "line": 2, "character": 28 },
},
"severity": 2,
- "code": "ban-untagged-todo",
+ "code": "camelcase",
"source": "deno-lint",
- "message": "TODO should be tagged with (@username) or (#issue)\nAdd a user tag or issue reference to the TODO comment, e.g. TODO(@djones), TODO(djones), TODO(#123)",
+ "message": "Identifier 'snake_case_var' is not in camel case.\nConsider renaming `snake_case_var` to `snakeCaseVar`",
}],
"version": 1,
})
@@ -12238,6 +12237,64 @@ fn lsp_deno_json_scopes_lint_config() {
}
#[test]
+fn lsp_deno_json_workspace_jsr_resolution() {
+ let context = TestContextBuilder::new().use_temp_cwd().build();
+ let temp_dir = context.temp_dir();
+ temp_dir.write(
+ "deno.json",
+ json!({
+ "workspaces": ["project1"],
+ })
+ .to_string(),
+ );
+ temp_dir.create_dir_all("project1");
+ temp_dir.write(
+ "project1/deno.json",
+ json!({
+ "name": "@org/project1",
+ "version": "1.0.0",
+ "exports": {
+ ".": "./mod.ts",
+ },
+ })
+ .to_string(),
+ );
+ let mut client = context.new_lsp_command().build();
+ client.initialize_default();
+ client.did_open(json!({
+ "textDocument": {
+ "uri": temp_dir.uri().join("file.ts").unwrap(),
+ "languageId": "typescript",
+ "version": 1,
+ "text": "import \"jsr:@org/project1@^1.0.0\";\n",
+ },
+ }));
+ let res = client.write_request(
+ "textDocument/hover",
+ json!({
+ "textDocument": {
+ "uri": temp_dir.uri().join("file.ts").unwrap(),
+ },
+ "position": { "line": 0, "character": 7 },
+ }),
+ );
+ assert_eq!(
+ res,
+ json!({
+ "contents": {
+ "kind": "markdown",
+ "value": format!("**Resolved Dependency**\n\n**Code**: jsr&#8203;:&#8203;@org/project1&#8203;@^1.0.0 (<{}project1/mod.ts>)\n", temp_dir.uri()),
+ },
+ "range": {
+ "start": { "line": 0, "character": 7 },
+ "end": { "line": 0, "character": 33 },
+ },
+ }),
+ );
+ client.shutdown();
+}
+
+#[test]
fn lsp_import_unstable_bare_node_builtins_auto_discovered() {
let context = TestContextBuilder::new().use_temp_cwd().build();
let temp_dir = context.temp_dir();