mirror of https://github.com/golang/go.git
internal/lsp: move hasValidBuildConfiguration into the snapshot
Update hasValidBuildConfiguration as modules are created and deleted. Change-Id: I9196611225d42a87ea5790c564bc9ac1ea1871f1 Reviewed-on: https://go-review.googlesource.com/c/tools/+/257968 Trust: Rebecca Stambler <rstambler@golang.org> Run-TryBot: Rebecca Stambler <rstambler@golang.org> gopls-CI: kokoro <noreply+kokoro@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Heschi Kreinick <heschi@google.com>
This commit is contained in:
parent
2e5f0cfadf
commit
e57f6d466a
|
|
@ -63,7 +63,7 @@ func (s *snapshot) load(ctx context.Context, scopes ...interface{}) error {
|
|||
case viewLoadScope:
|
||||
// If we are outside of GOPATH, a module, or some other known
|
||||
// build system, don't load subdirectories.
|
||||
if !s.view.hasValidBuildConfiguration {
|
||||
if !s.ValidBuildConfiguration() {
|
||||
query = append(query, "./")
|
||||
} else {
|
||||
query = append(query, "./...")
|
||||
|
|
|
|||
|
|
@ -185,20 +185,19 @@ func (s *Session) createView(ctx context.Context, name string, folder span.URI,
|
|||
backgroundCtx, cancel := context.WithCancel(baseCtx)
|
||||
|
||||
v := &View{
|
||||
session: s,
|
||||
initialized: make(chan struct{}),
|
||||
initializationSema: make(chan struct{}, 1),
|
||||
initializeOnce: &sync.Once{},
|
||||
id: strconv.FormatInt(index, 10),
|
||||
options: options,
|
||||
baseCtx: baseCtx,
|
||||
backgroundCtx: backgroundCtx,
|
||||
cancel: cancel,
|
||||
name: name,
|
||||
folder: folder,
|
||||
filesByURI: make(map[span.URI]*fileBase),
|
||||
filesByBase: make(map[string][]*fileBase),
|
||||
hasValidBuildConfiguration: validBuildConfiguration,
|
||||
session: s,
|
||||
initialized: make(chan struct{}),
|
||||
initializationSema: make(chan struct{}, 1),
|
||||
initializeOnce: &sync.Once{},
|
||||
id: strconv.FormatInt(index, 10),
|
||||
options: options,
|
||||
baseCtx: baseCtx,
|
||||
backgroundCtx: backgroundCtx,
|
||||
cancel: cancel,
|
||||
name: name,
|
||||
folder: folder,
|
||||
filesByURI: make(map[span.URI]*fileBase),
|
||||
filesByBase: make(map[string][]*fileBase),
|
||||
processEnv: &imports.ProcessEnv{
|
||||
GocmdRunner: s.gocmdRunner,
|
||||
WorkingDir: folder.Filename(),
|
||||
|
|
|
|||
|
|
@ -125,6 +125,17 @@ func (s *snapshot) FileSet() *token.FileSet {
|
|||
return s.view.session.cache.fset
|
||||
}
|
||||
|
||||
func (s *snapshot) ModFiles() []span.URI {
|
||||
if s.view.modURI == "" {
|
||||
return nil
|
||||
}
|
||||
return []span.URI{s.view.modURI}
|
||||
}
|
||||
|
||||
func (s *snapshot) ValidBuildConfiguration() bool {
|
||||
return validBuildConfiguration(s.view.rootURI, &s.view.workspaceInformation, s.modules)
|
||||
}
|
||||
|
||||
// config returns the configuration used for the snapshot's interaction with
|
||||
// the go/packages API. It uses the given working directory.
|
||||
//
|
||||
|
|
@ -811,7 +822,7 @@ func (s *snapshot) AwaitInitialized(ctx context.Context) {
|
|||
func (s *snapshot) reloadWorkspace(ctx context.Context) error {
|
||||
// If the view's build configuration is invalid, we cannot reload by
|
||||
// package path. Just reload the directory instead.
|
||||
if !s.view.hasValidBuildConfiguration {
|
||||
if !s.ValidBuildConfiguration() {
|
||||
return s.load(ctx, viewLoadScope("LOAD_INVALID_VIEW"))
|
||||
}
|
||||
|
||||
|
|
@ -1213,7 +1224,7 @@ copyIDs:
|
|||
result.workspacePackages[id] = pkgPath
|
||||
}
|
||||
|
||||
if shouldReinitializeView && s.view.hasValidBuildConfiguration {
|
||||
if shouldReinitializeView {
|
||||
s.view.definitelyReinitialize()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -121,10 +121,6 @@ type View struct {
|
|||
// workspaceMode describes the way in which the view's workspace should be
|
||||
// loaded.
|
||||
workspaceMode workspaceMode
|
||||
|
||||
// True if the view is either in GOPATH, a module, or some other
|
||||
// non go command build system.
|
||||
hasValidBuildConfiguration bool
|
||||
}
|
||||
|
||||
type workspaceInformation struct {
|
||||
|
|
@ -209,17 +205,6 @@ func (f *fileBase) addURI(uri span.URI) int {
|
|||
|
||||
func (v *View) ID() string { return v.id }
|
||||
|
||||
func (s *snapshot) ValidBuildConfiguration() bool {
|
||||
return s.view.hasValidBuildConfiguration
|
||||
}
|
||||
|
||||
func (s *snapshot) ModFiles() []span.URI {
|
||||
if s.view.modURI == "" {
|
||||
return nil
|
||||
}
|
||||
return []span.URI{s.view.modURI}
|
||||
}
|
||||
|
||||
// tempModFile creates a temporary go.mod file based on the contents of the
|
||||
// given go.mod file. It is the caller's responsibility to clean up the files
|
||||
// when they are done using them.
|
||||
|
|
@ -376,7 +361,7 @@ func (s *snapshot) WriteEnv(ctx context.Context, w io.Writer) error {
|
|||
s.view.folder.Filename(),
|
||||
s.view.rootURI.Filename(),
|
||||
goVersion.String(),
|
||||
s.view.hasValidBuildConfiguration,
|
||||
s.ValidBuildConfiguration(),
|
||||
buildFlags)
|
||||
for k, v := range fullEnv {
|
||||
fmt.Fprintf(w, "%s=%s\n", k, v)
|
||||
|
|
|
|||
Loading…
Reference in New Issue