golang.org/x/tools/gopls@v0.15.3/internal/test/marker/testdata/hover/const.txt (about) 1 This test checks hovering over constants. 2 3 Requires go1.19+ for the new go/doc/comment package. 4 5 -- flags -- 6 -min_go=go1.19 7 8 -- go.mod -- 9 module mod.com 10 11 go 1.17 12 13 -- c.go -- 14 package c 15 16 import ( 17 "math" 18 "time" 19 ) 20 21 const X = 0 //@hover("X", "X", bX) 22 23 // dur is a constant of type time.Duration. 24 const dur = 15*time.Minute + 10*time.Second + 350*time.Millisecond //@hover("dur", "dur", dur) 25 26 // MaxFloat32 is used in another package. 27 const MaxFloat32 = 0x1p127 * (1 + (1 - 0x1p-23)) 28 29 // Numbers. 30 func _() { 31 const hex, bin = 0xe34e, 0b1001001 32 33 const ( 34 // no inline comment 35 decimal = 153 36 37 numberWithUnderscore int64 = 10_000_000_000 38 octal = 0o777 39 expr = 2 << (0b111&0b101 - 2) 40 boolean = (55 - 3) == (26 * 2) 41 ) 42 43 _ = decimal //@hover("decimal", "decimal", decimalConst) 44 _ = hex //@hover("hex", "hex", hexConst) 45 _ = bin //@hover("bin", "bin", binConst) 46 _ = numberWithUnderscore //@hover("numberWithUnderscore", "numberWithUnderscore", numberWithUnderscoreConst) 47 _ = octal //@hover("octal", "octal", octalConst) 48 _ = expr //@hover("expr", "expr", exprConst) 49 _ = boolean //@hover("boolean", "boolean", boolConst) 50 51 const ln10 = 2.30258509299404568401799145468436420760110148862877297603332790 52 53 _ = ln10 //@hover("ln10", "ln10", ln10Const) 54 } 55 56 // Iota. 57 func _() { 58 const ( 59 a = 1 << iota 60 b 61 ) 62 63 _ = a //@hover("a", "a", aIota) 64 _ = b //@hover("b", "b", bIota) 65 } 66 67 // Strings. 68 func _() { 69 const ( 70 str = "hello" + " " + "world" 71 longStr = `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur eget ipsum non nunc 72 molestie mattis id quis augue. Mauris dictum tincidunt ipsum, in auctor arcu congue eu. 73 Morbi hendrerit fringilla libero commodo varius. Vestibulum in enim rutrum, rutrum tellus 74 aliquet, luctus enim. Nunc sem ex, consectetur id porta nec, placerat vel urna.` 75 ) 76 77 _ = str //@hover("str", "str", strConst) 78 _ = longStr //@hover("longStr", "longStr", longStrConst) 79 } 80 81 // Constants from other packages. 82 func _() { 83 _ = math.Log2E //@hover("Log2E", "Log2E", log2eConst) 84 } 85 86 -- @bX -- 87 ```go 88 const X untyped int = 0 89 ``` 90 91 @hover("X", "X", bX) 92 93 94 [`c.X` on pkg.go.dev](https://pkg.go.dev/mod.com#X) 95 -- @dur -- 96 ```go 97 const dur time.Duration = 15*time.Minute + 10*time.Second + 350*time.Millisecond // 15m10.35s 98 ``` 99 100 dur is a constant of type time.Duration. 101 -- @decimalConst -- 102 ```go 103 const decimal untyped int = 153 104 ``` 105 106 no inline comment 107 -- @hexConst -- 108 ```go 109 const hex untyped int = 0xe34e // 58190 110 ``` 111 -- @binConst -- 112 ```go 113 const bin untyped int = 0b1001001 // 73 114 ``` 115 -- @numberWithUnderscoreConst -- 116 ```go 117 const numberWithUnderscore int64 = 10_000_000_000 // 10000000000 118 ``` 119 -- @octalConst -- 120 ```go 121 const octal untyped int = 0o777 // 511 122 ``` 123 -- @exprConst -- 124 ```go 125 const expr untyped int = 2 << (0b111&0b101 - 2) // 16 126 ``` 127 -- @boolConst -- 128 ```go 129 const boolean untyped bool = (55 - 3) == (26 * 2) // true 130 ``` 131 -- @ln10Const -- 132 ```go 133 const ln10 untyped float = 2.30258509299404568401799145468436420760110148862877297603332790 // 2.30259 134 ``` 135 -- @aIota -- 136 ```go 137 const a untyped int = 1 << iota // 1 138 ``` 139 -- @bIota -- 140 ```go 141 const b untyped int = 2 142 ``` 143 -- @strConst -- 144 ```go 145 const str untyped string = "hello world" 146 ``` 147 -- @longStrConst -- 148 ```go 149 const longStr untyped string = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur e... 150 ``` 151 -- @log2eConst -- 152 ```go 153 const math.Log2E untyped float = 1 / Ln2 // 1.4427 154 ``` 155 156 Mathematical constants. 157 158 159 [`math.Log2E` on pkg.go.dev](https://pkg.go.dev/math#Log2E)