From 81c7dc4e4efa77b1f401e403365b23ca06422ab7 Mon Sep 17 00:00:00 2001 From: "Hana (Hyang-Ah) Kim" Date: Wed, 3 Aug 2022 00:01:48 -0400 Subject: [PATCH] internal/lsp: polish vulncheck progress messages gopls.run_vulncheck_exp runs `gopls vulncheck` (fork of govulncheck) and pipes its stderr (logs) as progress messages. The default log format includes timestamp and that is too long for progress message. Tell gopls vulncheck to omit timestamp in the log message. Use "govulncheck" as the progress message prefix, instead of the long "Checking vulnerabilities". Change-Id: I92fe9958b20d0260711a42af9b5f9f399e267587 Reviewed-on: https://go-review.googlesource.com/c/tools/+/420998 Run-TryBot: Hyang-Ah Hana Kim Reviewed-by: Suzy Mueller Reviewed-by: Jamal Carvalho gopls-CI: kokoro TryBot-Result: Gopher Robot --- gopls/internal/regtest/misc/vuln_test.go | 2 +- gopls/internal/vulncheck/command.go | 11 ++++++----- internal/lsp/command.go | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/gopls/internal/regtest/misc/vuln_test.go b/gopls/internal/regtest/misc/vuln_test.go index 78c193efa0..91fef3f88b 100644 --- a/gopls/internal/regtest/misc/vuln_test.go +++ b/gopls/internal/regtest/misc/vuln_test.go @@ -109,7 +109,7 @@ func main() { Arguments: lens.Command.Arguments, }, nil) env.Await( - CompletedWork("Checking vulnerability", 1, true), + CompletedWork("govulncheck", 1, true), // TODO(hyangah): once the diagnostics are published, wait for diagnostics. ShownMessage("Found GO-0000-001"), ) diff --git a/gopls/internal/vulncheck/command.go b/gopls/internal/vulncheck/command.go index b84daa5d9f..60d582ca31 100644 --- a/gopls/internal/vulncheck/command.go +++ b/gopls/internal/vulncheck/command.go @@ -70,29 +70,30 @@ type cmd struct { // Run runs the govulncheck after loading packages using the provided packages.Config. func (c *cmd) Run(ctx context.Context, cfg *packages.Config, patterns ...string) (_ []Vuln, err error) { + logger := log.New(log.Default().Writer(), "", 0) cfg.Mode |= packages.NeedModule | packages.NeedName | packages.NeedFiles | packages.NeedCompiledGoFiles | packages.NeedImports | packages.NeedTypes | packages.NeedTypesSizes | packages.NeedSyntax | packages.NeedTypesInfo | packages.NeedDeps - log.Println("loading packages...") + logger.Println("loading packages...") loadedPkgs, err := gvc.LoadPackages(cfg, patterns...) if err != nil { - log.Printf("package load failed: %v", err) + logger.Printf("package load failed: %v", err) return nil, err } - log.Printf("analyzing %d packages...\n", len(loadedPkgs)) + logger.Printf("analyzing %d packages...\n", len(loadedPkgs)) r, err := vulncheck.Source(ctx, loadedPkgs, &vulncheck.Config{Client: c.Client, SourceGoVersion: goVersion()}) if err != nil { return nil, err } - log.Printf("selecting affecting vulnerabilities from %d findings...\n", len(r.Vulns)) + logger.Printf("selecting affecting vulnerabilities from %d findings...\n", len(r.Vulns)) unaffectedMods := filterUnaffected(r.Vulns) r.Vulns = filterCalled(r) - log.Printf("found %d vulnerabilities.\n", len(r.Vulns)) + logger.Printf("found %d vulnerabilities.\n", len(r.Vulns)) callInfo := gvc.GetCallInfo(r, loadedPkgs) return toVulns(callInfo, unaffectedMods) // TODO: add import graphs. diff --git a/internal/lsp/command.go b/internal/lsp/command.go index 1d6c973212..35bc0e4328 100644 --- a/internal/lsp/command.go +++ b/internal/lsp/command.go @@ -807,7 +807,7 @@ func (c *commandHandler) RunVulncheckExp(ctx context.Context, args command.Vulnc } err := c.run(ctx, commandConfig{ async: true, // need to be async to be cancellable - progress: "Checking vulnerability", + progress: "govulncheck", requireSave: true, forURI: args.URI, }, func(ctx context.Context, deps commandDeps) error {