Skip to content

Commit

Permalink
gopls/internal/lsp/cache: clean up view workspace information
Browse files Browse the repository at this point in the history
Tracking of workspace information in the View contained several
inconsistencies and redundancies. Clean this up, with the following
changes:

- eliminate the View.rootURI, opting to derive it instead
- eliminate the View.explicitGowork field, instead using the view.gowork
  field and checking if it is outside of the workspace.
- eliminate many places where directory filters were interpreted
  relative to the rootURI. This is wrong: directory filters are
  expressed relative to the workspace folder.
- remove special handling of GOMODCACHE, now that we're on Go 1.16+
- rewrite the locateTemplateFiles function to use view.filterFunc and
  filepath.WalkDir (now that we're on Go 1.16+).
- don't request goimports env vars when loading environment variables
  for the view. They weren't being propagated to goimports anyway, and
  goimports will load them as needed.

For golang/go#55331

Change-Id: I5e7f7e77e86d9ae425d2feaff31030278fed8240
Reviewed-on: https://go-review.googlesource.com/c/tools/+/459789
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
  • Loading branch information
findleyr authored and rinchsan committed Feb 19, 2023
1 parent fe116ea commit 0985833
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions internal/imports/fix.go
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ type PackageExport struct {
Exports []string
}

var RequiredGoEnvVars = []string{"GO111MODULE", "GOFLAGS", "GOINSECURE", "GOMOD", "GOMODCACHE", "GONOPROXY", "GONOSUMDB", "GOPATH", "GOPROXY", "GOROOT", "GOSUMDB", "GOWORK"}
var requiredGoEnvVars = []string{"GO111MODULE", "GOFLAGS", "GOINSECURE", "GOMOD", "GOMODCACHE", "GONOPROXY", "GONOSUMDB", "GOPATH", "GOPROXY", "GOROOT", "GOSUMDB", "GOWORK"}

// ProcessEnv contains environment variables and settings that affect the use of
// the go command, the go/build package, etc.
Expand Down Expand Up @@ -781,7 +781,7 @@ func (e *ProcessEnv) init() error {
}

foundAllRequired := true
for _, k := range RequiredGoEnvVars {
for _, k := range requiredGoEnvVars {
if _, ok := e.Env[k]; !ok {
foundAllRequired = false
break
Expand All @@ -797,7 +797,7 @@ func (e *ProcessEnv) init() error {
}

goEnv := map[string]string{}
stdout, err := e.invokeGo(context.TODO(), "env", append([]string{"-json"}, RequiredGoEnvVars...)...)
stdout, err := e.invokeGo(context.TODO(), "env", append([]string{"-json"}, requiredGoEnvVars...)...)
if err != nil {
return err
}
Expand Down

0 comments on commit 0985833

Please sign in to comment.