1
0
mirror of https://github.com/golang/go synced 2024-11-18 22:44:48 -07:00
go/internal/lsp/workspace.go
Ian Cottrell 3d22a3cfff internal/lsp: only build a view when we have its configuration
We now wait to build views until we have the options for that view,
and pass the options in to the view constructor.
The environment and build flags are now part of the view options.

Change-Id: I303c8ba1eefd01b66962ba9cadb4847d3d2e1d3b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/194278
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-09-10 14:40:41 +00:00

49 lines
1.3 KiB
Go

// 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"
errors "golang.org/x/xerrors"
)
func (s *Server) changeFolders(ctx context.Context, event protocol.WorkspaceFoldersChangeEvent) error {
for _, folder := range event.Removed {
view := s.session.View(folder.Name)
if view != nil {
view.Shutdown(ctx)
} else {
return errors.Errorf("view %s for %v not found", folder.Name, folder.URI)
}
}
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 {
s.stateMu.Lock()
state := s.state
s.stateMu.Unlock()
if state < serverInitialized {
return errors.Errorf("addView called before server initialized")
}
options := s.session.Options()
viewOptions := options.DefaultViewOptions
//TODO: take this out, we only allow new session options here
defer func() { s.session.SetOptions(options) }()
s.fetchConfig(ctx, name, uri, &options, &viewOptions)
s.session.NewView(ctx, name, uri, viewOptions)
return nil
}