godef icon indicating copy to clipboard operation
godef copied to clipboard

Support showing variable initialization values when printing types

Open segevfiner opened this issue 7 years ago • 0 comments

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

image

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

segevfiner avatar Nov 27 '18 18:11 segevfiner