Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/tools/gopls: CLI column offset broken #52069

Closed
fommil opened this issue Mar 31, 2022 · 2 comments
Closed

x/tools/gopls: CLI column offset broken #52069

fommil opened this issue Mar 31, 2022 · 2 comments
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@fommil
Copy link

fommil commented Mar 31, 2022

gopls version

latest as of today

Build info
----------
golang.org/x/tools/gopls v0.8.1
    golang.org/x/tools/gopls@v0.8.1 h1:q5nDpRopYrnF4DN/1o8ZQ7Oar4Yd4I5OtGMx5RyV2/8=
    github.com/BurntSushi/toml@v1.0.0 h1:dtDWrepsVPfW9H/4y7dDgFc2MBUSeJhlaDtK13CxFlU=
    github.com/google/go-cmp@v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
    github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
    golang.org/x/mod@v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 h1:kQgndtyPBW/JIYERgdxfwMYh3AVStj88WQTlNDi2a+o=
    golang.org/x/sync@v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
    golang.org/x/sys@v0.0.0-20220209214540-3681064d5158 h1:rm+CHSpPEEW2IsXUib1ThaHIjuBVZjxNgSKmBLFfD4c=
    golang.org/x/text@v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
    golang.org/x/tools@v0.1.10-0.20220315142906-0c66750444e6 h1:AOqgMGxa5hFduIlFkKEX87HoRPO9wjyfhqf1yqwybeg=
    golang.org/x/xerrors@v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
    honnef.co/go/tools@v0.2.2 h1:MNh1AVMyVX23VUHE2O27jm6lNj3vjO5DexS4A1xvnzk=
    mvdan.cc/gofumpt@v0.3.0 h1:kTojdZo9AcEYbQYhGuLf/zszYthRdhDNDUi2JKTxas4=
    mvdan.cc/xurls/v2@v2.4.0 h1:tzxjVAj+wSBmDcF6zBB7/myTy3gX9xvi8Tyr28AuQgc=
go: go1.18

What did you do?

I am using the command line interface (I hope to replace my workflow's use of godef and gocode eventually with gopls).

I have some code that looks like this

counts := map[string]map[Foo]int64

and I wish to get the definition at the line/column position at Foo. Ignoring the row offset, I would use a column offset of 26, 27 or 28.

What did you expect to see?

Same as godef, the object definition for Foo

What did you see instead?

gopls definition picks up the int64, returning

/usr/lib/go/src/builtin/builtin.go:52:6-11: defined here as type int64 int64 ...

If I use a column value 6 characters less than it should be (could be coincidence but that's the length of the identifier counts that my line starts with, or both the map identifiers) of 20, 21 or 22 then I see what I want.

Somewhat related: gopls implementation, references and highlight all seem to be affected by the same problem.

@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Mar 31, 2022
@gopherbot gopherbot added this to the Unreleased milestone Mar 31, 2022
@findleyr
Copy link
Contributor

I can't reproduce this -- it works as expected for me with the character offset 27, 28, or 29 (off by one from your example due to the leading tab).

type Foo struct{}

func _() {
	counts := map[string]map[Foo]int64{}
}

Did you save your file? If so, can you provide a minimal full file that I can use to test?

@hyangah hyangah added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Mar 31, 2022
@fommil
Copy link
Author

fommil commented Mar 31, 2022

when you said "the leading tab"... that made me realise that the file is using TAB on disk but exposed as spaces in Emacs' visual column count 🤦🏻‍♂️

The reason it works for godef is that the call to get the offset counts the correct number of characters into the file.

Thank you for the prompt answer! I will likely be creating some feature requests that allow me to replace gocode next 😄

@fommil fommil closed this as completed Mar 31, 2022
@golang golang locked and limited conversation to collaborators Mar 31, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants