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.rs38
1 files changed, 29 insertions, 9 deletions
diff --git a/cli/lsp/diagnostics.rs b/cli/lsp/diagnostics.rs
index 6deafde4c..fe6904830 100644
--- a/cli/lsp/diagnostics.rs
+++ b/cli/lsp/diagnostics.rs
@@ -1305,6 +1305,33 @@ fn diagnose_resolution(
is_dynamic: bool,
maybe_assert_type: Option<&str>,
) -> Vec<DenoDiagnostic> {
+ fn check_redirect_diagnostic(
+ specifier: &ModuleSpecifier,
+ doc: &Document,
+ ) -> Option<DenoDiagnostic> {
+ let doc_specifier = doc.specifier();
+ // If the module was redirected, we want to issue an informational
+ // diagnostic that indicates this. This then allows us to issue a code
+ // action to replace the specifier with the final redirected one.
+ if specifier.scheme() == "jsr" || doc_specifier == specifier {
+ return None;
+ }
+ // don't bother warning about sloppy import redirects from .js to .d.ts
+ // because explaining how to fix this via a diagnostic involves using
+ // @deno-types and that's a bit complicated to explain
+ let is_sloppy_import_dts_redirect = doc_specifier.scheme() == "file"
+ && doc.media_type().is_declaration()
+ && !MediaType::from_specifier(specifier).is_declaration();
+ if is_sloppy_import_dts_redirect {
+ return None;
+ }
+
+ Some(DenoDiagnostic::Redirect {
+ from: specifier.clone(),
+ to: doc_specifier.clone(),
+ })
+ }
+
let mut diagnostics = vec![];
match resolution {
Resolution::Ok(resolved) => {
@@ -1319,15 +1346,8 @@ fn diagnose_resolution(
}
}
if let Some(doc) = snapshot.documents.get(specifier) {
- let doc_specifier = doc.specifier();
- // If the module was redirected, we want to issue an informational
- // diagnostic that indicates this. This then allows us to issue a code
- // action to replace the specifier with the final redirected one.
- if specifier.scheme() != "jsr" && doc_specifier != specifier {
- diagnostics.push(DenoDiagnostic::Redirect {
- from: specifier.clone(),
- to: doc_specifier.clone(),
- });
+ if let Some(diagnostic) = check_redirect_diagnostic(specifier, &doc) {
+ diagnostics.push(diagnostic);
}
if doc.media_type() == MediaType::Json {
match maybe_assert_type {