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

Can't use 'go to definition' when cursor is at the end of a word #891

Closed
roblourens opened this issue Mar 28, 2017 · 13 comments
Closed

Can't use 'go to definition' when cursor is at the end of a word #891

roblourens opened this issue Mar 28, 2017 · 13 comments

Comments

@roblourens
Copy link
Member

  • Cursor at |: fmt.Println|(stringutil.Reverse("!selpmaxe oG ,olleH"))
  • Press F12
  • "No definition found for Println"
  • Cursor in the middle of the word, it works
@ramya-rao-a
Copy link
Contributor

@roblourens Can you check what is your setting value for go.docsTool ? or if you are using the language server?

@yageek
Copy link
Contributor

yageek commented Apr 2, 2017

I have the same error. Switching to gogetdoc did not solve it.

@ramya-rao-a
Copy link
Contributor

@yageek Do you have the language server enabled?

I am able to repro when

  • the language server is enabled OR
  • the language server is disabled and go.docsTool is set to gogetdoc

Not when language server is disabled and go.docsTool is set to godoc

@yageek
Copy link
Contributor

yageek commented Apr 2, 2017

My bad. It does not seems related to the cursor position. In fact, no package from the standard library is suggested, so it is not possible to jump to the declaration of the function.

@ramya-rao-a
Copy link
Contributor

@yageek Well, that is much more serious.

I did end up in such a scenario once, getting the latest for the tools solved it for me.

Can you try running the command Go: Install Tools ?

@yageek
Copy link
Contributor

yageek commented Apr 3, 2017

On my side, the issue was related to a mis configured GOROOT env var sur to an error within goenv.
Now everything is fine.

@ramya-rao-a
Copy link
Contributor

@zmb3 gogetdoc returns no pos in such cases. Can you take a look and see if this can be fixed in gogetdoc ?

@zmb3
Copy link
Contributor

zmb3 commented Apr 8, 2017

Lots of the go tools behave in this way (gogetdoc, guru, gorename, etc)..

I believe the cause is that for:

fmt.Println("hello")
           |

The cursor is positioned at byte 11, and the Println identifier ends at byte 10.

There are two workarounds that have worked well for me:

  1. Optionally step back a byte if Guru fails.

  2. If your editor supports it, you can ask for the range covered by the current word (treating ( as a valid word character), and then averaging it to get somewhere in the middle.

For example, if your editor allows it, you can tell it to include ( in the list of "word characters" and then ask for the current word position. You'd get something like: 0 > 11, and you average those values to get 5.

I personally prefer option 2.

@ramya-rao-a
Copy link
Contributor

Rename operation works in this case.

Find All References and Go to/Peek Definition features like you said don't though.

This is a corner case, so there is no rush.

Will keep it open if anyone wants to take a shot at sending the updated offset to the tools

@bconway
Copy link

bconway commented May 29, 2018

I ran into this and assumed that gogetdoc was totally busted. I think one common use case not mentioned here thus far is for people whose muscle memory is to double-click a method to highlight it, and then hit F12. Since that places the cursor at the end of the method, it hits this bug, but it's also how I've used IDEs since forever. Maybe I'm the only one? Would love a fix either way!

ramya-rao-a added a commit that referenced this issue May 29, 2018
@ramya-rao-a
Copy link
Contributor

@dauntlesscarp That's a good scenario that pulls us out of the corner case. I have pushed a fix which will be available in the next update.

@bconway
Copy link

bconway commented May 29, 2018

Much appreciated!

@ramya-rao-a
Copy link
Contributor

This bug fix is now out in the latest update to the Go extension (0.6.81)

@ramya-rao-a ramya-rao-a added this to the 0.6.81 milestone Jun 4, 2018
@vscodebot vscodebot bot locked and limited conversation to collaborators Jul 13, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants