[tools] go/analysis: propose to add Code/CodeHref in Diagnostics

3 views
Skip to first unread message

Hyang-Ah Hana Kim (Gerrit)

unread,
Mar 14, 2022, 12:52:49 PM3/14/22
to goph...@pubsubhelper.golang.org, Hyang-Ah Hana Kim, golang-co...@googlegroups.com

Hyang-Ah Hana Kim has uploaded this change for review.

View Change

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.

Gerrit-Project: tools
Gerrit-Branch: master
Gerrit-Change-Id: Ida466a37e7c181412ff97a406b55df5f1397f41f
Gerrit-Change-Number: 392535
Gerrit-PatchSet: 1
Gerrit-Owner: Hyang-Ah Hana Kim <hya...@gmail.com>
Gerrit-Reviewer: Hyang-Ah Hana Kim <hya...@gmail.com>
Gerrit-MessageType: newchange

kokoro (Gerrit)

unread,
Mar 14, 2022, 12:59:46 PM3/14/22
to Hyang-Ah Hana Kim, goph...@pubsubhelper.golang.org, Gopher Robot, golang-co...@googlegroups.com

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

View Change

    To view, visit change 392535. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: tools
    Gerrit-Branch: master
    Gerrit-Change-Id: Ida466a37e7c181412ff97a406b55df5f1397f41f
    Gerrit-Change-Number: 392535
    Gerrit-PatchSet: 1
    Gerrit-Owner: Hyang-Ah Hana Kim <hya...@gmail.com>
    Gerrit-Reviewer: Hyang-Ah Hana Kim <hya...@gmail.com>
    Gerrit-Reviewer: kokoro <noreply...@google.com>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-Comment-Date: Mon, 14 Mar 2022 16:59:43 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    Gerrit-MessageType: comment

    Nooras Saba‎ (Gerrit)

    unread,
    May 12, 2022, 10:00:42 AM5/12/22
    to Hyang-Ah Hana Kim, goph...@pubsubhelper.golang.org, Gopher Robot, kokoro, golang-co...@googlegroups.com

    Attention is currently required from: Hyang-Ah Hana Kim.

    Patch set 1:Code-Review +1

    View Change

    1 comment:

    To view, visit change 392535. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: tools
    Gerrit-Branch: master
    Gerrit-Change-Id: Ida466a37e7c181412ff97a406b55df5f1397f41f
    Gerrit-Change-Number: 392535
    Gerrit-PatchSet: 1
    Gerrit-Owner: Hyang-Ah Hana Kim <hya...@gmail.com>
    Gerrit-Reviewer: Gopher Robot <go...@golang.org>
    Gerrit-Reviewer: Hyang-Ah Hana Kim <hya...@gmail.com>
    Gerrit-Reviewer: Nooras Saba‎ <sa...@golang.org>
    Gerrit-Reviewer: kokoro <noreply...@google.com>
    Gerrit-Attention: Hyang-Ah Hana Kim <hya...@gmail.com>
    Gerrit-Comment-Date: Thu, 12 May 2022 14:00:37 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: Yes
    Gerrit-MessageType: comment

    Hyang-Ah Hana Kim (Gerrit)

    unread,
    Sep 27, 2022, 1:05:32 PM9/27/22
    to Hyang-Ah Hana Kim, goph...@pubsubhelper.golang.org, Nooras Saba‎, Gopher Robot, kokoro, golang-co...@googlegroups.com

    Hyang-Ah Hana Kim abandoned this change.

    View Change

    Abandoned

    To view, visit change 392535. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: tools
    Gerrit-Branch: master
    Gerrit-Change-Id: Ida466a37e7c181412ff97a406b55df5f1397f41f
    Gerrit-Change-Number: 392535
    Gerrit-PatchSet: 1
    Gerrit-Owner: Hyang-Ah Hana Kim <hya...@gmail.com>
    Gerrit-Reviewer: Gopher Robot <go...@golang.org>
    Gerrit-Reviewer: Hyang-Ah Hana Kim <hya...@gmail.com>
    Gerrit-Reviewer: Nooras Saba‎ <sa...@golang.org>
    Gerrit-Reviewer: kokoro <noreply...@google.com>
    Gerrit-MessageType: abandon
    Reply all
    Reply to author
    Forward
    0 new messages