Skip to content

Commit dfa5cbb

Browse files
committed
gopls/internal/lsp/cache: remove workspaceMode
Remove the last vestiges of workspaceMode, which was an abstraction that has been replaced with more specific conditionals where appropriate. For golang/go#57979 Change-Id: Id7ec8e0db3dee9833605b6188ade7c729436b3e8 Reviewed-on: https://go-review.googlesource.com/c/tools/+/542622 Reviewed-by: Alan Donovan <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent a98c076 commit dfa5cbb

File tree

2 files changed

+2
-49
lines changed

2 files changed

+2
-49
lines changed

gopls/internal/lsp/cache/snapshot.go

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -379,29 +379,6 @@ func (s *Snapshot) validBuildConfiguration() bool {
379379
return false
380380
}
381381

382-
// workspaceMode describes the way in which the snapshot's workspace should
383-
// be loaded.
384-
//
385-
// TODO(rfindley): remove this, in favor of specific methods.
386-
func (s *Snapshot) workspaceMode() workspaceMode {
387-
var mode workspaceMode
388-
389-
// If the view has an invalid configuration, don't build the workspace
390-
// module.
391-
validBuildConfiguration := s.validBuildConfiguration()
392-
if !validBuildConfiguration {
393-
return mode
394-
}
395-
// If the view is not in a module and contains no modules, but still has a
396-
// valid workspace configuration, do not create the workspace module.
397-
// It could be using GOPATH or a different build system entirely.
398-
if len(s.view.workspaceModFiles) == 0 && validBuildConfiguration {
399-
return mode
400-
}
401-
mode |= moduleMode
402-
return mode
403-
}
404-
405382
// config returns the configuration used for the snapshot's interaction with
406383
// the go/packages API. It uses the given working directory.
407384
//
@@ -527,7 +504,7 @@ func (s *Snapshot) goCommandInvocation(ctx context.Context, flags source.Invocat
527504
cleanup = func() {} // fallback
528505

529506
// All logic below is for module mode.
530-
if s.workspaceMode()&moduleMode == 0 {
507+
if len(s.view.workspaceModFiles) == 0 {
531508
return "", inv, cleanup, nil
532509
}
533510

@@ -2168,18 +2145,6 @@ func (s *Snapshot) clone(ctx, bgCtx context.Context, changed StateChange) (*Snap
21682145
result.workspacePackages = s.workspacePackages
21692146
}
21702147

2171-
// Don't bother copying the importedBy graph,
2172-
// as it changes each time we update metadata.
2173-
2174-
// TODO(rfindley): consolidate the this workspace mode detection with
2175-
// workspace invalidation.
2176-
workspaceModeChanged := s.workspaceMode() != result.workspaceMode()
2177-
2178-
// If the snapshot's workspace mode has changed, the packages loaded using
2179-
// the previous mode are no longer relevant, so clear them out.
2180-
if workspaceModeChanged {
2181-
result.workspacePackages = immutable.MapOf[PackageID, PackagePath](nil)
2182-
}
21832148
return result, release
21842149
}
21852150

gopls/internal/lsp/cache/view.go

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -387,18 +387,6 @@ func (env *goEnv) vars() map[string]*string {
387387
}
388388
}
389389

390-
// workspaceMode holds various flags defining how the gopls workspace should
391-
// behave. They may be derived from the environment, user configuration, or
392-
// depend on the Go version.
393-
//
394-
// TODO(rfindley): remove workspace mode, in favor of explicit checks.
395-
type workspaceMode int
396-
397-
const (
398-
moduleMode workspaceMode = 1 << iota
399-
)
400-
401-
// ID returns a globally unique identifier for this view.
402390
func (v *View) ID() string { return v.id }
403391

404392
// tempModFile creates a temporary go.mod file based on the contents
@@ -1211,7 +1199,7 @@ var modFlagRegexp = regexp.MustCompile(`-mod[ =](\w+)`)
12111199
// cannot delete it.
12121200
func (s *Snapshot) vendorEnabled(ctx context.Context, modURI protocol.DocumentURI, modContent []byte) (bool, error) {
12131201
// Legacy GOPATH workspace?
1214-
if s.workspaceMode()&moduleMode == 0 {
1202+
if len(s.view.workspaceModFiles) == 0 {
12151203
return false, nil
12161204
}
12171205

0 commit comments

Comments
 (0)