summaryrefslogtreecommitdiff
path: root/cli/lsp/diagnostics.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2023-01-24 15:05:54 +0100
committerGitHub <noreply@github.com>2023-01-24 09:05:54 -0500
commitfc2e00152b162280e78b06028d51274e33275629 (patch)
treeee567a99cabc6633454de231939f7d898146f1d8 /cli/lsp/diagnostics.rs
parentcadeaae045d2489fe125286b8c2c641c6d973c3f (diff)
feat: support node built-in module imports (#17264)
Co-authored-by: David Sherret <dsherret@gmail.com>
Diffstat (limited to 'cli/lsp/diagnostics.rs')
-rw-r--r--cli/lsp/diagnostics.rs29
1 files changed, 29 insertions, 0 deletions
diff --git a/cli/lsp/diagnostics.rs b/cli/lsp/diagnostics.rs
index b4be63a55..4faff2fae 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::node;
use crate::npm::NpmPackageReference;
use crate::tools::lint::get_configured_rules;
@@ -614,6 +615,8 @@ pub enum DenoDiagnostic {
},
/// An error occurred when resolving the specifier string.
ResolutionError(deno_graph::ResolutionError),
+ /// Invalid `node:` specifier.
+ InvalidNodeSpecifier(ModuleSpecifier),
}
impl DenoDiagnostic {
@@ -641,6 +644,7 @@ impl DenoDiagnostic {
},
ResolutionError::ResolverError { .. } => "resolver-error",
},
+ Self::InvalidNodeSpecifier(_) => "resolver-error",
}
}
@@ -791,6 +795,7 @@ impl DenoDiagnostic {
Self::NoLocal(specifier) => (lsp::DiagnosticSeverity::ERROR, format!("Unable to load a local module: \"{}\".\n Please check the file path.", specifier), None),
Self::Redirect { from, to} => (lsp::DiagnosticSeverity::INFORMATION, format!("The import of \"{}\" was redirected to \"{}\".", from, to), Some(json!({ "specifier": from, "redirect": to }))),
Self::ResolutionError(err) => (lsp::DiagnosticSeverity::ERROR, err.to_string(), None),
+ Self::InvalidNodeSpecifier(specifier) => (lsp::DiagnosticSeverity::ERROR, format!("Unknown Node built-in module: {}", specifier.path()), None),
};
lsp::Diagnostic {
range: *range,
@@ -872,6 +877,30 @@ fn diagnose_resolved(
);
}
}
+ } else if let Some(module_name) = specifier.as_str().strip_prefix("node:")
+ {
+ if node::resolve_builtin_node_module(module_name).is_err() {
+ diagnostics.push(
+ DenoDiagnostic::InvalidNodeSpecifier(specifier.clone())
+ .to_lsp_diagnostic(&range),
+ );
+ } else if let Some(npm_resolver) = &snapshot.maybe_npm_resolver {
+ // check that a @types/node package exists in the resolver
+ let types_node_ref =
+ NpmPackageReference::from_str("npm:@types/node").unwrap();
+ if npm_resolver
+ .resolve_package_folder_from_deno_module(&types_node_ref.req)
+ .is_err()
+ {
+ diagnostics.push(
+ DenoDiagnostic::NoCacheNpm(
+ types_node_ref,
+ ModuleSpecifier::parse("npm:@types/node").unwrap(),
+ )
+ .to_lsp_diagnostic(&range),
+ );
+ }
+ }
} else {
// When the document is not available, it means that it cannot be found
// in the cache or locally on the disk, so we want to issue a diagnostic