2019-05-06 14:44:43 -06:00
|
|
|
// Copyright 2019 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package lsp
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"golang.org/x/tools/internal/lsp/protocol"
|
|
|
|
"golang.org/x/tools/internal/span"
|
2019-08-06 13:13:11 -06:00
|
|
|
errors "golang.org/x/xerrors"
|
2019-05-06 14:44:43 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
func (s *Server) changeFolders(ctx context.Context, event protocol.WorkspaceFoldersChangeEvent) error {
|
|
|
|
for _, folder := range event.Removed {
|
2019-05-15 10:24:49 -06:00
|
|
|
view := s.session.View(folder.Name)
|
|
|
|
if view != nil {
|
|
|
|
view.Shutdown(ctx)
|
|
|
|
} else {
|
2019-08-06 13:13:11 -06:00
|
|
|
return errors.Errorf("view %s for %v not found", folder.Name, folder.URI)
|
2019-05-06 14:44:43 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, folder := range event.Added {
|
|
|
|
if err := s.addView(ctx, folder.Name, span.NewURI(folder.URI)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Server) addView(ctx context.Context, name string, uri span.URI) error {
|
2019-07-29 21:48:11 -06:00
|
|
|
s.stateMu.Lock()
|
|
|
|
state := s.state
|
|
|
|
s.stateMu.Unlock()
|
2019-09-09 11:04:12 -06:00
|
|
|
if state < serverInitialized {
|
|
|
|
return errors.Errorf("addView called before server initialized")
|
|
|
|
}
|
|
|
|
|
2019-09-11 11:13:44 -06:00
|
|
|
options := s.session.Options()
|
|
|
|
s.fetchConfig(ctx, name, uri, &options)
|
|
|
|
s.session.NewView(ctx, name, uri, options)
|
2019-05-15 10:24:49 -06:00
|
|
|
return nil
|
2019-05-06 14:44:43 -06:00
|
|
|
}
|