Skip to content

Support showing variable initialization values when printing types #97

@segevfiner

Description

@segevfiner

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: microsoft/vscode-go#2146

cc @ramya-rao-a

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions