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"
|
2019-11-01 14:45:32 -06:00
|
|
|
"golang.org/x/tools/internal/lsp/source"
|
2019-05-06 14:44:43 -06:00
|
|
|
"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
|
|
|
}
|
|
|
|
}
|
2019-11-21 16:55:49 -07:00
|
|
|
s.addFolders(ctx, event.Added)
|
2019-05-06 14:44:43 -06:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-11-29 21:51:14 -07:00
|
|
|
func (s *Server) addView(ctx context.Context, name string, uri span.URI) (source.View, source.Snapshot, 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 {
|
2019-11-15 12:47:29 -07:00
|
|
|
return nil, nil, errors.Errorf("addView called before server initialized")
|
2019-09-09 11:04:12 -06:00
|
|
|
}
|
|
|
|
|
2019-09-11 11:13:44 -06:00
|
|
|
options := s.session.Options()
|
2019-11-29 21:51:14 -07:00
|
|
|
if err := s.fetchConfig(ctx, name, uri, &options); err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
2019-11-01 14:45:32 -06:00
|
|
|
return s.session.NewView(ctx, name, uri, options)
|
2019-11-08 11:26:32 -07:00
|
|
|
}
|
2019-11-01 14:45:32 -06:00
|
|
|
|
2019-11-08 11:26:32 -07:00
|
|
|
func (s *Server) updateConfiguration(ctx context.Context, changed interface{}) error {
|
|
|
|
// go through all the views getting the config
|
|
|
|
for _, view := range s.session.Views() {
|
|
|
|
options := s.session.Options()
|
2019-11-29 21:51:14 -07:00
|
|
|
if err := s.fetchConfig(ctx, view.Name(), view.Folder(), &options); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if _, err := view.SetOptions(ctx, options); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
go s.diagnoseSnapshot(view.Snapshot())
|
2019-11-08 11:26:32 -07:00
|
|
|
}
|
|
|
|
return nil
|
2019-05-06 14:44:43 -06:00
|
|
|
}
|