gopls/internal/lsp/mod: fix vulncheck hover message

This fixes multi-paragraph vulnerability description rendering.

Change-Id: I2960c5f3a839fb4161ae5e25d3e88b5a7345b65d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/447736
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
This commit is contained in:
Hana (Hyang-Ah) Kim 2022-11-03 14:30:08 -04:00 committed by Hyang-Ah Hana Kim
parent 4ada35e5cb
commit a77a1fb995
2 changed files with 4 additions and 5 deletions

View File

@ -7,7 +7,6 @@
package mod
import (
"bytes"
"context"
"fmt"
"sort"
@ -306,7 +305,7 @@ func formatMessage(v govulncheck.Vuln) string {
details[i] = ' '
}
}
return fmt.Sprintf("%s has a known vulnerability: %s", v.ModPath, string(bytes.TrimSpace(details)))
return strings.TrimSpace(strings.Replace(string(details), "\n\n", "\n\n ", -1))
}
// href returns a URL embedded in the entry if any.

View File

@ -169,13 +169,13 @@ func formatVulnerabilities(affecting, nonaffecting []govulncheck.Vuln, options *
}
if useMarkdown {
fmt.Fprintf(&b, " - [**%v**](%v) %v %v\n", v.OSV.ID, href(v.OSV), formatMessage(v), fix)
fmt.Fprintf(&b, "- [**%v**](%v) %v %v\n", v.OSV.ID, href(v.OSV), formatMessage(v), fix)
} else {
fmt.Fprintf(&b, " - [%v] %v (%v) %v\n", v.OSV.ID, formatMessage(v), href(v.OSV), fix)
}
}
if len(nonaffecting) > 0 {
fmt.Fprintf(&b, "The project imports packages affected by the following vulnerabilities, but does not use vulnerable symbols.")
fmt.Fprintf(&b, "\n**FYI:** The project imports packages with known vulnerabilities, but does not call the vulnerable code.\n")
}
for _, v := range nonaffecting {
fix := "No fix is available."
@ -183,7 +183,7 @@ func formatVulnerabilities(affecting, nonaffecting []govulncheck.Vuln, options *
fix = "Fixed in " + v.FixedIn + "."
}
if useMarkdown {
fmt.Fprintf(&b, " - [%v](%v) %v %v\n", v.OSV.ID, href(v.OSV), formatMessage(v), fix)
fmt.Fprintf(&b, "- [%v](%v) %v %v\n", v.OSV.ID, href(v.OSV), formatMessage(v), fix)
} else {
fmt.Fprintf(&b, " - [%v] %v %v (%v)\n", v.OSV.ID, formatMessage(v), fix, href(v.OSV))
}