summaryrefslogtreecommitdiff
path: root/tests/integration/lsp_tests.rs
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2024-07-08 22:31:27 +0100
committerGitHub <noreply@github.com>2024-07-08 22:31:27 +0100
commitd472c48b388992e2e0b059492dddf50400520809 (patch)
treef72848bb296ca81309f001fd63232c8473276dd6 /tests/integration/lsp_tests.rs
parentb338b541ac828113667fdd24c18db97d3e47c282 (diff)
fix(lsp): inherit workspace-root-only fields in members (#24440)
Diffstat (limited to 'tests/integration/lsp_tests.rs')
-rw-r--r--tests/integration/lsp_tests.rs402
1 files changed, 401 insertions, 1 deletions
diff --git a/tests/integration/lsp_tests.rs b/tests/integration/lsp_tests.rs
index f66fc97be..2111c6f07 100644
--- a/tests/integration/lsp_tests.rs
+++ b/tests/integration/lsp_tests.rs
@@ -12366,7 +12366,7 @@ fn lsp_deno_json_scopes_import_map() {
}
#[test]
-fn lsp_deno_json_scopes_vendor_dirs() {
+fn lsp_deno_json_scopes_vendor_dir() {
let context = TestContextBuilder::new()
.use_http_server()
.use_temp_cwd()
@@ -12551,6 +12551,194 @@ fn lsp_deno_json_scopes_vendor_dirs() {
}
#[test]
+fn lsp_deno_json_scopes_node_modules_dir() {
+ let context = TestContextBuilder::new()
+ .use_http_server()
+ .use_temp_cwd()
+ .build();
+ let temp_dir = context.temp_dir();
+ temp_dir.create_dir_all("project1");
+ temp_dir.create_dir_all("project2/project3");
+ temp_dir.write(
+ "project1/deno.json",
+ json!({
+ "nodeModulesDir": true,
+ })
+ .to_string(),
+ );
+ temp_dir.write(
+ "project2/deno.json",
+ json!({
+ "nodeModulesDir": true,
+ })
+ .to_string(),
+ );
+ temp_dir.write(
+ "project2/project3/deno.json",
+ json!({
+ "nodeModulesDir": true,
+ })
+ .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(),
+ "languageId": "typescript",
+ "version": 1,
+ "text": "import \"npm:@denotest/add@1\";\n",
+ },
+ }));
+ client.write_request(
+ "workspace/executeCommand",
+ json!({
+ "command": "deno.cache",
+ "arguments": [[], temp_dir.uri().join("project1/file.ts").unwrap()],
+ }),
+ );
+ let res = client.write_request(
+ "textDocument/definition",
+ json!({
+ "textDocument": {
+ "uri": temp_dir.uri().join("project1/file.ts").unwrap(),
+ },
+ "position": { "line": 0, "character": 7 },
+ }),
+ );
+ // The temp dir is symlinked in macos, and `node_modules` is canonicalized.
+ let canon_temp_dir =
+ Url::from_directory_path(temp_dir.path().canonicalize()).unwrap();
+ assert_eq!(
+ res,
+ json!([{
+ "targetUri": canon_temp_dir.join("project1/node_modules/.deno/@denotest+add@1.0.0/node_modules/@denotest/add/index.d.ts").unwrap(),
+ "targetRange": {
+ "start": {
+ "line": 0,
+ "character": 0,
+ },
+ "end": {
+ "line": 1,
+ "character": 0,
+ },
+ },
+ "targetSelectionRange": {
+ "start": {
+ "line": 0,
+ "character": 0,
+ },
+ "end": {
+ "line": 1,
+ "character": 0,
+ },
+ },
+ }]),
+ );
+ client.did_open(json!({
+ "textDocument": {
+ "uri": temp_dir.uri().join("project2/file.ts").unwrap(),
+ "languageId": "typescript",
+ "version": 1,
+ "text": "import \"npm:@denotest/add@1\";\n",
+ },
+ }));
+ client.write_request(
+ "workspace/executeCommand",
+ json!({
+ "command": "deno.cache",
+ "arguments": [[], temp_dir.uri().join("project2/file.ts").unwrap()],
+ }),
+ );
+ let res = client.write_request(
+ "textDocument/definition",
+ json!({
+ "textDocument": {
+ "uri": temp_dir.uri().join("project2/file.ts").unwrap(),
+ },
+ "position": { "line": 0, "character": 7 },
+ }),
+ );
+ assert_eq!(
+ res,
+ json!([{
+ "targetUri": canon_temp_dir.join("project2/node_modules/.deno/@denotest+add@1.0.0/node_modules/@denotest/add/index.d.ts").unwrap(),
+ "targetRange": {
+ "start": {
+ "line": 0,
+ "character": 0,
+ },
+ "end": {
+ "line": 1,
+ "character": 0,
+ },
+ },
+ "targetSelectionRange": {
+ "start": {
+ "line": 0,
+ "character": 0,
+ },
+ "end": {
+ "line": 1,
+ "character": 0,
+ },
+ },
+ }]),
+ );
+ client.did_open(json!({
+ "textDocument": {
+ "uri": temp_dir.uri().join("project2/project3/file.ts").unwrap(),
+ "languageId": "typescript",
+ "version": 1,
+ "text": "import \"npm:@denotest/add@1\";\n",
+ },
+ }));
+ client.write_request(
+ "workspace/executeCommand",
+ json!({
+ "command": "deno.cache",
+ "arguments": [[], temp_dir.uri().join("project2/project3/file.ts").unwrap()],
+ }),
+ );
+ let res = client.write_request(
+ "textDocument/definition",
+ json!({
+ "textDocument": {
+ "uri": temp_dir.uri().join("project2/project3/file.ts").unwrap(),
+ },
+ "position": { "line": 0, "character": 7 },
+ }),
+ );
+ assert_eq!(
+ res,
+ json!([{
+ "targetUri": canon_temp_dir.join("project2/project3/node_modules/.deno/@denotest+add@1.0.0/node_modules/@denotest/add/index.d.ts").unwrap(),
+ "targetRange": {
+ "start": {
+ "line": 0,
+ "character": 0,
+ },
+ "end": {
+ "line": 1,
+ "character": 0,
+ },
+ },
+ "targetSelectionRange": {
+ "start": {
+ "line": 0,
+ "character": 0,
+ },
+ "end": {
+ "line": 1,
+ "character": 0,
+ },
+ },
+ }]),
+ );
+ client.shutdown();
+}
+
+#[test]
fn lsp_deno_json_scopes_ts_config() {
let context = TestContextBuilder::new().use_temp_cwd().build();
let temp_dir = context.temp_dir();
@@ -13370,6 +13558,218 @@ fn lsp_deno_json_workspace_import_map() {
}
#[test]
+fn lsp_workspace_lockfile() {
+ let context = TestContextBuilder::new()
+ .use_http_server()
+ .use_temp_cwd()
+ .build();
+ let temp_dir = context.temp_dir();
+ temp_dir.create_dir_all("project1/project2");
+ temp_dir.write(
+ "project1/deno.json",
+ json!({
+ "workspace": ["project2"],
+ })
+ .to_string(),
+ );
+ temp_dir.write("project1/deno.lock", json!({
+ "version": "3",
+ "redirects": {
+ "http://localhost:4545/subdir/mod1.ts": "http://localhost:4545/subdir/mod2.ts",
+ },
+ "remote": {},
+ }).to_string());
+ temp_dir.write("project1/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/project2/file.ts").unwrap(),
+ "languageId": "typescript",
+ "version": 1,
+ "text": "import \"http://localhost:4545/subdir/mod1.ts\";\n",
+ },
+ }));
+ client.write_request(
+ "workspace/executeCommand",
+ json!({
+ "command": "deno.cache",
+ "arguments": [[], temp_dir.uri().join("project1/project2/file.ts").unwrap()],
+ }),
+ );
+ client.read_diagnostics();
+ let res = client.write_request(
+ "textDocument/definition",
+ json!({
+ "textDocument": { "uri": temp_dir.uri().join("project1/project2/file.ts").unwrap() },
+ "position": { "line": 0, "character": 7 },
+ }),
+ );
+ assert_eq!(
+ res,
+ json!([{
+ "targetUri": "deno:/http/localhost%3A4545/subdir/mod2.ts",
+ "targetRange": {
+ "start": { "line": 0, "character": 0 },
+ "end": { "line": 1, "character": 0 },
+ },
+ "targetSelectionRange": {
+ "start": { "line": 0, "character": 0 },
+ "end": { "line": 1, "character": 0 },
+ },
+ }]),
+ );
+ client.shutdown();
+}
+
+#[test]
+fn lsp_deno_json_workspace_vendor_dir() {
+ let context = TestContextBuilder::new()
+ .use_http_server()
+ .use_temp_cwd()
+ .build();
+ let temp_dir = context.temp_dir();
+ temp_dir.create_dir_all("project1/project2");
+ temp_dir.write(
+ "project1/deno.json",
+ json!({
+ "workspace": ["project2"],
+ "vendor": true,
+ })
+ .to_string(),
+ );
+ temp_dir.write("project1/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/project2/file.ts").unwrap(),
+ "languageId": "typescript",
+ "version": 1,
+ "text": "import \"http://localhost:4545/subdir/mod1.ts\";\n",
+ },
+ }));
+ client.write_request(
+ "workspace/executeCommand",
+ json!({
+ "command": "deno.cache",
+ "arguments": [[], temp_dir.uri().join("project1/project2/file.ts").unwrap()],
+ }),
+ );
+ let res = client.write_request(
+ "textDocument/definition",
+ json!({
+ "textDocument": {
+ "uri": temp_dir.uri().join("project1/project2/file.ts").unwrap(),
+ },
+ "position": { "line": 0, "character": 7 },
+ }),
+ );
+ assert_eq!(
+ res,
+ json!([{
+ "targetUri": temp_dir.uri().join("project1/vendor/http_localhost_4545/subdir/mod1.ts").unwrap(),
+ "targetRange": {
+ "start": {
+ "line": 0,
+ "character": 0,
+ },
+ "end": {
+ "line": 17,
+ "character": 0,
+ },
+ },
+ "targetSelectionRange": {
+ "start": {
+ "line": 0,
+ "character": 0,
+ },
+ "end": {
+ "line": 17,
+ "character": 0,
+ },
+ },
+ }]),
+ );
+ client.shutdown();
+}
+
+#[test]
+fn lsp_deno_json_workspace_node_modules_dir() {
+ let context = TestContextBuilder::new()
+ .use_http_server()
+ .use_temp_cwd()
+ .build();
+ let temp_dir = context.temp_dir();
+ temp_dir.create_dir_all("project1/project2");
+ temp_dir.write(
+ "project1/deno.json",
+ json!({
+ "workspace": ["project2"],
+ "nodeModulesDir": true,
+ })
+ .to_string(),
+ );
+ temp_dir.write("project1/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/project2/file.ts").unwrap(),
+ "languageId": "typescript",
+ "version": 1,
+ "text": "import \"npm:@denotest/add@1\";\n",
+ },
+ }));
+ client.write_request(
+ "workspace/executeCommand",
+ json!({
+ "command": "deno.cache",
+ "arguments": [[], temp_dir.uri().join("project1/project2/file.ts").unwrap()],
+ }),
+ );
+ let res = client.write_request(
+ "textDocument/definition",
+ json!({
+ "textDocument": {
+ "uri": temp_dir.uri().join("project1/project2/file.ts").unwrap(),
+ },
+ "position": { "line": 0, "character": 7 },
+ }),
+ );
+ // The temp dir is symlinked in macos, and `node_modules` is canonicalized.
+ let canon_temp_dir =
+ Url::from_directory_path(temp_dir.path().canonicalize()).unwrap();
+ assert_eq!(
+ res,
+ json!([{
+ "targetUri": canon_temp_dir.join("project1/node_modules/.deno/@denotest+add@1.0.0/node_modules/@denotest/add/index.d.ts").unwrap(),
+ "targetRange": {
+ "start": {
+ "line": 0,
+ "character": 0,
+ },
+ "end": {
+ "line": 1,
+ "character": 0,
+ },
+ },
+ "targetSelectionRange": {
+ "start": {
+ "line": 0,
+ "character": 0,
+ },
+ "end": {
+ "line": 1,
+ "character": 0,
+ },
+ },
+ }]),
+ );
+ client.shutdown();
+}
+
+#[test]
fn lsp_deno_json_workspace_jsr_resolution() {
let context = TestContextBuilder::new().use_temp_cwd().build();
let temp_dir = context.temp_dir();