mirror of
https://github.com/golang/go
synced 2024-11-18 20:34:39 -07:00
internal/lsp: do not invoke the Go command when checking common errors
There's no need to do this more than once per view. Change-Id: I3160adc602764204155dd0e506fd554aeb55d639 Reviewed-on: https://go-review.googlesource.com/c/tools/+/215321 Run-TryBot: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Heschi Kreinick <heschi@google.com>
This commit is contained in:
parent
354bea8ca8
commit
1486df0b25
4
internal/lsp/cache/view.go
vendored
4
internal/lsp/cache/view.go
vendored
@ -502,6 +502,10 @@ func (v *view) addIgnoredFile(uri span.URI) {
|
||||
v.ignoredURIs[uri] = struct{}{}
|
||||
}
|
||||
|
||||
func (v *view) ModFile() string {
|
||||
return v.gomod
|
||||
}
|
||||
|
||||
func (v *view) BackgroundContext() context.Context {
|
||||
v.mu.Lock()
|
||||
defer v.mu.Unlock()
|
||||
|
@ -20,10 +20,6 @@ import (
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
if runtime.GOOS == "android" {
|
||||
fmt.Fprintln(os.Stderr, "skipping test: cmd tests open too many files on android")
|
||||
os.Exit(0)
|
||||
}
|
||||
testenv.ExitIfSmallMachine()
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
@ -31,25 +31,13 @@ func checkCommonErrors(ctx context.Context, v View) (string, error) {
|
||||
// 1. The user is in GOPATH mode and is working outside their GOPATH
|
||||
// 2. The user is in module mode and has opened a subdirectory of their module
|
||||
//
|
||||
|
||||
// TODO(rstambler): Get the values for GOPATH and GOMOD from
|
||||
// the view, once it's possible to do so: golang.org/cl/214417.
|
||||
gopath := os.Getenv("GOPATH")
|
||||
folder := v.Folder().Filename()
|
||||
|
||||
// Invoke `go env GOMOD` inside of the directory of the view.
|
||||
b, err := InvokeGo(ctx, folder, v.Config(ctx).Env, "env", "GOMOD")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
modFile := strings.TrimSpace(b.String())
|
||||
if modFile == filepath.FromSlash("/dev/null") {
|
||||
modFile = ""
|
||||
}
|
||||
modRoot := filepath.Dir(modFile)
|
||||
modRoot := filepath.Dir(v.ModFile())
|
||||
|
||||
// Not inside of a module.
|
||||
inAModule := modFile != ""
|
||||
inAModule := v.ModFile() != "" && v.ModFile() != os.DevNull
|
||||
|
||||
// The user may have a multiple directories in their GOPATH.
|
||||
var inGopath bool
|
||||
|
@ -92,6 +92,9 @@ type View interface {
|
||||
// Folder returns the root folder for this view.
|
||||
Folder() span.URI
|
||||
|
||||
// ModFile is the path to the go.mod file for the view, if any.
|
||||
ModFile() string
|
||||
|
||||
// LookupBuiltin returns the go/ast.Object for the given name in the builtin package.
|
||||
LookupBuiltin(ctx context.Context, name string) (*ast.Object, error)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user