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.
internal/lsp/source: show an original declaration and a value for var…
…iables and constants This change improves the hover information for variables and constants by showing both an original declaration and a value. The value is shown as an inline comment. Two kinds of declarations are currently supported: 1. Basic literals of type int: * var x int64 = 0xff // 255 * const x untyped int = 0b11 // 3 * const x uint = 1_000_000 // 1000000 2. Binary expressions with bitwise operators: * var x uint = 0b10 | 0b1 // 3 * const x untyped int = 10 << 20 // 10485760 This change also removes TestHoverIntLiteral in favor of marker tests Fixes golang/go#47453
- Loading branch information
1 parent
939c2c0
commit e7834b8
Showing
6 changed files
with
205 additions
and
61 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
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package a | ||
|
||
import "time" | ||
|
||
var globalVar = 0xfffff3 | ||
|
||
func _() { | ||
var hex, bin, test = 0xe34e, 0b1001001, time.Hour | ||
|
||
var ( | ||
// Number with underscore | ||
numberWithUnderscore = 10_000_000_000 | ||
octal int64 = 0o666 | ||
bitwiseShift = 10 << 20 | ||
bitwiseXor = 0b111 ^ 0b101 | ||
// No original value | ||
str = "string" | ||
) | ||
|
||
_ = globalVar //@mark(globalVar, "globalVar"),hoverdef("globalVar", globalVar) | ||
_ = hex //@mark(hexVar, "hex"),hoverdef("hex", hexVar) | ||
_ = bin //@mark(binVar, "bin"),hoverdef("bin", binVar) | ||
_ = numberWithUnderscore //@mark(numberWithUnderscoreVar, "numberWithUnderscore"),hoverdef("numberWithUnderscore", numberWithUnderscoreVar) | ||
_ = octal //@mark(octalVar, "octal"),hoverdef("octal", octalVar) | ||
_ = bitwiseShift //@mark(bitwiseShiftVar, "bitwiseShift"),hoverdef("bitwiseShift", bitwiseShiftVar) | ||
_ = bitwiseXor //@mark(bitwiseXorVar, "bitwiseXor"),hoverdef("bitwiseXor", bitwiseXorVar) | ||
_ = str //@mark(strVar, "str"),hoverdef("str", strVar) | ||
} | ||
|
||
const globalConst = 0xfffff3 | ||
|
||
func _() { | ||
const hex, bin = 0xe34e, 0b1001001 | ||
|
||
const ( | ||
numberWithUnderscore int64 = 10_000_000_000 | ||
// Comment for test | ||
octal = 0o777 | ||
bitwise = 8 >> 1 | ||
str = "string" | ||
) | ||
|
||
_ = hex //@mark(hexConst, "hex"),hoverdef("hex", hexConst) | ||
_ = bin //@mark(binConst, "bin"),hoverdef("bin", binConst) | ||
_ = numberWithUnderscore //@mark(numberWithUnderscoreConst, "numberWithUnderscore"),hoverdef("numberWithUnderscore", numberWithUnderscoreConst) | ||
_ = globalConst //@mark(globalConst, "globalConst"),hoverdef("globalConst", globalConst) | ||
_ = octal //@mark(octalConst, "octal"),hoverdef("octal", octalConst) | ||
_ = bitwise //@mark(bitwiseConst, "bitwise"),hoverdef("bitwise", bitwiseConst) | ||
_ = str //@mark(strConst, "str"),hoverdef("str", strConst) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
-- globalVar-hoverdef -- | ||
```go | ||
var globalVar int = 0xfffff3 // 16777203 | ||
``` | ||
-- hexVar-hoverdef -- | ||
```go | ||
var hex int = 0xe34e // 58190 | ||
``` | ||
-- binVar-hoverdef -- | ||
```go | ||
var bin int = 0b1001001 // 73 | ||
``` | ||
-- numberWithUnderscoreVar-hoverdef -- | ||
```go | ||
var numberWithUnderscore int = 10_000_000_000 // 10000000000 | ||
``` | ||
|
||
Number with underscore | ||
-- octalVar-hoverdef -- | ||
```go | ||
var octal int64 = 0o666 // 438 | ||
``` | ||
-- bitwiseShiftVar-hoverdef -- | ||
```go | ||
var bitwiseShift int = 10 << 20 // 10485760 | ||
``` | ||
-- bitwiseXorVar-hoverdef -- | ||
```go | ||
var bitwiseXor int = 0b111 ^ 0b101 // 2 | ||
``` | ||
-- strVar-hoverdef -- | ||
```go | ||
var str string | ||
``` | ||
|
||
No original value | ||
-- globalConst-hoverdef -- | ||
```go | ||
const globalConst untyped int = 0xfffff3 // 16777203 | ||
``` | ||
-- 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 | ||
``` | ||
|
||
Comment for test | ||
-- bitwiseConst-hoverdef -- | ||
```go | ||
const bitwise untyped int = 8 >> 1 // 4 | ||
``` | ||
-- strConst-hoverdef -- | ||
```go | ||
const str untyped string = "string" | ||
``` |
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