@@ -458,6 +458,13 @@ async fn generate_lint_diagnostics(
458
458
break ;
459
459
}
460
460
461
+ // ignore any npm package files
462
+ if let Some ( npm_resolver) = & snapshot. maybe_npm_resolver {
463
+ if npm_resolver. in_npm_package ( document. specifier ( ) ) {
464
+ continue ;
465
+ }
466
+ }
467
+
461
468
let version = document. maybe_lsp_version ( ) ;
462
469
diagnostics_vec. push ( (
463
470
document. specifier ( ) . clone ( ) ,
@@ -597,6 +604,8 @@ pub enum DenoDiagnostic {
597
604
NoCacheBlob ,
598
605
/// A data module was not found in the cache.
599
606
NoCacheData ( ModuleSpecifier ) ,
607
+ /// A remote npm package reference was not found in the cache.
608
+ NoCacheNpm ( NpmPackageReference , ModuleSpecifier ) ,
600
609
/// A local module was not found on the local file system.
601
610
NoLocal ( ModuleSpecifier ) ,
602
611
/// The specifier resolved to a remote specifier that was redirected to
@@ -622,6 +631,7 @@ impl DenoDiagnostic {
622
631
Self :: NoCache ( _) => "no-cache" ,
623
632
Self :: NoCacheBlob => "no-cache-blob" ,
624
633
Self :: NoCacheData ( _) => "no-cache-data" ,
634
+ Self :: NoCacheNpm ( _, _) => "no-cache-npm" ,
625
635
Self :: NoLocal ( _) => "no-local" ,
626
636
Self :: Redirect { .. } => "redirect" ,
627
637
Self :: ResolutionError ( err) => match err {
@@ -690,16 +700,17 @@ impl DenoDiagnostic {
690
700
} ) ,
691
701
..Default :: default ( )
692
702
} ,
693
- "no-cache" | "no-cache-data" => {
703
+ "no-cache" | "no-cache-data" | "no-cache-npm" => {
694
704
let data = diagnostic
695
705
. data
696
706
. clone ( )
697
707
. ok_or_else ( || anyhow ! ( "Diagnostic is missing data" ) ) ?;
698
708
let data: DiagnosticDataSpecifier = serde_json:: from_value ( data) ?;
699
- let title = if code == "no-cache" {
700
- format ! ( "Cache \" {}\" and its dependencies." , data. specifier)
701
- } else {
702
- "Cache the data URL and its dependencies." . to_string ( )
709
+ let title = match code. as_str ( ) {
710
+ "no-cache" | "no-cache-npm" => {
711
+ format ! ( "Cache \" {}\" and its dependencies." , data. specifier)
712
+ }
713
+ _ => "Cache the data URL and its dependencies." . to_string ( ) ,
703
714
} ;
704
715
lsp:: CodeAction {
705
716
title,
@@ -757,6 +768,7 @@ impl DenoDiagnostic {
757
768
code. as_str( ) ,
758
769
"import-map-remap"
759
770
| "no-cache"
771
+ | "no-cache-npm"
760
772
| "no-cache-data"
761
773
| "no-assert-type"
762
774
| "redirect"
@@ -777,6 +789,7 @@ impl DenoDiagnostic {
777
789
Self :: NoCache ( specifier) => ( lsp:: DiagnosticSeverity :: ERROR , format ! ( "Uncached or missing remote URL: \" {}\" ." , specifier) , Some ( json ! ( { "specifier" : specifier } ) ) ) ,
778
790
Self :: NoCacheBlob => ( lsp:: DiagnosticSeverity :: ERROR , "Uncached blob URL." . to_string ( ) , None ) ,
779
791
Self :: NoCacheData ( specifier) => ( lsp:: DiagnosticSeverity :: ERROR , "Uncached data URL." . to_string ( ) , Some ( json ! ( { "specifier" : specifier } ) ) ) ,
792
+ Self :: NoCacheNpm ( pkg_ref, specifier) => ( lsp:: DiagnosticSeverity :: ERROR , format ! ( "Uncached or missing npm package: \" {}\" ." , pkg_ref. req) , Some ( json ! ( { "specifier" : specifier } ) ) ) ,
780
793
Self :: NoLocal ( specifier) => ( lsp:: DiagnosticSeverity :: ERROR , format ! ( "Unable to load a local module: \" {}\" .\n Please check the file path." , specifier) , None ) ,
781
794
Self :: Redirect { from, to} => ( lsp:: DiagnosticSeverity :: INFORMATION , format ! ( "The import of \" {}\" was redirected to \" {}\" ." , from, to) , Some ( json ! ( { "specifier" : from, "redirect" : to } ) ) ) ,
782
795
Self :: ResolutionError ( err) => ( lsp:: DiagnosticSeverity :: ERROR , err. to_string ( ) , None ) ,
@@ -847,8 +860,20 @@ fn diagnose_resolved(
847
860
. push ( DenoDiagnostic :: NoAssertType . to_lsp_diagnostic ( & range) ) ,
848
861
}
849
862
}
850
- } else if NpmPackageReference :: from_specifier ( specifier) . is_ok ( ) {
851
- // ignore npm specifiers for now
863
+ } else if let Ok ( pkg_ref) = NpmPackageReference :: from_specifier ( specifier)
864
+ {
865
+ if let Some ( npm_resolver) = & snapshot. maybe_npm_resolver {
866
+ // show diagnostics for npm package references that aren't cached
867
+ if npm_resolver
868
+ . resolve_package_folder_from_deno_module ( & pkg_ref. req )
869
+ . is_err ( )
870
+ {
871
+ diagnostics. push (
872
+ DenoDiagnostic :: NoCacheNpm ( pkg_ref, specifier. clone ( ) )
873
+ . to_lsp_diagnostic ( & range) ,
874
+ ) ;
875
+ }
876
+ }
852
877
} else {
853
878
// When the document is not available, it means that it cannot be found
854
879
// in the cache or locally on the disk, so we want to issue a diagnostic
@@ -882,6 +907,12 @@ fn diagnose_dependency(
882
907
dependency_key : & str ,
883
908
dependency : & deno_graph:: Dependency ,
884
909
) {
910
+ if let Some ( npm_resolver) = & snapshot. maybe_npm_resolver {
911
+ if npm_resolver. in_npm_package ( referrer) {
912
+ return ; // ignore, surface typescript errors instead
913
+ }
914
+ }
915
+
885
916
if let Some ( import_map) = & snapshot. maybe_import_map {
886
917
if let Resolved :: Ok {
887
918
specifier, range, ..
@@ -938,8 +969,8 @@ async fn generate_deno_diagnostics(
938
969
& mut diagnostics,
939
970
snapshot,
940
971
specifier,
941
- & dependency_key,
942
- & dependency,
972
+ dependency_key,
973
+ dependency,
943
974
) ;
944
975
}
945
976
}
0 commit comments