-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Completion returns wrong candidates due to inconsistent file path usage. #2913
Comments
How did you open the file identified in your step 2, vim-go good about using the paths you give it AFAIK. And given that the
It would be helpful if you could provide some clear steps for how to duplicate this in a simple scenario and also if you could provide the LSP debug output by adding |
Hi @bhcleek thanks for the help! I'm starting vim from the current working directory using Log |
Thank you @egravert I think the we'll be able to get to the bottom of this pretty quickly. The screen recording and the lsp debug log will help immensely. The paths being different for the file vs the rootUri is likely an issue that vim-go can resolve. I haven't yet been able to duplicate the completion candidates that you're seeing, but I'll take a thorough look at the log you provided to see if it offers any clues. In the meantime, can remove your |
I can duplicate the completion issue. There's no need for you to test without the |
I don't think there's a solution for this on the vim-go side. GOPATH with a symlink has similar kinds of issues. The best I could do would be to open the Ideally, that wouldn't be necessary, because Vim would be able to expand the path with a symlink in it, but Vim doesn't have an option to be able to do that: expanding file paths always provides the real path. Even if we could handle this particular use case, the community tooling wouldn't support symlinks generally and we'd be left with a variety of related issues. I'll refer you to previous discussions where vim-go users have had questions about symlinks and our answers there (e.g. #2731). I think your best option maybe to work in |
Resolve the module root to the true path. All other path expansions in Vim are the resolved path, so the module root path should also be the resolved path. Fixes fatih#2913
I found an easy solution for this after thinking about it some more and considering the options and the tradeoffs. Thank you for a detailed issue report @egravert ! |
@bhcleek Thank you for the amazing help! |
Hi all
I'm running into an issue where the completion menu in vim shows unexpected results. I enabled completion within my vimrc to show contextual candidates when I press period (see vimrc below).
Unfortunately, the candidates are almost always wrong.
After tracing through
gopls
I was eventually able to track down the issue, but need further assistance on how to best fix it.For context, this is on FreeBSD using zfs for the filesystem. This is relevant due to how the default filesystem is setup. For FreeBSD,
/home
is a symlink to/usr/home
.By tracing gopls, this is what appears to be happening:
Note that workspaceFolders and rootUri are both set to
/home/
Gopls uses this event to initialize its cache. When files are added to the cache, the file URI is tracked, and is based on the rootUri that was provided by this event.
The uri provided now points to
/usr/home
instead.gopls adds the uri to the file's uri list (See here: fileBase.addURI)
While the uri points to the uri of the last change, gopls is hardcoded to only return the URI of the first URI added to the list (see here).
This results in gopls returning the wrong text document when looking for the identifier closest to the cursor, causing the wrong result to be returned.
I see two way to fix this:
For now, I have worked around the issue by hacking gopls to have
URI()
always return the last added uri.What did you do? (required: The issue will be closed when not provided)
fmt.Println("go-vim")
fmt.
What did you expect to happen?
I would expect vim to show the
fmt
package's exported types in the completion window.What happened instead?
Only keywords are show.
Configuration (MUST fill this out):
vim-go version:
v1.23
vimrc
you used to reproduce:vimrc
Vim version (first three lines from
:version
):Go version (
go version
):Go environment
go env
Output:gopls version
gopls version
Output:The text was updated successfully, but these errors were encountered: