Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Type hints on hover are incorrect when omitting the value while ranging over a slice #1242

Closed
m90 opened this issue Sep 23, 2017 · 6 comments
Labels

Comments

@m90
Copy link
Contributor

m90 commented Sep 23, 2017

Considering the following program:

package main

import (
	"fmt"
)

func main() {
	s := []string{"a", "b", "c"}
	for index, char := range s {
		fmt.Println(index, char)
	}
	for index := range s {
		fmt.Println(index)
	}
}

with the rather obvious output of

0 a
1 b
2 c
0
1
2

I found a bug in the type hints that will be displayed when hovering over an expression in the editor.

Using 0.6.65, running Go 1.9 I will see the correct hint (int) when hovering over index in the first loop of the example:

bildschirmfoto vom 2017-09-23 13-20-18

when hovering over the second index, I will incorrectly be told that this is a bool (when it is still an int):

bildschirmfoto vom 2017-09-23 13-20-24

@ramya-rao-a
Copy link
Contributor

@zmb3 Thoughts? I see the same when using gogetdoc as well.

@zmb3
Copy link
Contributor

zmb3 commented Sep 25, 2017

Interesting. I will look into it!

@zmb3
Copy link
Contributor

zmb3 commented Sep 25, 2017

@ramya-rao-a can we confirm vs-code is invoking gogetdoc with the correct offset? I'm not able to reproduce at the command line:

~/src/github.com/zmb3/doctest
❯ cat main.go
package main

import (
	"fmt"
)

func main() {
	s := []string{"a", "b", "c"}
	for index, char := range s {
		fmt.Println(index, char)
	}
	for index := range s {
		fmt.Println(index)
	}
}

~/src/github.com/zmb3/doctest
❯ gogetdoc -pos "main.go:#84"
import "github.com/zmb3/doctest"

var index int

Undocumented.


~/src/github.com/zmb3/doctest
❯ gogetdoc -pos "main.go:#144"
import "github.com/zmb3/doctest"

var index int

Undocumented.

@m90
Copy link
Contributor Author

m90 commented Sep 25, 2017

@zmb3 I just looked into this and it seems that the bug stems from the fact that the extension is falling back to godef as it is set to go.docsTool: godoc. If I use gogetdoc it will show me the correct type, bot in the extension as well as on the command line (which is great).

@ramya-rao-a this probably means it is still an upstream bug, but in godef. What's the reason for godoc as a default?

@m90
Copy link
Contributor Author

m90 commented Sep 25, 2017

Yes, I can confirm that godef prints incorrect information in this case:

frederik@fr-xps:~/projects/go/src/github.com/m90/test$ cat main.go 
package main

import (
	"fmt"
)

func main() {
	s := []string{"a", "b", "c"}
	for index, char := range s {
		fmt.Println(index, char)
	}
	for index := range s {
		fmt.Println(index)
	}
}

frederik@fr-xps:~/projects/go/src/github.com/m90/test$ godef -o 144 -f main.go -t
main.go:12:6
index bool

@ramya-rao-a
Copy link
Contributor

ramya-rao-a commented Sep 25, 2017

Sorry about that @zmb3, I was so sure I had changed the setting to use gogetdoc when testing :(

@m90 godef gives the location and signature of the definition. We pass this to godoc to get further doc info.

Please open an issue in the godef repo so that @rogpeppe can take a look there

#1025 is tracking the feature request to make gogetdoc the default option as there are quite a few cases where the godef+godoc combo doesnt give the right results

Closing this issue for now as using gogetdoc gives you the right results

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants