summaryrefslogtreecommitdiff
path: root/cli/lsp
diff options
context:
space:
mode:
Diffstat (limited to 'cli/lsp')
-rw-r--r--cli/lsp/diagnostics.rs18
-rw-r--r--cli/lsp/documents.rs26
-rw-r--r--cli/lsp/language_server.rs1
3 files changed, 31 insertions, 14 deletions
diff --git a/cli/lsp/diagnostics.rs b/cli/lsp/diagnostics.rs
index 4e4e9b3bb..4dbb4e1dd 100644
--- a/cli/lsp/diagnostics.rs
+++ b/cli/lsp/diagnostics.rs
@@ -37,6 +37,7 @@ use deno_graph::Resolution;
use deno_graph::ResolutionError;
use deno_graph::SpecifierError;
use deno_lint::rules::LintRule;
+use deno_runtime::deno_fs;
use deno_runtime::deno_node;
use deno_runtime::tokio_util::create_basic_runtime;
use deno_semver::npm::NpmPackageReqReference;
@@ -1166,6 +1167,21 @@ impl DenoDiagnostic {
/// Convert to an lsp Diagnostic when the range the diagnostic applies to is
/// provided.
pub fn to_lsp_diagnostic(&self, range: &lsp::Range) -> lsp::Diagnostic {
+ fn no_local_message(specifier: &ModuleSpecifier) -> String {
+ let fs: Arc<dyn deno_fs::FileSystem> = Arc::new(deno_fs::RealFs);
+ let mut message =
+ format!("Unable to load a local module: {}\n", specifier);
+ if let Some(additional_message) =
+ graph_util::maybe_sloppy_imports_suggestion_message(&fs, specifier)
+ {
+ message.push_str(&additional_message);
+ message.push('.');
+ } else {
+ message.push_str("Please check the file path.");
+ }
+ message
+ }
+
let (severity, message, data) = match self {
Self::DenoWarn(message) => (lsp::DiagnosticSeverity::WARNING, message.to_string(), None),
Self::ImportMapRemap { from, to } => (lsp::DiagnosticSeverity::HINT, format!("The import specifier can be remapped to \"{to}\" which will resolve it via the active import map."), Some(json!({ "from": from, "to": to }))),
@@ -1173,7 +1189,7 @@ impl DenoDiagnostic {
Self::NoAttributeType => (lsp::DiagnosticSeverity::ERROR, "The module is a JSON module and not being imported with an import attribute. Consider adding `with { type: \"json\" }` to the import statement.".to_string(), None),
Self::NoCache(specifier) => (lsp::DiagnosticSeverity::ERROR, format!("Uncached or missing remote URL: {specifier}"), Some(json!({ "specifier": specifier }))),
Self::NoCacheNpm(pkg_req, specifier) => (lsp::DiagnosticSeverity::ERROR, format!("Uncached or missing npm package: {}", pkg_req), Some(json!({ "specifier": specifier }))),
- Self::NoLocal(specifier) => (lsp::DiagnosticSeverity::ERROR, format!("Unable to load a local module: {specifier}\n Please check the file path."), None),
+ Self::NoLocal(specifier) => (lsp::DiagnosticSeverity::ERROR, no_local_message(specifier), None),
Self::Redirect { from, to} => (lsp::DiagnosticSeverity::INFORMATION, format!("The import of \"{from}\" was redirected to \"{to}\"."), Some(json!({ "specifier": from, "redirect": to }))),
Self::ResolutionError(err) => (
lsp::DiagnosticSeverity::ERROR,
diff --git a/cli/lsp/documents.rs b/cli/lsp/documents.rs
index 6687d2208..a341ae207 100644
--- a/cli/lsp/documents.rs
+++ b/cli/lsp/documents.rs
@@ -20,9 +20,9 @@ use crate::lsp::logging::lsp_warn;
use crate::npm::CliNpmResolver;
use crate::resolver::CliGraphResolver;
use crate::resolver::CliGraphResolverOptions;
-use crate::resolver::UnstableSloppyImportsFsEntry;
-use crate::resolver::UnstableSloppyImportsResolution;
-use crate::resolver::UnstableSloppyImportsResolver;
+use crate::resolver::SloppyImportsFsEntry;
+use crate::resolver::SloppyImportsResolution;
+use crate::resolver::SloppyImportsResolver;
use crate::util::glob;
use crate::util::path::specifier_to_file_path;
use crate::util::text_encoding;
@@ -1065,20 +1065,20 @@ impl Documents {
fn resolve_unstable_sloppy_import<'a>(
&self,
specifier: &'a ModuleSpecifier,
- ) -> UnstableSloppyImportsResolution<'a> {
- UnstableSloppyImportsResolver::resolve_with_stat_sync(specifier, |path| {
+ ) -> SloppyImportsResolution<'a> {
+ SloppyImportsResolver::resolve_with_stat_sync(specifier, |path| {
if let Ok(specifier) = ModuleSpecifier::from_file_path(path) {
if self.open_docs.contains_key(&specifier)
|| self.cache.contains(&specifier)
{
- return Some(UnstableSloppyImportsFsEntry::File);
+ return Some(SloppyImportsFsEntry::File);
}
}
path.metadata().ok().and_then(|m| {
if m.is_file() {
- Some(UnstableSloppyImportsFsEntry::File)
+ Some(SloppyImportsFsEntry::File)
} else if m.is_dir() {
- Some(UnstableSloppyImportsFsEntry::Dir)
+ Some(SloppyImportsFsEntry::Dir)
} else {
None
}
@@ -1732,18 +1732,18 @@ impl<'a> OpenDocumentsGraphLoader<'a> {
fn resolve_unstable_sloppy_import<'b>(
&self,
specifier: &'b ModuleSpecifier,
- ) -> UnstableSloppyImportsResolution<'b> {
- UnstableSloppyImportsResolver::resolve_with_stat_sync(specifier, |path| {
+ ) -> SloppyImportsResolution<'b> {
+ SloppyImportsResolver::resolve_with_stat_sync(specifier, |path| {
if let Ok(specifier) = ModuleSpecifier::from_file_path(path) {
if self.open_docs.contains_key(&specifier) {
- return Some(UnstableSloppyImportsFsEntry::File);
+ return Some(SloppyImportsFsEntry::File);
}
}
path.metadata().ok().and_then(|m| {
if m.is_file() {
- Some(UnstableSloppyImportsFsEntry::File)
+ Some(SloppyImportsFsEntry::File)
} else if m.is_dir() {
- Some(UnstableSloppyImportsFsEntry::Dir)
+ Some(SloppyImportsFsEntry::Dir)
} else {
None
}
diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs
index 92173b8ad..bc8a10235 100644
--- a/cli/lsp/language_server.rs
+++ b/cli/lsp/language_server.rs
@@ -263,6 +263,7 @@ impl LanguageServer {
.await?;
graph_util::graph_valid(
&graph,
+ factory.fs(),
&roots,
graph_util::GraphValidOptions {
is_vendoring: false,