@@ -159,12 +159,7 @@ func (s *snapshot) packageHandle(ctx context.Context, id packageID) (*packageHan
159
159
return nil , errors .Errorf ("%s needs loading" , id )
160
160
}
161
161
if check {
162
- ph , err := s .buildPackageHandle (ctx , m .id )
163
- if err != nil {
164
- return nil , err
165
- }
166
- expectMode (ph , source .ParseFull )
167
- return ph , nil
162
+ return s .buildPackageHandle (ctx , m .id , source .ParseFull )
168
163
}
169
164
var result * packageHandle
170
165
for _ , ph := range phs {
@@ -202,11 +197,10 @@ func (s *snapshot) packageHandles(ctx context.Context, uri span.URI, meta []*met
202
197
var results []* packageHandle
203
198
if check {
204
199
for _ , m := range meta {
205
- ph , err := s .buildPackageHandle (ctx , m .id )
200
+ ph , err := s .buildPackageHandle (ctx , m .id , source . ParseFull )
206
201
if err != nil {
207
202
return nil , err
208
203
}
209
- expectMode (ph , source .ParseFull )
210
204
results = append (results , ph )
211
205
}
212
206
} else {
@@ -252,11 +246,10 @@ func (s *snapshot) shouldCheck(m []*metadata) (phs []*packageHandle, load, check
252
246
// If a single PackageHandle is missing, re-check all of them.
253
247
// TODO: Optimize this by only checking the necessary packages.
254
248
for _ , m := range m {
255
- ph := s .getPackage (m .id )
249
+ ph := s .getPackage (m .id , source . ParseFull )
256
250
if ph == nil {
257
251
return nil , false , true
258
252
}
259
- expectMode (ph , source .ParseFull )
260
253
phs = append (phs , ph )
261
254
}
262
255
// If the metadata for the package had missing dependencies,
@@ -414,24 +407,15 @@ func (s *snapshot) KnownPackages(ctx context.Context) ([]source.PackageHandle, e
414
407
for pkgID := range pkgIDs {
415
408
// Metadata for these packages should already be up-to-date,
416
409
// so just build the package handle directly (without a reload).
417
- ph , err := s .buildPackageHandle (ctx , pkgID )
410
+ ph , err := s .buildPackageHandle (ctx , pkgID , source . ParseExported )
418
411
if err != nil {
419
412
return nil , err
420
413
}
421
- expectMode (ph , source .ParseExported )
422
414
results = append (results , ph )
423
415
}
424
416
return results , nil
425
417
}
426
418
427
- // expectMode is a defensive check to make sure that we mark workspace packages
428
- // correctly. TODO(rstambler): Remove this once we're confident this works.
429
- func expectMode (ph * packageHandle , mode source.ParseMode ) {
430
- if ph .mode != mode {
431
- panic (fmt .Sprintf ("unexpected parse mode for %s" , ph .m .id ))
432
- }
433
- }
434
-
435
419
func (s * snapshot ) CachedImportPaths (ctx context.Context ) (map [string ]source.Package , error ) {
436
420
// Don't reload workspace package metadata.
437
421
// This function is meant to only return currently cached information.
@@ -460,31 +444,17 @@ func (s *snapshot) CachedImportPaths(ctx context.Context) (map[string]source.Pac
460
444
return results , nil
461
445
}
462
446
463
- func (s * snapshot ) getPackage (id packageID ) * packageHandle {
447
+ func (s * snapshot ) getPackage (id packageID , mode source. ParseMode ) * packageHandle {
464
448
s .mu .Lock ()
465
449
defer s .mu .Unlock ()
466
450
467
451
key := packageKey {
468
452
id : id ,
469
- mode : s . packageModeLocked ( id ) ,
453
+ mode : mode ,
470
454
}
471
455
return s .packages [key ]
472
456
}
473
457
474
- func (s * snapshot ) packageMode (id packageID ) source.ParseMode {
475
- s .mu .Lock ()
476
- defer s .mu .Unlock ()
477
-
478
- return s .packageModeLocked (id )
479
- }
480
-
481
- func (s * snapshot ) packageModeLocked (id packageID ) source.ParseMode {
482
- if _ , ok := s .workspacePackages [id ]; ok {
483
- return source .ParseFull
484
- }
485
- return source .ParseExported
486
- }
487
-
488
458
func (s * snapshot ) getActionHandle (id packageID , m source.ParseMode , a * analysis.Analyzer ) * actionHandle {
489
459
s .mu .Lock ()
490
460
defer s .mu .Unlock ()
0 commit comments