summaryrefslogtreecommitdiff
path: root/cli/tools
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tools')
-rw-r--r--cli/tools/registry/api.rs14
-rw-r--r--cli/tools/registry/diagnostics.rs25
2 files changed, 38 insertions, 1 deletions
diff --git a/cli/tools/registry/api.rs b/cli/tools/registry/api.rs
index b8eb6c18e..de9b4a333 100644
--- a/cli/tools/registry/api.rs
+++ b/cli/tools/registry/api.rs
@@ -3,6 +3,7 @@
use deno_core::error::AnyError;
use deno_core::serde_json;
use deno_runtime::deno_fetch::reqwest;
+use lsp_types::Url;
use serde::de::DeserializeOwned;
#[derive(serde::Deserialize)]
@@ -142,3 +143,16 @@ pub async fn get_package(
let response = client.get(&package_url).send().await?;
Ok(response)
}
+
+pub fn get_jsr_alternative(imported: &Url) -> Option<String> {
+ if !matches!(imported.host_str(), Some("esm.sh")) {
+ return None;
+ }
+
+ let mut segments = imported.path_segments().unwrap();
+ match segments.next() {
+ Some("gh") => None,
+ Some(module) => Some(format!("\"npm:{module}\"")),
+ None => None,
+ }
+}
diff --git a/cli/tools/registry/diagnostics.rs b/cli/tools/registry/diagnostics.rs
index ff86e68fb..9e88e81de 100644
--- a/cli/tools/registry/diagnostics.rs
+++ b/cli/tools/registry/diagnostics.rs
@@ -287,7 +287,30 @@ impl Diagnostic for PublishDiagnostic {
}
fn snippet_fixed(&self) -> Option<DiagnosticSnippet<'_>> {
- None
+ match &self {
+ PublishDiagnostic::InvalidExternalImport { imported, .. } => {
+ match super::api::get_jsr_alternative(imported) {
+ Some(replacement) => {
+ let replacement = SourceTextInfo::new(replacement.into());
+ let start = replacement.line_start(0);
+ let end = replacement.line_end(0);
+ Some(DiagnosticSnippet {
+ source: Cow::Owned(replacement),
+ highlight: DiagnosticSnippetHighlight {
+ style: DiagnosticSnippetHighlightStyle::Hint,
+ range: DiagnosticSourceRange {
+ start: DiagnosticSourcePos::SourcePos(start),
+ end: DiagnosticSourcePos::SourcePos(end),
+ },
+ description: Some("try this specifier".into()),
+ },
+ })
+ }
+ None => None,
+ }
+ }
+ _ => None,
+ }
}
fn info(&self) -> Cow<'_, [Cow<'_, str>]> {