Skip to content

Commit

Permalink
fix(lsp): update diagnostics on npm install (#25352)
Browse files Browse the repository at this point in the history
  • Loading branch information
nayeemrmn authored Sep 4, 2024
1 parent 0e0a5c2 commit 84dc375
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
11 changes: 8 additions & 3 deletions cli/lsp/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
46 changes: 45 additions & 1 deletion tests/integration/lsp_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!({
Expand All @@ -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!([
Expand Down

0 comments on commit 84dc375

Please sign in to comment.