godef
godef copied to clipboard
Support showing variable initialization values when printing types
It's quite useful to be able to see the value of a const/var when godef is used to show hovers. It's currently only shown for consts.
The case for also doing this for variables is that consts in Go don't support any type, if you need some "constant" value that isn't scalar, e.g. a slice, you often see a global variable used instead.
Screenshot from VS Code

Example
$ godef -t -f foo.go foo
foo.go:5:7
const foo string = "foo"
$ godef -t -f foo.go baz
foo.go:8:5
baz string
Sample Code
package main
import "fmt"
const foo = "foo"
const Bar = "bar"
var baz = "baz"
var Qux = "Qux"
func main() {
fmt.Println(foo, Bar, baz, Qux)
}
Originally reported at: https://github.com/Microsoft/vscode-go/issues/2146
cc @ramya-rao-a