@@ -546,28 +546,32 @@ func (s *snapshot) initialize(ctx context.Context, firstAttempt bool) {
546
546
Message : err .Error (),
547
547
})
548
548
}
549
- for modURI := range s .workspace .getActiveModFiles () {
550
- fh , err := s .GetFile (ctx , modURI )
551
- if err != nil {
552
- addError (modURI , err )
553
- continue
554
- }
555
- parsed , err := s .ParseMod (ctx , fh )
556
- if err != nil {
557
- addError (modURI , err )
558
- continue
559
- }
560
- if parsed .File == nil || parsed .File .Module == nil {
561
- addError (modURI , fmt .Errorf ("no module path for %s" , modURI ))
562
- continue
549
+ if len (s .workspace .getActiveModFiles ()) > 0 {
550
+ for modURI := range s .workspace .getActiveModFiles () {
551
+ fh , err := s .GetFile (ctx , modURI )
552
+ if err != nil {
553
+ addError (modURI , err )
554
+ continue
555
+ }
556
+ parsed , err := s .ParseMod (ctx , fh )
557
+ if err != nil {
558
+ addError (modURI , err )
559
+ continue
560
+ }
561
+ if parsed .File == nil || parsed .File .Module == nil {
562
+ addError (modURI , fmt .Errorf ("no module path for %s" , modURI ))
563
+ continue
564
+ }
565
+ path := parsed .File .Module .Mod .Path
566
+ scopes = append (scopes , moduleLoadScope (path ))
563
567
}
564
- path := parsed .File .Module .Mod .Path
565
- scopes = append (scopes , moduleLoadScope (path ))
566
- }
567
- if len (scopes ) == 0 {
568
+ } else {
568
569
scopes = append (scopes , viewLoadScope ("LOAD_VIEW" ))
569
570
}
570
- err := s .load (ctx , firstAttempt , append (scopes , packagePath ("builtin" ))... )
571
+ var err error
572
+ if len (scopes ) > 0 {
573
+ err = s .load (ctx , firstAttempt , append (scopes , packagePath ("builtin" ))... )
574
+ }
571
575
if ctx .Err () != nil {
572
576
return
573
577
}
@@ -578,7 +582,12 @@ func (s *snapshot) initialize(ctx context.Context, firstAttempt bool) {
578
582
MainError : err ,
579
583
DiagList : append (modDiagnostics , extractedDiags ... ),
580
584
}
581
- } else if len (modDiagnostics ) != 0 {
585
+ } else if len (modDiagnostics ) == 1 {
586
+ s .initializedErr = & source.CriticalError {
587
+ MainError : fmt .Errorf (modDiagnostics [0 ].Message ),
588
+ DiagList : modDiagnostics ,
589
+ }
590
+ } else if len (modDiagnostics ) > 1 {
582
591
s .initializedErr = & source.CriticalError {
583
592
MainError : fmt .Errorf ("error loading module names" ),
584
593
DiagList : modDiagnostics ,
0 commit comments