1
0
mirror of https://github.com/golang/go synced 2024-11-18 08:54:45 -07:00

internal/lsp: fix docs on hover for var/const blocks

The priorities for which comment to show should be 1) documentation
directly above the var/const, 2) documentation for the var/const block,
3) line comments.

See https://github.com/microsoft/vscode-go/issues/3240.

Change-Id: Ie136f0f25ac8208147070682bb1f3a663d6da25f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/234101
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
This commit is contained in:
Rebecca Stambler 2020-05-14 17:16:05 -04:00
parent 259583f2d8
commit 39aadb5b76
5 changed files with 38 additions and 18 deletions

View File

@ -306,9 +306,9 @@ func formatVar(node ast.Spec, obj types.Object, decl *ast.GenDecl) *HoverInforma
fieldList = t.Methods
}
case *ast.ValueSpec:
comment := decl.Doc
comment := spec.Doc
if comment == nil {
comment = spec.Doc
comment = decl.Doc
}
if comment == nil {
comment = spec.Comment

View File

@ -12,6 +12,14 @@ var (
x string //@x,hover("x", x)
)
// Constant block. When I hover on h, I should see this comment.
const (
// When I hover on g, I should see this comment.
g = 1 //@g,hover("g", g)
h = 2 //@h,hover("h", h)
)
// z is a variable too.
var z string //@z,hover("z", z)

View File

@ -81,7 +81,7 @@ func Random2(y int) int
-- aPackage-hover --
Package a is a package for testing go to definition\.
-- err-definition --
godef/a/a.go:25:6-9: defined here as ```go
godef/a/a.go:33:6-9: defined here as ```go
var err error
```
@ -91,14 +91,14 @@ var err error
"span": {
"uri": "file://godef/a/a.go",
"start": {
"line": 25,
"line": 33,
"column": 6,
"offset": 418
"offset": 597
},
"end": {
"line": 25,
"line": 33,
"column": 9,
"offset": 421
"offset": 600
}
},
"description": "```go\nvar err error\n```\n\n\\@err"
@ -110,6 +110,18 @@ var err error
```go
var err error
```
-- g-hover --
When I hover on g, I should see this comment\.
```go
const g untyped int = 1
```
-- h-hover --
Constant block\.
```go
const h untyped int = 2
```
-- make-hover --
The make built\-in function allocates and initializes an object of type slice, map, or chan \(only\)\.

View File

@ -29,7 +29,7 @@ package a ("golang.org/x/tools/internal/lsp/godef/a")
package a ("golang.org/x/tools/internal/lsp/godef/a")
```
-- AString-definition --
godef/a/a.go:18:6-7: defined here as ```go
godef/a/a.go:26:6-7: defined here as ```go
A string //@mark(AString, "A")
```
@ -40,14 +40,14 @@ A string //@mark(AString, "A")
"span": {
"uri": "file://godef/a/a.go",
"start": {
"line": 18,
"line": 26,
"column": 6,
"offset": 273
"offset": 452
},
"end": {
"line": 18,
"line": 26,
"column": 7,
"offset": 274
"offset": 453
}
},
"description": "```go\nA string //@mark(AString, \"A\")\n\n```\n\n[`a.A` on pkg.go.dev](https://pkg.go.dev/golang.org/x/tools/internal/lsp/godef/a#A)"
@ -61,7 +61,7 @@ A string //@mark(AString, "A")
```
-- AStuff-definition --
godef/a/a.go:20:6-12: defined here as ```go
godef/a/a.go:28:6-12: defined here as ```go
func a.AStuff()
```
@ -71,14 +71,14 @@ func a.AStuff()
"span": {
"uri": "file://godef/a/a.go",
"start": {
"line": 20,
"line": 28,
"column": 6,
"offset": 310
"offset": 489
},
"end": {
"line": 20,
"line": 28,
"column": 12,
"offset": 316
"offset": 495
}
},
"description": "```go\nfunc a.AStuff()\n```\n\n[`a.AStuff` on pkg.go.dev](https://pkg.go.dev/golang.org/x/tools/internal/lsp/godef/a#AStuff)"

View File

@ -12,7 +12,7 @@ FoldingRangesCount = 2
FormatCount = 6
ImportCount = 8
SuggestedFixCount = 6
DefinitionsCount = 51
DefinitionsCount = 53
TypeDefinitionsCount = 2
HighlightsCount = 52
ReferencesCount = 11