Skip to content

Commit 81c7dc4

Browse files
committed
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 <[email protected]> Reviewed-by: Suzy Mueller <[email protected]> Reviewed-by: Jamal Carvalho <[email protected]> gopls-CI: kokoro <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent af2a0a8 commit 81c7dc4

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

gopls/internal/regtest/misc/vuln_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func main() {
109109
Arguments: lens.Command.Arguments,
110110
}, nil)
111111
env.Await(
112-
CompletedWork("Checking vulnerability", 1, true),
112+
CompletedWork("govulncheck", 1, true),
113113
// TODO(hyangah): once the diagnostics are published, wait for diagnostics.
114114
ShownMessage("Found GO-0000-001"),
115115
)

gopls/internal/vulncheck/command.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,29 +70,30 @@ type cmd struct {
7070

7171
// Run runs the govulncheck after loading packages using the provided packages.Config.
7272
func (c *cmd) Run(ctx context.Context, cfg *packages.Config, patterns ...string) (_ []Vuln, err error) {
73+
logger := log.New(log.Default().Writer(), "", 0)
7374
cfg.Mode |= packages.NeedModule | packages.NeedName | packages.NeedFiles |
7475
packages.NeedCompiledGoFiles | packages.NeedImports | packages.NeedTypes |
7576
packages.NeedTypesSizes | packages.NeedSyntax | packages.NeedTypesInfo | packages.NeedDeps
7677

77-
log.Println("loading packages...")
78+
logger.Println("loading packages...")
7879
loadedPkgs, err := gvc.LoadPackages(cfg, patterns...)
7980
if err != nil {
80-
log.Printf("package load failed: %v", err)
81+
logger.Printf("package load failed: %v", err)
8182
return nil, err
8283
}
8384

84-
log.Printf("analyzing %d packages...\n", len(loadedPkgs))
85+
logger.Printf("analyzing %d packages...\n", len(loadedPkgs))
8586

8687
r, err := vulncheck.Source(ctx, loadedPkgs, &vulncheck.Config{Client: c.Client, SourceGoVersion: goVersion()})
8788
if err != nil {
8889
return nil, err
8990
}
9091

91-
log.Printf("selecting affecting vulnerabilities from %d findings...\n", len(r.Vulns))
92+
logger.Printf("selecting affecting vulnerabilities from %d findings...\n", len(r.Vulns))
9293
unaffectedMods := filterUnaffected(r.Vulns)
9394
r.Vulns = filterCalled(r)
9495

95-
log.Printf("found %d vulnerabilities.\n", len(r.Vulns))
96+
logger.Printf("found %d vulnerabilities.\n", len(r.Vulns))
9697
callInfo := gvc.GetCallInfo(r, loadedPkgs)
9798
return toVulns(callInfo, unaffectedMods)
9899
// TODO: add import graphs.

internal/lsp/command.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ func (c *commandHandler) RunVulncheckExp(ctx context.Context, args command.Vulnc
807807
}
808808
err := c.run(ctx, commandConfig{
809809
async: true, // need to be async to be cancellable
810-
progress: "Checking vulnerability",
810+
progress: "govulncheck",
811811
requireSave: true,
812812
forURI: args.URI,
813813
}, func(ctx context.Context, deps commandDeps) error {

0 commit comments

Comments
 (0)