diff --git a/internal/lsp/cache/load.go b/internal/lsp/cache/load.go index 63254f0827..b44be38faf 100644 --- a/internal/lsp/cache/load.go +++ b/internal/lsp/cache/load.go @@ -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, "./...") diff --git a/internal/lsp/cache/session.go b/internal/lsp/cache/session.go index 7de3bc8ee0..61595a27d9 100644 --- a/internal/lsp/cache/session.go +++ b/internal/lsp/cache/session.go @@ -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(), diff --git a/internal/lsp/cache/snapshot.go b/internal/lsp/cache/snapshot.go index 102113338c..759cb33cc5 100644 --- a/internal/lsp/cache/snapshot.go +++ b/internal/lsp/cache/snapshot.go @@ -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() } diff --git a/internal/lsp/cache/view.go b/internal/lsp/cache/view.go index 5be4c006b2..fca69e8f62 100644 --- a/internal/lsp/cache/view.go +++ b/internal/lsp/cache/view.go @@ -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)