From 84dc375b2d28a0ba9ddf0fbc5168505c19b1adea Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Wed, 4 Sep 2024 13:22:30 +0100 Subject: [PATCH] fix(lsp): update diagnostics on npm install (#25352) --- cli/lsp/config.rs | 11 +++++--- tests/integration/lsp_tests.rs | 46 +++++++++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/cli/lsp/config.rs b/cli/lsp/config.rs index d204dce646acf8..f9262d12e8b263 100644 --- a/cli/lsp/config.rs +++ b/cli/lsp/config.rs @@ -1697,9 +1697,14 @@ impl ConfigTree { } pub fn is_watched_file(&self, specifier: &ModuleSpecifier) -> bool { - if specifier.path().ends_with("/deno.json") - || specifier.path().ends_with("/deno.jsonc") - || specifier.path().ends_with("/package.json") + let path = specifier.path(); + if path.ends_with("/deno.json") + || path.ends_with("/deno.jsonc") + || path.ends_with("/package.json") + || path.ends_with("/node_modules/.package-lock.json") + || path.ends_with("/node_modules/.yarn-integrity.json") + || path.ends_with("/node_modules/.modules.yaml") + || path.ends_with("/node_modules/.deno/.setup-cache.bin") { return true; } diff --git a/tests/integration/lsp_tests.rs b/tests/integration/lsp_tests.rs index 7c7e9315ceacf0..4693b72223388e 100644 --- a/tests/integration/lsp_tests.rs +++ b/tests/integration/lsp_tests.rs @@ -14767,7 +14767,6 @@ fn lsp_byonm() { "@denotest/esm-basic": "*", }, })); - context.run_npm("install"); let mut client = context.new_lsp_command().build(); client.initialize_default(); let diagnostics = client.did_open(json!({ @@ -14781,6 +14780,51 @@ fn lsp_byonm() { "#, }, })); + assert_eq!( + json!(diagnostics.all()), + json!([ + { + "range": { + "start": { + "line": 1, + "character": 15, + }, + "end": { + "line": 1, + "character": 26, + }, + }, + "severity": 1, + "code": "resolver-error", + "source": "deno", + "message": "Could not find a matching package for 'npm:chalk' in a package.json file. You must specify this as a package.json dependency when the node_modules folder is not managed by Deno.", + }, + { + "range": { + "start": { + "line": 2, + "character": 15, + }, + "end": { + "line": 2, + "character": 36, + }, + }, + "severity": 1, + "code": "resolver-error", + "source": "deno", + "message": "Could not resolve \"@denotest/esm-basic\", but found it in a package.json. Deno expects the node_modules/ directory to be up to date. Did you forget to run `deno install`?", + }, + ]) + ); + context.run_npm("install"); + client.did_change_watched_files(json!({ + "changes": [{ + "uri": temp_dir.url().join("node_modules/.package-lock.json").unwrap(), + "type": 1, + }], + })); + let diagnostics = client.read_diagnostics(); assert_eq!( json!(diagnostics.all()), json!([