aboutsummaryrefslogtreecommitdiff
path: root/internal/lsp/analysis/noresultvalues
diff options
context:
space:
mode:
authorRebecca Stambler <rstambler@golang.org>2020-03-31 23:53:42 -0400
committerRebecca Stambler <rstambler@golang.org>2020-04-08 01:45:16 +0000
commit4d14fc9c00cedea0631fe7d87ee41b1a25031402 (patch)
treed0541048262d145058a4a372b914ab7c43ee15b4 /internal/lsp/analysis/noresultvalues
parentcd5a53e07f8afe06972bd4cb8226aebeb6cfaf68 (diff)
downloadgolang-x-tools-4d14fc9c00cedea0631fe7d87ee41b1a25031402.tar.gz
internal/lsp: add type error fixes to existing diagnostics
This change is the first step in handling golang/go#38136. Instead of creating multiple diagnostic reports for type error analyzers, we add suggested fixes to the existing reports. To match the analyzers for FindAnalysisError, we add an ErrorMatch function to source.Analyzer. This is not an ideal solution, but it was the best one I could come up with without modifying the go/analysis API. analysisinternal could be used for this purpose, but it seemed to complicated to be worth it, and this is fairly simple. I think that go/analysis itself might need to be extended for type error analyzers, but these temporary measures will help us understand the kinds of features we need for type error analyzers. A follow-up CL might be to not add reports for type error analyzers until the end of source.Diagnostic, which would remove the need for the look-up. Fixes golang/go#38136 Change-Id: I25bc6396b09d49facecd918bf5591d2d5bdf1b3a Reviewed-on: https://go-review.googlesource.com/c/tools/+/226777 Run-TryBot: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Heschi Kreinick <heschi@google.com>
Diffstat (limited to 'internal/lsp/analysis/noresultvalues')
-rw-r--r--internal/lsp/analysis/noresultvalues/noresultvalues.go8
1 files changed, 5 insertions, 3 deletions
diff --git a/internal/lsp/analysis/noresultvalues/noresultvalues.go b/internal/lsp/analysis/noresultvalues/noresultvalues.go
index 0259691ed..0e6b26f8b 100644
--- a/internal/lsp/analysis/noresultvalues/noresultvalues.go
+++ b/internal/lsp/analysis/noresultvalues/noresultvalues.go
@@ -34,8 +34,6 @@ var Analyzer = &analysis.Analyzer{
RunDespiteErrors: true,
}
-const noResultValuesMsg = "no result values expected"
-
func run(pass *analysis.Pass) (interface{}, error) {
inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
errors := analysisinternal.GetTypeErrors(pass)
@@ -56,7 +54,7 @@ func run(pass *analysis.Pass) (interface{}, error) {
}
for _, err := range errors {
- if err.Msg != noResultValuesMsg {
+ if !FixesError(err.Msg) {
continue
}
if retStmt.Pos() >= err.Pos || err.Pos >= retStmt.End() {
@@ -83,3 +81,7 @@ func run(pass *analysis.Pass) (interface{}, error) {
})
return nil, nil
}
+
+func FixesError(msg string) bool {
+ return msg == "no result values expected"
+}