mirror of
https://github.com/golang/go
synced 2024-11-18 10:54:40 -07:00
internal/lsp: fix erroneous documentation for struct fields
The fix is just a missing return. Also clean up a staticcheck thing, regenerate the golden files. Fixes golang/go#38417 Change-Id: I290b63df9d97211c59d6399fda7a273bc700fbdb Reviewed-on: https://go-review.googlesource.com/c/tools/+/228297 Run-TryBot: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
parent
92398ad77b
commit
5d8e1897c7
@ -10,6 +10,8 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/tools/internal/lsp/diff"
|
||||
"golang.org/x/tools/internal/lsp/diff/myers"
|
||||
"golang.org/x/tools/internal/lsp/tests"
|
||||
"golang.org/x/tools/internal/span"
|
||||
)
|
||||
@ -50,7 +52,8 @@ func (r *runner) Definition(t *testing.T, spn span.Span, d tests.Definition) {
|
||||
return []byte(got), nil
|
||||
})))
|
||||
if expect != "" && !strings.HasPrefix(got, expect) {
|
||||
t.Errorf("definition %v failed with %#v expected:\n%q\ngot:\n%q", tag, args, expect, got)
|
||||
d := myers.ComputeEdits("", expect, got)
|
||||
t.Errorf("definition %v failed with %#v\n%s", tag, args, diff.ToUnified("expect", "got", expect, d))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -350,9 +350,7 @@ func addReports(snapshot Snapshot, reports map[FileIdentity][]*Diagnostic, uri s
|
||||
return nil
|
||||
}
|
||||
}
|
||||
for _, diag := range diagnostics {
|
||||
reports[fh.Identity()] = append(reports[fh.Identity()], diag)
|
||||
}
|
||||
reports[fh.Identity()] = append(reports[fh.Identity()], diagnostics...)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -291,9 +291,8 @@ func formatVar(node ast.Spec, obj types.Object, decl *ast.GenDecl) *HoverInforma
|
||||
if field.Pos() <= obj.Pos() && obj.Pos() <= field.End() {
|
||||
if field.Doc.Text() != "" {
|
||||
return &HoverInformation{source: obj, comment: field.Doc}
|
||||
} else if field.Comment.Text() != "" {
|
||||
return &HoverInformation{source: obj, comment: field.Comment}
|
||||
}
|
||||
return &HoverInformation{source: obj, comment: field.Comment}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,14 @@ type Pos struct {
|
||||
x, y int //@mark(PosX, "x"),mark(PosY, "y")
|
||||
}
|
||||
|
||||
// Typ has a comment. Its fields do not.
|
||||
type Typ struct{ field string } //@mark(TypField, "field")
|
||||
|
||||
func _() {
|
||||
x := &Typ{}
|
||||
x.field //@godef("field", TypField)
|
||||
}
|
||||
|
||||
func (p *Pos) Sum() int { //@mark(PosSum, "Sum")
|
||||
return p.x + p.y //@godef("x", PosX)
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
-- PosSum-definition --
|
||||
godef/a/random.go:16:15-18: defined here as ```go
|
||||
godef/a/random.go:24:15-18: defined here as ```go
|
||||
func (*Pos).Sum() int
|
||||
```
|
||||
|
||||
@ -9,14 +9,14 @@ func (*Pos).Sum() int
|
||||
"span": {
|
||||
"uri": "file://godef/a/random.go",
|
||||
"start": {
|
||||
"line": 16,
|
||||
"line": 24,
|
||||
"column": 15,
|
||||
"offset": 248
|
||||
"offset": 413
|
||||
},
|
||||
"end": {
|
||||
"line": 16,
|
||||
"line": 24,
|
||||
"column": 18,
|
||||
"offset": 251
|
||||
"offset": 416
|
||||
}
|
||||
},
|
||||
"description": "```go\nfunc (*Pos).Sum() int\n```\n\n[`(a.Pos).Sum` on pkg.go.dev](https://pkg.go.dev/golang.org/x/tools/internal/lsp/godef/a#Pos.Sum)"
|
||||
@ -84,3 +84,30 @@ var y int
|
||||
```go
|
||||
var y int
|
||||
```
|
||||
-- TypField-definition --
|
||||
godef/a/random.go:17:18-23: defined here as ```go
|
||||
field field string
|
||||
```
|
||||
|
||||
-- TypField-definition-json --
|
||||
{
|
||||
"span": {
|
||||
"uri": "file://godef/a/random.go",
|
||||
"start": {
|
||||
"line": 17,
|
||||
"column": 18,
|
||||
"offset": 292
|
||||
},
|
||||
"end": {
|
||||
"line": 17,
|
||||
"column": 23,
|
||||
"offset": 297
|
||||
}
|
||||
},
|
||||
"description": "```go\nfield field string\n```"
|
||||
}
|
||||
|
||||
-- TypField-hover --
|
||||
```go
|
||||
field field string
|
||||
```
|
||||
|
@ -1,3 +1,20 @@
|
||||
-- suggestedfix_var_10_6 --
|
||||
package undeclared
|
||||
|
||||
func m() int {
|
||||
z, _ := 1+y, 11 //@diag("y", "compiler", "undeclared name: y", "error"),suggestedfix("y", "quickfix")
|
||||
if 100 < 90 {
|
||||
z = 1
|
||||
} else if 100 > n+2 { //@diag("n", "compiler", "undeclared name: n", "error"),suggestedfix("n", "quickfix")
|
||||
z = 4
|
||||
}
|
||||
i :=
|
||||
for i < 200 { //@diag("i", "compiler", "undeclared name: i", "error"),suggestedfix("i", "quickfix")
|
||||
}
|
||||
r() //@diag("r", "compiler", "undeclared name: r", "error")
|
||||
return z
|
||||
}
|
||||
|
||||
-- suggestedfix_var_4_12 --
|
||||
package undeclared
|
||||
|
||||
@ -32,20 +49,3 @@ func m() int {
|
||||
return z
|
||||
}
|
||||
|
||||
-- suggestedfix_var_10_6 --
|
||||
package undeclared
|
||||
|
||||
func m() int {
|
||||
z, _ := 1+y, 11 //@diag("y", "compiler", "undeclared name: y", "error"),suggestedfix("y", "quickfix")
|
||||
if 100 < 90 {
|
||||
z = 1
|
||||
} else if 100 > n+2 { //@diag("n", "compiler", "undeclared name: n", "error"),suggestedfix("n", "quickfix")
|
||||
z = 4
|
||||
}
|
||||
i :=
|
||||
for i < 200 { //@diag("i", "compiler", "undeclared name: i", "error"),suggestedfix("i", "quickfix")
|
||||
}
|
||||
r() //@diag("r", "compiler", "undeclared name: r", "error")
|
||||
return z
|
||||
}
|
||||
|
||||
|
2
internal/lsp/testdata/lsp/summary.txt.golden
vendored
2
internal/lsp/testdata/lsp/summary.txt.golden
vendored
@ -12,7 +12,7 @@ FoldingRangesCount = 2
|
||||
FormatCount = 6
|
||||
ImportCount = 7
|
||||
SuggestedFixCount = 6
|
||||
DefinitionsCount = 45
|
||||
DefinitionsCount = 46
|
||||
TypeDefinitionsCount = 2
|
||||
HighlightsCount = 52
|
||||
ReferencesCount = 11
|
||||
|
Loading…
Reference in New Issue
Block a user