@@ -109,13 +109,14 @@ func (s *Session) NewView(ctx context.Context, name string, folder span.URI, opt
109
109
110
110
// TODO(rfindley): clarify that createView can never be cancelled (with the
111
111
// possible exception of server shutdown).
112
+ // On success, the caller becomes responsible for calling the release function once.
112
113
func (s * Session ) createView (ctx context.Context , name string , folder span.URI , options * source.Options , seqID uint64 ) (* View , * snapshot , func (), error ) {
113
114
index := atomic .AddInt64 (& viewIndex , 1 )
114
115
115
116
// Get immutable workspace information.
116
117
info , err := s .getWorkspaceInformation (ctx , folder , options )
117
118
if err != nil {
118
- return nil , nil , func () {} , err
119
+ return nil , nil , nil , err
119
120
}
120
121
121
122
gowork , _ := info .GOWORK ()
@@ -327,6 +328,15 @@ func (s *Session) updateViewLocked(ctx context.Context, view *View, options *sou
327
328
}
328
329
329
330
v , snapshot , release , err := s .createView (ctx , view .name , view .folder , options , seqID )
331
+ if err != nil {
332
+ // we have dropped the old view, but could not create the new one
333
+ // this should not happen and is very bad, but we still need to clean
334
+ // up the view array if it happens
335
+ s .views = removeElement (s .views , i )
336
+ return nil , err
337
+ }
338
+ defer release ()
339
+
330
340
// The new snapshot has lost the history of the previous view. As a result,
331
341
// it may not see open files that aren't in its build configuration (as it
332
342
// would have done via didOpen notifications). This can lead to inconsistent
@@ -336,15 +346,7 @@ func (s *Session) updateViewLocked(ctx context.Context, view *View, options *sou
336
346
for _ , o := range v .fs .Overlays () {
337
347
_ , _ = snapshot .ReadFile (ctx , o .URI ())
338
348
}
339
- release ()
340
349
341
- if err != nil {
342
- // we have dropped the old view, but could not create the new one
343
- // this should not happen and is very bad, but we still need to clean
344
- // up the view array if it happens
345
- s .views = removeElement (s .views , i )
346
- return nil , err
347
- }
348
350
// substitute the new view into the array where the old view was
349
351
s .views [i ] = v
350
352
return v , nil
0 commit comments