gopls/internal/vulncheck: pass go version to vulncheck config

For golang/go#53869

Change-Id: I8c34adaf81415dafb724ca67fa731912832c3ee5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/418538
Run-TryBot: Jamal Carvalho <jamal@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
This commit is contained in:
Jamal Carvalho 2022-07-20 18:49:20 +00:00
parent 126ef8f864
commit 7b605f471d
2 changed files with 17 additions and 1 deletions

View File

@ -84,7 +84,7 @@ func (c *cmd) Run(ctx context.Context, cfg *packages.Config, patterns ...string)
log.Printf("analyzing %d packages...\n", len(loadedPkgs))
r, err := vulncheck.Source(ctx, loadedPkgs, &vulncheck.Config{Client: c.Client})
r, err := vulncheck.Source(ctx, loadedPkgs, &vulncheck.Config{Client: c.Client, SourceGoVersion: goVersion()})
if err != nil {
return nil, err
}

View File

@ -8,8 +8,11 @@
package vulncheck
import (
"bytes"
"fmt"
"go/token"
"os"
"os/exec"
gvc "golang.org/x/tools/gopls/internal/govulncheck"
"golang.org/x/tools/internal/lsp/protocol"
@ -80,3 +83,16 @@ func posToPosition(pos *token.Position) (p protocol.Position) {
}
return p
}
func goVersion() string {
if v := os.Getenv("GOVERSION"); v != "" {
// Unlikely to happen in practice, mostly used for testing.
return v
}
out, err := exec.Command("go", "env", "GOVERSION").Output()
if err != nil {
fmt.Fprintf(os.Stderr, "failed to determine go version; skipping stdlib scanning: %v\n", err)
return ""
}
return string(bytes.TrimSpace(out))
}