@@ -64,7 +64,7 @@ type Session struct {
64
64
65
65
viewMu sync.Mutex
66
66
views []* View
67
- viewMap map [protocol.DocumentURI ]* View // file->best view or nil; nil after shutdown
67
+ viewMap map [protocol.DocumentURI ]* View // file->best view or nil; nil after shutdown; the key must be a clean uri.
68
68
69
69
// snapshots is a counting semaphore that records the number
70
70
// of unreleased snapshots associated with this session.
@@ -139,15 +139,16 @@ func (s *Session) NewView(ctx context.Context, folder *Folder) (*View, *Snapshot
139
139
}
140
140
view , snapshot , release := s .createView (ctx , def )
141
141
s .views = append (s .views , view )
142
- s .viewMap [protocol . Clean ( folder .Dir )] = view
142
+ s .viewMap [folder .Dir . Clean ( )] = view
143
143
return view , snapshot , release , nil
144
144
}
145
145
146
146
// HasView checks whether the uri's view exists.
147
147
func (s * Session ) HasView (uri protocol.DocumentURI ) bool {
148
+ uri = uri .Clean ()
148
149
s .viewMu .Lock ()
149
150
defer s .viewMu .Unlock ()
150
- _ , ok := s .viewMap [protocol . Clean ( uri ) ]
151
+ _ , ok := s .viewMap [uri ]
151
152
return ok
152
153
}
153
154
@@ -379,6 +380,7 @@ func (s *Session) View(id string) (*View, error) {
379
380
//
380
381
// On success, the caller must call the returned function to release the snapshot.
381
382
func (s * Session ) SnapshotOf (ctx context.Context , uri protocol.DocumentURI ) (* Snapshot , func (), error ) {
383
+ uri = uri .Clean ()
382
384
// Fast path: if the uri has a static association with a view, return it.
383
385
s .viewMu .Lock ()
384
386
v , err := s .viewOfLocked (ctx , uri )
@@ -396,7 +398,7 @@ func (s *Session) SnapshotOf(ctx context.Context, uri protocol.DocumentURI) (*Sn
396
398
// View is shut down. Forget this association.
397
399
s .viewMu .Lock ()
398
400
if s .viewMap [uri ] == v {
399
- delete (s .viewMap , protocol . Clean ( uri ) )
401
+ delete (s .viewMap , uri )
400
402
}
401
403
s .viewMu .Unlock ()
402
404
}
@@ -473,7 +475,7 @@ var errNoViews = errors.New("no views")
473
475
// viewOfLocked evaluates the best view for uri, memoizing its result in
474
476
// s.viewMap.
475
477
//
476
- // Precondition: caller holds s.viewMu lock.
478
+ // Precondition: caller holds s.viewMu lock; uri must be clean .
477
479
//
478
480
// May return (nil, nil) if no best view can be determined.
479
481
func (s * Session ) viewOfLocked (ctx context.Context , uri protocol.DocumentURI ) (* View , error ) {
@@ -500,7 +502,7 @@ func (s *Session) viewOfLocked(ctx context.Context, uri protocol.DocumentURI) (*
500
502
// (as in golang/go#60776).
501
503
v = relevantViews [0 ]
502
504
}
503
- s .viewMap [protocol . Clean ( uri ) ] = v // may be nil
505
+ s .viewMap [uri ] = v // may be nil
504
506
}
505
507
return v , nil
506
508
}
@@ -748,7 +750,7 @@ func (s *Session) ResetView(ctx context.Context, uri protocol.DocumentURI) (*Vie
748
750
return nil , fmt .Errorf ("session is shut down" )
749
751
}
750
752
751
- view , err := s .viewOfLocked (ctx , uri )
753
+ view , err := s .viewOfLocked (ctx , uri . Clean () )
752
754
if err != nil {
753
755
return nil , err
754
756
}
0 commit comments