Hyang-Ah Hana Kim has uploaded this change for review.
go/analysis: propose to add Code/CodeHref in Diagnostics
LSP diagnostics allow to use diagnostics code and a link to a doc
that includes more details about the diagnostics.
Inclusion of these fields in the Diagnostics allows each analyzer
to add more structured context useful for users.
Propagate these when converting from analysis.Diagnostic to
internal/lsp/source.Diagnostic.
Change-Id: Ida466a37e7c181412ff97a406b55df5f1397f41f
---
M go/analysis/diagnostic.go
M go/analysis/internal/analysisflags/flags.go
M internal/lsp/cache/errors.go
3 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/go/analysis/diagnostic.go b/go/analysis/diagnostic.go
index cd462a0..65ea24d 100644
--- a/go/analysis/diagnostic.go
+++ b/go/analysis/diagnostic.go
@@ -28,7 +28,9 @@
SuggestedFixes []SuggestedFix // optional
// Experimental: This API is experimental and may change in the future.
- Related []RelatedInformation // optional
+ Related []RelatedInformation // optional
+ Code string // optional
+ CodeHref string // optional
}
// RelatedInformation contains information related to a diagnostic.
diff --git a/go/analysis/internal/analysisflags/flags.go b/go/analysis/internal/analysisflags/flags.go
index 4b7be2d..663eb93 100644
--- a/go/analysis/internal/analysisflags/flags.go
+++ b/go/analysis/internal/analysisflags/flags.go
@@ -319,7 +319,11 @@
// with context specified by the -c flag.
func PrintPlain(fset *token.FileSet, diag analysis.Diagnostic) {
posn := fset.Position(diag.Pos)
- fmt.Fprintf(os.Stderr, "%s: %s\n", posn, diag.Message)
+ msg := diag.Message
+ if diag.Code != "" {
+ msg = fmt.Sprintf("%s\n(%s) %s", strings.TrimSpace(diag.Message), diag.Code, diag.CodeHref)
+ }
+ fmt.Fprintf(os.Stderr, "%s: %s\n", posn, msg)
// -c=N: show offending line plus N lines of context.
if Context >= 0 {
diff --git a/internal/lsp/cache/errors.go b/internal/lsp/cache/errors.go
index e9a86de..16c09d1 100644
--- a/internal/lsp/cache/errors.go
+++ b/internal/lsp/cache/errors.go
@@ -245,6 +245,8 @@
Related: related,
SuggestedFixes: fixes,
Analyzer: srcAnalyzer,
+ Code: e.Code,
+ CodeHref: e.CodeHref,
}
// If the fixes only delete code, assume that the diagnostic is reporting dead code.
if onlyDeletions(fixes) {
To view, visit change 392535. To unsubscribe, or for help writing mail filters, visit settings.
Kokoro presubmit build finished with status: SUCCESS
Logs at: https://source.cloud.google.com/results/invocations/2c488965-bf00-40e3-abee-8b98e41c4e23
Patch set 1:gopls-CI +1
Attention is currently required from: Hyang-Ah Hana Kim.
Patch set 1:Code-Review +1
1 comment:
Commit Message:
Issue id ?
To view, visit change 392535. To unsubscribe, or for help writing mail filters, visit settings.
Hyang-Ah Hana Kim abandoned this change.
To view, visit change 392535. To unsubscribe, or for help writing mail filters, visit settings.