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

Get completion for package when it's not imported yet (using with deoplete) #2562

Closed
marselmustafin opened this issue Nov 6, 2019 · 16 comments · Fixed by #2567 or #2568
Closed

Get completion for package when it's not imported yet (using with deoplete) #2562

marselmustafin opened this issue Nov 6, 2019 · 16 comments · Fixed by #2567 or #2568

Comments

@marselmustafin
Copy link

What did you do? (required: The issue will be closed when not provided)

let g:go_fmt_command = "goimports"
let g:go_fmt_fail_silently = 1
let g:go_list_type = "quickfix"

let g:go_highlight_types = 1
let g:go_highlight_fields = 1
let g:go_highlight_functions = 1
let g:go_highlight_function_calls = 1
let g:go_highlight_operators = 1
let g:go_highlight_extra_types = 1
let g:go_highlight_generate_tags = 1
let g:go_highlight_build_constraints = 1
let g:go_echo_go_info = 0
let g:go_metalinter_autosave=1

autocmd BufNewFile,BufRead *.go setlocal noexpandtab tabstop=4 shiftwidth=4
autocmd InsertLeave,CompleteDone * if pumvisible() == 0 | pclose | endif

call deoplete#custom#option('omni_patterns', {
      \ 'go': '[^. *\t]\.\w*',
      \})

Also deoplete and vim-go plugins installed.

What did you expect to happen?

Autocompletion works excellent with deoplete for imported packages. But given I entered fmt for example and it's not in my import list, I want to see functions for this package in completions list anyway.

What happened instead?

I see no completions for package until it imported. This forces me to import package manually or add function call and import it by goimports before using completion.

Configuration (MUST fill this out):

(written above)

vim-go version:

v1.21

Vim version (first three lines from :version):

Neovim v0.4.2

Go version (go version):

go version go1.13.1 darwin/amd64

Go environment

not relevant here

@stamblerre
Copy link
Contributor

This feature is currently available behind a flag in gopls (see golang/go#31906). You will need to add the completeUnimported setting to your configuration to use it (though I'm not sure exactly how to do that with vim-go).

@bhcleek
Copy link
Collaborator

bhcleek commented Nov 6, 2019

We need to add some options to vim-go to support starting gopls with flags.

@bhcleek
Copy link
Collaborator

bhcleek commented Nov 6, 2019

@marselmustafin is deoplete using vim-go's autocompletion? If not, then your particular use case needs to be solved by deoplete, not with vim-go.

@bhcleek
Copy link
Collaborator

bhcleek commented Nov 7, 2019

@stamblerre will completeUnimported still be behind a flag in the upcoming gopls release?

@stamblerre
Copy link
Contributor

I'm not sure yet, but most likely, yes. I think the feature still needs to be iterated on a bit more.

@delphinus
Copy link
Contributor

@bhcleek

Deoplete has the omni_patterns option. With this, Deoplete does not use its own features but uses omnifunc from vim-go. (@marselmustafin is using this option)

So this issue should aim to implement completeUnimported in vim-go.

@bhcleek
Copy link
Collaborator

bhcleek commented Nov 8, 2019

@stamblerre I just want to confirm: completeUnimported is a workspace configuration option, not a cli flag?

@stamblerre
Copy link
Contributor

Yes, exactly.

@marselmustafin
Copy link
Author

@bhcleek thanks for the update. Did you test completion with let g:go_gopls_complete_unimported = 1? I've enabled this parameter, but completion for unimported packages still doesn't work. I've tried to disable deoplete and use original omnicompletion, but it works only for imported packages as before.

@bhcleek bhcleek reopened this Nov 9, 2019
@bhcleek
Copy link
Collaborator

bhcleek commented Nov 9, 2019

It will, of course depend on the version of gopls you have installed. I think that the latest release of gopls doesn't yet support this feature, but a new release is imminent. Once a new release of gopls is made, you can use :GoUpdateBinaries gopls to update it.

You may find golang/go#31906 useful, too.

@bhcleek
Copy link
Collaborator

bhcleek commented Nov 9, 2019

@marselmustafin after correcting to use the proper values to encode for json, the version of gopls installed by vim-go works as expected for me.

@marselmustafin
Copy link
Author

@bhcleek I've updated plugin and gopls package (v0.1.7), but still don't get any completions for unimported fmt package for example😔. If it works for you, could you provide your gopls version and completion config please? maybe I missed something necessary

@delphinus
Copy link
Contributor

@marselmustafin

The latest stable version (v0.1.7) does not seem to have this feature. You can install gopls with a certain commit to support this. such as...

go get -v -u golang.org/x/tools/gopls@97ad0ed33101b39103eaf8aeab62b59dd1cfb89e

I have successfully completed methods from unimported ones.

@bhcleek
Copy link
Collaborator

bhcleek commented Nov 10, 2019

@delphinus I am using gopls 0.1.7, and completion of unimnported package names is working fine.

@marselmustafin completeUnimported is not enabled by default. You'll need to have g:go_gopls_comleted_unimported=1 in your vimrc or in an after/plugin file (mine is in after/plugin/vim-go.vim file).

@marselmustafin
Copy link
Author

@bhcleek sorry for importunity. I tried different things but it still doesn't work. I've set g:go_gopls_comleted_unimported=1, tried to disable both plugins deoplete and deoplete-tabnine which I use, also tried to reinstall gopls with the latest revision, but still when I write fmt. and press <C-x><C-o> nothing happens. Is vim type (I use neovim) or some configuration can affect it?

@bhcleek
Copy link
Collaborator

bhcleek commented Nov 11, 2019

No worries, @marselmustafin . Currently, gopls does not complete the identifiers from unimported packages; it only completes the package itself.

golang/go#31906 is useful to explain some of the details of the gopls feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants