Skip to content

Commit

Permalink
gopls/internal/vulncheck: log progress
Browse files Browse the repository at this point in the history
Log before/after package loading and govulncheck.Source calls.
All stderr output of `gopls vulncheck` command is forwarded to the
client as LSP progress reports and visible to users.

go/packages.Load can be traced further if GOPACKAGESDEBUG env var
is set. Instrumentation in govulncheck.Source is still under
discussion in upstream.

For golang/go#56795

Change-Id: I8244930494aed17b319887bf96c2523f3215fa50
Reviewed-on: https://go-review.googlesource.com/c/tools/+/452055
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
  • Loading branch information
hyangah committed Nov 18, 2022
1 parent 36a5c6a commit c099dff
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion gopls/internal/vulncheck/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,14 @@ func init() {
cfg.Mode = packages.NeedName | packages.NeedImports | packages.NeedTypes |
packages.NeedSyntax | packages.NeedTypesInfo | packages.NeedDeps |
packages.NeedModule

logf := log.New(os.Stderr, "", log.Ltime).Printf
logf("Loading packages...")
pkgs, err := packages.Load(&cfg, patterns...)
if err != nil {
logf("Failed to load packages: %v", err)
return err
}
logf("Loaded %d packages and their dependencies", len(pkgs))
cli, err := client.NewClient(findGOVULNDB(&cfg), client.Options{
HTTPCache: gvc.DefaultCache(),
})
Expand All @@ -240,6 +243,7 @@ func init() {
if err != nil {
return err
}
logf("Found %d vulnerabilities", len(res.Vulns))
if err := json.NewEncoder(os.Stdout).Encode(res); err != nil {
return err
}
Expand Down

0 comments on commit c099dff

Please sign in to comment.