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
|
|
|
)
|
|
|
|
|
2020-01-23 08:56:00 -07:00
|
|
|
func (s *Server) didChangeWorkspaceFolders(ctx context.Context, params *protocol.DidChangeWorkspaceFoldersParams) error {
|
|
|
|
event := params.Event
|
2019-05-06 14:44:43 -06:00
|
|
|
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
|
|
|
|
2020-01-23 08:56:00 -07:00
|
|
|
func (s *Server) didChangeConfiguration(ctx context.Context, changed interface{}) error {
|
2019-11-08 11:26:32 -07:00
|
|
|
// 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
|
|
|
|
}
|
2019-12-19 12:31:39 -07:00
|
|
|
view, err := view.SetOptions(ctx, options)
|
|
|
|
if err != nil {
|
2019-11-29 21:51:14 -07:00
|
|
|
return err
|
|
|
|
}
|
2020-01-11 21:59:57 -07:00
|
|
|
go s.diagnoseDetached(view.Snapshot())
|
2019-11-08 11:26:32 -07:00
|
|
|
}
|
|
|
|
return nil
|
2019-05-06 14:44:43 -06:00
|
|
|
}
|