summaryrefslogtreecommitdiff
path: root/cli/lsp/diagnostics.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2023-01-27 17:36:23 -0500
committerGitHub <noreply@github.com>2023-01-27 22:36:23 +0000
commit2b247be517d789a37e532849e2e40b724af0918f (patch)
tree1f689a0b872a5b05a4ce812f9f120df7134ba69d /cli/lsp/diagnostics.rs
parentf5840bdcd360ec0bac2501f333e58e25742b1537 (diff)
fix: ensure "fs" -> "node:fs" error/quick fix works when user has import map (#17566)
Closes #17563
Diffstat (limited to 'cli/lsp/diagnostics.rs')
-rw-r--r--cli/lsp/diagnostics.rs71
1 files changed, 33 insertions, 38 deletions
diff --git a/cli/lsp/diagnostics.rs b/cli/lsp/diagnostics.rs
index b6dff8682..0a6f33126 100644
--- a/cli/lsp/diagnostics.rs
+++ b/cli/lsp/diagnostics.rs
@@ -13,6 +13,7 @@ use super::tsc;
use super::tsc::TsServer;
use crate::args::LintOptions;
+use crate::graph_util;
use crate::graph_util::enhanced_resolution_error_message;
use crate::node;
use crate::npm::NpmPackageReference;
@@ -641,15 +642,25 @@ impl DenoDiagnostic {
Self::NoCacheNpm(_, _) => "no-cache-npm",
Self::NoLocal(_) => "no-local",
Self::Redirect { .. } => "redirect",
- Self::ResolutionError(err) => match err {
- ResolutionError::InvalidDowngrade { .. } => "invalid-downgrade",
- ResolutionError::InvalidLocalImport { .. } => "invalid-local-import",
- ResolutionError::InvalidSpecifier { error, .. } => match error {
- SpecifierError::ImportPrefixMissing(_, _) => "import-prefix-missing",
- SpecifierError::InvalidUrl(_) => "invalid-url",
- },
- ResolutionError::ResolverError { .. } => "resolver-error",
- },
+ Self::ResolutionError(err) => {
+ if graph_util::get_resolution_error_bare_node_specifier(err).is_some() {
+ "import-node-prefix-missing"
+ } else {
+ match err {
+ ResolutionError::InvalidDowngrade { .. } => "invalid-downgrade",
+ ResolutionError::InvalidLocalImport { .. } => {
+ "invalid-local-import"
+ }
+ ResolutionError::InvalidSpecifier { error, .. } => match error {
+ SpecifierError::ImportPrefixMissing(_, _) => {
+ "import-prefix-missing"
+ }
+ SpecifierError::InvalidUrl(_) => "invalid-url",
+ },
+ ResolutionError::ResolverError { .. } => "resolver-error",
+ }
+ }
+ }
Self::InvalidNodeSpecifier(_) => "resolver-error",
}
}
@@ -752,10 +763,7 @@ impl DenoDiagnostic {
..Default::default()
}
}
- "import-prefix-missing" => {
- // if an import-prefix-missing diagnostic ends up here, then that currently
- // will only ever occur for a possible "node:" specifier, so don't bother
- // checking if it's actually a "node:"" specifier
+ "import-node-prefix-missing" => {
let data = diagnostic
.data
.clone()
@@ -795,19 +803,16 @@ impl DenoDiagnostic {
/// diagnostic is fixable or not
pub fn is_fixable(diagnostic: &lsp_types::Diagnostic) -> bool {
if let Some(lsp::NumberOrString::String(code)) = &diagnostic.code {
- if code == "import-prefix-missing" {
- diagnostic.data.is_some()
- } else {
- matches!(
- code.as_str(),
- "import-map-remap"
- | "no-cache"
- | "no-cache-npm"
- | "no-cache-data"
- | "no-assert-type"
- | "redirect"
- )
- }
+ matches!(
+ code.as_str(),
+ "import-map-remap"
+ | "no-cache"
+ | "no-cache-npm"
+ | "no-cache-data"
+ | "no-assert-type"
+ | "redirect"
+ | "import-node-prefix-missing"
+ )
} else {
false
}
@@ -830,18 +835,8 @@ impl DenoDiagnostic {
Self::ResolutionError(err) => (
lsp::DiagnosticSeverity::ERROR,
enhanced_resolution_error_message(err),
- if let ResolutionError::InvalidSpecifier {
- error: SpecifierError::ImportPrefixMissing(specifier, _),
- ..
- } = err {
- if crate::node::resolve_builtin_node_module(specifier).is_ok() {
- Some(json!({ "specifier": specifier }))
- } else {
- None
- }
- } else {
- None
- },
+ graph_util::get_resolution_error_bare_node_specifier(err)
+ .map(|specifier| json!({ "specifier": specifier }))
),
Self::InvalidNodeSpecifier(specifier) => (lsp::DiagnosticSeverity::ERROR, format!("Unknown Node built-in module: {}", specifier.path()), None),
};