@@ -64,7 +64,7 @@ type Session struct {
6464
6565 viewMu sync.Mutex
6666 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.
6868
6969 // snapshots is a counting semaphore that records the number
7070 // of unreleased snapshots associated with this session.
@@ -139,15 +139,16 @@ func (s *Session) NewView(ctx context.Context, folder *Folder) (*View, *Snapshot
139139 }
140140 view , snapshot , release := s .createView (ctx , def )
141141 s .views = append (s .views , view )
142- s .viewMap [protocol . Clean ( folder .Dir )] = view
142+ s .viewMap [folder .Dir . Clean ( )] = view
143143 return view , snapshot , release , nil
144144}
145145
146146// HasView checks whether the uri's view exists.
147147func (s * Session ) HasView (uri protocol.DocumentURI ) bool {
148+ uri = uri .Clean ()
148149 s .viewMu .Lock ()
149150 defer s .viewMu .Unlock ()
150- _ , ok := s .viewMap [protocol . Clean ( uri ) ]
151+ _ , ok := s .viewMap [uri ]
151152 return ok
152153}
153154
@@ -379,6 +380,7 @@ func (s *Session) View(id string) (*View, error) {
379380//
380381// On success, the caller must call the returned function to release the snapshot.
381382func (s * Session ) SnapshotOf (ctx context.Context , uri protocol.DocumentURI ) (* Snapshot , func (), error ) {
383+ uri = uri .Clean ()
382384 // Fast path: if the uri has a static association with a view, return it.
383385 s .viewMu .Lock ()
384386 v , err := s .viewOfLocked (ctx , uri )
@@ -396,7 +398,7 @@ func (s *Session) SnapshotOf(ctx context.Context, uri protocol.DocumentURI) (*Sn
396398 // View is shut down. Forget this association.
397399 s .viewMu .Lock ()
398400 if s .viewMap [uri ] == v {
399- delete (s .viewMap , protocol . Clean ( uri ) )
401+ delete (s .viewMap , uri )
400402 }
401403 s .viewMu .Unlock ()
402404 }
@@ -473,7 +475,7 @@ var errNoViews = errors.New("no views")
473475// viewOfLocked evaluates the best view for uri, memoizing its result in
474476// s.viewMap.
475477//
476- // Precondition: caller holds s.viewMu lock.
478+ // Precondition: caller holds s.viewMu lock; uri must be clean .
477479//
478480// May return (nil, nil) if no best view can be determined.
479481func (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) (*
500502 // (as in golang/go#60776).
501503 v = relevantViews [0 ]
502504 }
503- s .viewMap [protocol . Clean ( uri ) ] = v // may be nil
505+ s .viewMap [uri ] = v // may be nil
504506 }
505507 return v , nil
506508}
@@ -748,7 +750,7 @@ func (s *Session) ResetView(ctx context.Context, uri protocol.DocumentURI) (*Vie
748750 return nil , fmt .Errorf ("session is shut down" )
749751 }
750752
751- view , err := s .viewOfLocked (ctx , uri )
753+ view , err := s .viewOfLocked (ctx , uri . Clean () )
752754 if err != nil {
753755 return nil , err
754756 }
0 commit comments