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"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"golang.org/x/tools/internal/lsp/protocol"
|
|
|
|
"golang.org/x/tools/internal/span"
|
|
|
|
)
|
|
|
|
|
|
|
|
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 {
|
|
|
|
return fmt.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-27 12:59:14 -06:00
|
|
|
view := s.session.NewView(ctx, name, uri)
|
2019-07-29 21:48:11 -06:00
|
|
|
s.stateMu.Lock()
|
|
|
|
state := s.state
|
|
|
|
s.stateMu.Unlock()
|
|
|
|
if state >= serverInitialized {
|
2019-07-27 12:59:14 -06:00
|
|
|
s.fetchConfig(ctx, view)
|
|
|
|
}
|
2019-05-15 10:24:49 -06:00
|
|
|
return nil
|
2019-05-06 14:44:43 -06:00
|
|
|
}
|