mirror of
https://github.com/golang/go
synced 2024-11-05 11:36:10 -07:00
internal/lsp: show comments for grouped variable declarations
Fixes golang/go#36139 Change-Id: I8aaf1a5d65b8d66ea7bb350439cc960c7505307d Reviewed-on: https://go-review.googlesource.com/c/tools/+/211637 Run-TryBot: Rebecca Stambler <rstambler@golang.org> Reviewed-by: Heschi Kreinick <heschi@google.com>
This commit is contained in:
parent
61f5e7d299
commit
61483d104a
@ -212,13 +212,16 @@ func formatGenDecl(node *ast.GenDecl, obj types.Object, typ types.Type) (*HoverI
|
||||
|
||||
func formatVar(node ast.Spec, obj types.Object, decl *ast.GenDecl) *HoverInformation {
|
||||
var fieldList *ast.FieldList
|
||||
if spec, ok := node.(*ast.TypeSpec); ok {
|
||||
switch spec := node.(type) {
|
||||
case *ast.TypeSpec:
|
||||
switch t := spec.Type.(type) {
|
||||
case *ast.StructType:
|
||||
fieldList = t.Fields
|
||||
case *ast.InterfaceType:
|
||||
fieldList = t.Methods
|
||||
}
|
||||
case *ast.ValueSpec:
|
||||
return &HoverInformation{source: obj, comment: spec.Doc}
|
||||
}
|
||||
// If we have a struct or interface declaration,
|
||||
// we need to match the object to the corresponding field or method.
|
||||
|
5
internal/lsp/testdata/godef/a/a.go
vendored
5
internal/lsp/testdata/godef/a/a.go
vendored
@ -8,6 +8,11 @@ import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
var (
|
||||
// x is a variable.
|
||||
x string //@x,hover("x", x)
|
||||
)
|
||||
|
||||
type A string //@A
|
||||
|
||||
func AStuff() { //@AStuff
|
||||
|
16
internal/lsp/testdata/godef/a/a.go.golden
vendored
16
internal/lsp/testdata/godef/a/a.go.golden
vendored
@ -75,7 +75,7 @@ func Random2(y int) int
|
||||
func Random2(y int) int
|
||||
```
|
||||
-- err-definition --
|
||||
godef/a/a.go:18:6-9: defined here as ```go
|
||||
godef/a/a.go:23:6-9: defined here as ```go
|
||||
var err error
|
||||
```
|
||||
-- err-definition-json --
|
||||
@ -83,14 +83,14 @@ var err error
|
||||
"span": {
|
||||
"uri": "file://godef/a/a.go",
|
||||
"start": {
|
||||
"line": 18,
|
||||
"line": 23,
|
||||
"column": 6,
|
||||
"offset": 228
|
||||
"offset": 287
|
||||
},
|
||||
"end": {
|
||||
"line": 18,
|
||||
"line": 23,
|
||||
"column": 9,
|
||||
"offset": 231
|
||||
"offset": 290
|
||||
}
|
||||
},
|
||||
"description": "```go\nvar err error\n```"
|
||||
@ -112,3 +112,9 @@ func(t Type, size ...IntegerType) Type
|
||||
```go
|
||||
string
|
||||
```
|
||||
-- x-hover --
|
||||
x is a variable\.
|
||||
|
||||
```go
|
||||
var x string
|
||||
```
|
||||
|
20
internal/lsp/testdata/godef/b/b.go.golden
vendored
20
internal/lsp/testdata/godef/b/b.go.golden
vendored
@ -1,5 +1,5 @@
|
||||
-- A-definition --
|
||||
godef/a/a.go:11:6-7: defined here as [`a.A` on pkg.go.dev](https://pkg.go.dev/golang.org/x/tools/internal/lsp/godef/a#A)
|
||||
godef/a/a.go:16:6-7: defined here as [`a.A` on pkg.go.dev](https://pkg.go.dev/golang.org/x/tools/internal/lsp/godef/a#A)
|
||||
|
||||
```go
|
||||
A string //@A
|
||||
@ -10,14 +10,14 @@ A string //@A
|
||||
"span": {
|
||||
"uri": "file://godef/a/a.go",
|
||||
"start": {
|
||||
"line": 11,
|
||||
"line": 16,
|
||||
"column": 6,
|
||||
"offset": 100
|
||||
"offset": 159
|
||||
},
|
||||
"end": {
|
||||
"line": 11,
|
||||
"line": 16,
|
||||
"column": 7,
|
||||
"offset": 101
|
||||
"offset": 160
|
||||
}
|
||||
},
|
||||
"description": "[`a.A` on pkg.go.dev](https://pkg.go.dev/golang.org/x/tools/internal/lsp/godef/a#A)\n\n```go\nA string //@A\n\n```"
|
||||
@ -61,7 +61,7 @@ package a ("golang.org/x/tools/internal/lsp/godef/a")
|
||||
package a ("golang.org/x/tools/internal/lsp/godef/a")
|
||||
```
|
||||
-- AStuff-definition --
|
||||
godef/a/a.go:13:6-12: defined here as [`a.AStuff` on pkg.go.dev](https://pkg.go.dev/golang.org/x/tools/internal/lsp/godef/a#AStuff)
|
||||
godef/a/a.go:18:6-12: defined here as [`a.AStuff` on pkg.go.dev](https://pkg.go.dev/golang.org/x/tools/internal/lsp/godef/a#AStuff)
|
||||
|
||||
```go
|
||||
func a.AStuff()
|
||||
@ -71,14 +71,14 @@ func a.AStuff()
|
||||
"span": {
|
||||
"uri": "file://godef/a/a.go",
|
||||
"start": {
|
||||
"line": 13,
|
||||
"line": 18,
|
||||
"column": 6,
|
||||
"offset": 120
|
||||
"offset": 179
|
||||
},
|
||||
"end": {
|
||||
"line": 13,
|
||||
"line": 18,
|
||||
"column": 12,
|
||||
"offset": 126
|
||||
"offset": 185
|
||||
}
|
||||
},
|
||||
"description": "[`a.AStuff` on pkg.go.dev](https://pkg.go.dev/golang.org/x/tools/internal/lsp/godef/a#AStuff)\n\n```go\nfunc a.AStuff()\n```"
|
||||
|
2
internal/lsp/testdata/summary.txt.golden
vendored
2
internal/lsp/testdata/summary.txt.golden
vendored
@ -11,7 +11,7 @@ FoldingRangesCount = 2
|
||||
FormatCount = 6
|
||||
ImportCount = 7
|
||||
SuggestedFixCount = 1
|
||||
DefinitionsCount = 42
|
||||
DefinitionsCount = 43
|
||||
TypeDefinitionsCount = 2
|
||||
HighlightsCount = 44
|
||||
ReferencesCount = 7
|
||||
|
Loading…
Reference in New Issue
Block a user