-
Notifications
You must be signed in to change notification settings - Fork 18k
x/tools/internal/lsp: support files outside $GOPATH and outside of a module #31168
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
Comments
Workaround
|
@Lekensteyn We can't accept patches posted to issues, but if you have a fix please send a PR or CL per https://golang.org/doc/contribute.html. |
This comment has been minimized.
This comment has been minimized.
This should work correctly as of https://golang.org/cl/183620. Closing. |
This isn't resolved. Editing a file outside of EDIT: Apologies. It works after there's |
Thanks Guy , it can resolve my problem " YouCompleteMe
let g:ycm_server_python_interpreter='/usr/local/bin/python3'
" Note that you can install YCM with both libclang and clangd enabled. In that case clangd will be preferred unless you have the following in your vimrc:
"let g:ycm_use_clangd = 0
let g:ycm_global_ycm_extra_conf = "~/.vim/bundle/YouCompleteMe/.ycm_extra_conf.py"
let g:ycm_language_server =
\ [
\ {
\ 'name': 'gopls',
\ 'cmdline': [ '~/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/go/src/golang.org/x/tools/cmd/gopls/gopls' , "-rpc.trace" ],
\ 'filetypes': [ 'go' ],
\ "project_root_files": [ "go.mod" ]
\ }
\ ]
let g:go_def_mode='~/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/go/src/golang.org/x/tools/cmd/gopls/gopls'
let g:go_info_mode='~/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/go/src/golang.org/x/tools/cmd/gopls/gopls'
" let g:ycm_log_level = 'debug'
set completeopt=longest,menu |
@relunctance Don't do that. YCM migrated to gopls a while ago. Just use |
@bstaletic Thanks , I have remove |
What version of Go are you using (
go version
)?Originally encountered with 1.12. Reproduced on Arch Linux (x86_64).
What did you do?
Install vim-go (fatih/vim-go@17d4c08) for use with vim (8.1.1073-1). This will use
gopls
by default for autocompletion.Create a file outside
$GOPATH
, e.g./tmp/foo.vim
with this sample content:After
fmt.
, press Ctrl-X, Ctrl-O to trigger auto completion.Alternatively, try this reproducer which does not require vim:
repro.py
Run
python3 repro.py
which will send some commands to gopls and print the responses.What did you expect to see?
Expected to see completion:

With the Python reproducer, I would expect something like:
What did you see instead?
No autocompletion.
With the Python reproducer, I see:
Additional information
I posted an analysis at fatih/vim-go#2193 (comment), the following patch would permit gopls to be used with individual files, e.g. for use with
go run script.go
. When used with projects with multiple files, there may be issues like missing identifiers (unless the client loads all files) or duplicate identifiers when multiple packages are combined.Regardless of those issues, it does address the single script use case though.
[Patch redacted by @bcmills. Please send a PR or CL so that we can verify CLA compliance.]
Other similar issues:
The text was updated successfully, but these errors were encountered: