forked from golang/tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gopls/internal/lsp/source: show both the original declaration and the…
… value of constants in hover This change improves the hover information for constants by showing both the original declaration and the value. The value is displayed as an inline comment. If the original declaration and the value are the same, there will be no inline comment. Examples: ```go const duration time.Duration = 15*time.Minute + 10*time.Second // 15m10s const octal untyped int = 0o777 // 511 const expr untyped int = 2 << (0b111&0b101 - 2) // 16 const boolean untyped bool = (55 - 3) == (26 * 2) // true const dec untyped int = 500 ``` Other changes: * Calls to `objectString` that format methods or variables have been replaced with `types.ObjectString`. * The logic of inferred signature formatting has been extracted from `objectString` to a new function `inferredSignatureString`. * Remove unused function `extractFieldList`. Fixes golang/go#47453
- Loading branch information
1 parent
13850b3
commit a7fbd1e
Showing
6 changed files
with
184 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,66 @@ | ||
package a | ||
|
||
import "time" | ||
import ( | ||
"math" | ||
"time" | ||
) | ||
|
||
// dur is a constant of type time.Duration. | ||
const dur = 15*time.Minute + 10*time.Second + 350*time.Millisecond //@dur,hoverdef("dur", dur) | ||
|
||
// Numbers. | ||
func _() { | ||
const hex, bin = 0xe34e, 0b1001001 | ||
|
||
const ( | ||
// no inline comment | ||
decimal = 153 | ||
|
||
numberWithUnderscore int64 = 10_000_000_000 | ||
octal = 0o777 | ||
expr = 2 << (0b111&0b101 - 2) | ||
boolean = (55 - 3) == (26 * 2) | ||
) | ||
|
||
_ = decimal //@mark(decimalConst, "decimal"),hoverdef("decimal", decimalConst) | ||
_ = hex //@mark(hexConst, "hex"),hoverdef("hex", hexConst) | ||
_ = bin //@mark(binConst, "bin"),hoverdef("bin", binConst) | ||
_ = numberWithUnderscore //@mark(numberWithUnderscoreConst, "numberWithUnderscore"),hoverdef("numberWithUnderscore", numberWithUnderscoreConst) | ||
_ = octal //@mark(octalConst, "octal"),hoverdef("octal", octalConst) | ||
_ = expr //@mark(exprConst, "expr"),hoverdef("expr", exprConst) | ||
_ = boolean //@mark(boolConst, "boolean"),hoverdef("boolean", boolConst) | ||
|
||
const ln10 = 2.30258509299404568401799145468436420760110148862877297603332790 | ||
|
||
_ = ln10 //@mark(ln10Const, "ln10"),hoverdef("ln10", ln10Const) | ||
} | ||
|
||
// Iota. | ||
func _() { | ||
const ( | ||
a = 1 << iota | ||
b | ||
) | ||
|
||
_ = a //@mark(aIota, "a"),hoverdef("a", aIota) | ||
_ = b //@mark(bIota, "b"),hoverdef("b", bIota) | ||
} | ||
|
||
// Strings. | ||
func _() { | ||
const ( | ||
str = "hello" + " " + "world" | ||
longStr = `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur eget ipsum non nunc | ||
molestie mattis id quis augue. Mauris dictum tincidunt ipsum, in auctor arcu congue eu. | ||
Morbi hendrerit fringilla libero commodo varius. Vestibulum in enim rutrum, rutrum tellus | ||
aliquet, luctus enim. Nunc sem ex, consectetur id porta nec, placerat vel urna.` | ||
) | ||
|
||
_ = str //@mark(strConst, "str"),hoverdef("str", strConst) | ||
_ = longStr //@mark(longStrConst, "longStr"),hoverdef("longStr", longStrConst) | ||
} | ||
|
||
// Constants from other packages. | ||
func _() { | ||
_ = math.MaxFloat32 //@mark(maxFloat32Const, "MaxFloat32"),hoverdef("MaxFloat32", maxFloat32Const) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,67 @@ | ||
-- dur-hoverdef -- | ||
```go | ||
const dur time.Duration = 910350000000 // 15m10.35s | ||
const dur time.Duration = 15*time.Minute + 10*time.Second + 350*time.Millisecond // 15m10.35s | ||
``` | ||
|
||
dur is a constant of type time.Duration. | ||
|
||
-- decimalConst-hoverdef -- | ||
```go | ||
const decimal untyped int = 153 | ||
``` | ||
|
||
no inline comment | ||
|
||
-- hexConst-hoverdef -- | ||
```go | ||
const hex untyped int = 0xe34e // 58190 | ||
``` | ||
-- binConst-hoverdef -- | ||
```go | ||
const bin untyped int = 0b1001001 // 73 | ||
``` | ||
-- numberWithUnderscoreConst-hoverdef -- | ||
```go | ||
const numberWithUnderscore int64 = 10_000_000_000 // 10000000000 | ||
``` | ||
-- octalConst-hoverdef -- | ||
```go | ||
const octal untyped int = 0o777 // 511 | ||
``` | ||
-- exprConst-hoverdef -- | ||
```go | ||
const expr untyped int = 2 << (0b111&0b101 - 2) // 16 | ||
``` | ||
-- boolConst-hoverdef -- | ||
```go | ||
const boolean untyped bool = (55 - 3) == (26 * 2) // true | ||
``` | ||
-- ln10Const-hoverdef -- | ||
```go | ||
const ln10 untyped float = 2.30258509299404568401799145468436420760110148862877297603332790 // 2.30259 | ||
``` | ||
-- aIota-hoverdef -- | ||
```go | ||
const a untyped int = 1 << iota // 1 | ||
``` | ||
-- bIota-hoverdef -- | ||
```go | ||
const b untyped int = 2 | ||
``` | ||
-- strConst-hoverdef -- | ||
```go | ||
const str untyped string = "hello world" | ||
``` | ||
-- longStrConst-hoverdef -- | ||
```go | ||
const longStr untyped string = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur e... | ||
``` | ||
-- maxFloat32Const-hoverdef -- | ||
```go | ||
const math.MaxFloat32 untyped float = 0x1p127 * (1 + (1 - 0x1p-23)) // 3.40282e+38 | ||
``` | ||
|
||
Floating-point limit values. | ||
|
||
|
||
[`math.MaxFloat32` on pkg.go.dev](https://pkg.go.dev/math#MaxFloat32) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters