summaryrefslogtreecommitdiff
path: root/cli/lsp/diagnostics.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/lsp/diagnostics.rs')
-rw-r--r--cli/lsp/diagnostics.rs30
1 files changed, 19 insertions, 11 deletions
diff --git a/cli/lsp/diagnostics.rs b/cli/lsp/diagnostics.rs
index 25cfd94e2..6deafde4c 100644
--- a/cli/lsp/diagnostics.rs
+++ b/cli/lsp/diagnostics.rs
@@ -1456,12 +1456,28 @@ fn diagnose_dependency(
.iter()
.map(|i| documents::to_lsp_range(&i.range))
.collect();
+ // TODO(nayeemrmn): This is a crude way of detecting `@deno-types` which has
+ // a different specifier and therefore needs a separate call to
+ // `diagnose_resolution()`. It would be much cleaner if that were modelled as
+ // a separate dependency: https://github.com/denoland/deno_graph/issues/247.
+ let is_types_deno_types = !dependency.maybe_type.is_none()
+ && !dependency
+ .imports
+ .iter()
+ .any(|i| dependency.maybe_type.includes(&i.range.start).is_some());
diagnostics.extend(
diagnose_resolution(
snapshot,
dependency_key,
- if dependency.maybe_code.is_none() {
+ if dependency.maybe_code.is_none()
+ // If not @deno-types, diagnose the types if the code errored because
+ // it's likely resolving into the node_modules folder, which might be
+ // erroring correctly due to resolution only being for bundlers. Let this
+ // fail at runtime if necesarry, but don't bother erroring in the editor
+ || !is_types_deno_types && matches!(dependency.maybe_type, Resolution::Ok(_))
+ && matches!(dependency.maybe_code, Resolution::Err(_))
+ {
&dependency.maybe_type
} else {
&dependency.maybe_code
@@ -1476,16 +1492,8 @@ fn diagnose_dependency(
.map(|range| diag.to_lsp_diagnostic(range))
}),
);
- // TODO(nayeemrmn): This is a crude way of detecting `@deno-types` which has
- // a different specifier and therefore needs a separate call to
- // `diagnose_resolution()`. It would be much cleaner if that were modelled as
- // a separate dependency: https://github.com/denoland/deno_graph/issues/247.
- if !dependency.maybe_type.is_none()
- && !dependency
- .imports
- .iter()
- .any(|i| dependency.maybe_type.includes(&i.range.start).is_some())
- {
+
+ if is_types_deno_types {
let range = match &dependency.maybe_type {
Resolution::Ok(resolved) => documents::to_lsp_range(&resolved.range),
Resolution::Err(error) => documents::to_lsp_range(error.range()),