Closed Caratpine closed 4 years ago
language server needs to support this.
You can try to use :LspCodeAction
and see something like this.
Also give this a try and it should make it simple to setup language servers. readme contains instructions on how to setup. https://github.com/prabirshrestha/vim-lsp#registering-servers
goland doesn't depend directly on gopls so it has custom features.
I can't repro the cursor moving so please make sure you have the latest master. There were few changes that went in yesterday.
Also might be good to suggest gopls to support auto imports via textedits.
Thanks for your answer :) I'll try it later.
Hi, prabirshrestha
The problem I encountered was similar to this issue, but I did not use asyncomplete-omni.vim
plugin. I configured the completion shortcut as follows:
inoremap <expr> <CR> pumvisible() ? asyncomplete#close_popup() . "\<CR>" : "\<CR>"
inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
The reproduction process is as follows:
I did not import the io
package beforehand, I defined a variable i
whose type is io.Writer
, I pressed .
. Wait for the completion prompt, then pressed Tab
to the Writer
column, and then pressed Enter
. At this time, the io
package was be imported automatically and the cursor drifted.
the asyncomplete-omni
seems modify cursor position on purpose.
So the problem isn't vim-lsp side , I think.
Could you check via <C-x><C-o>
manually without asyncomplete-omni.
@hrsh7th I didn't use asyncomplete-omni
Here is my .vimrc about completion:
Plug 'prabirshrestha/asyncomplete.vim'
Plug 'prabirshrestha/async.vim'
Plug 'prabirshrestha/vim-lsp', {'branch': 'master'}
Plug 'prabirshrestha/asyncomplete-lsp.vim'
if executable('gopls')
au User lsp_setup call lsp#register_server({
\ 'name': 'gopls',
\ 'cmd': {server_info->['gopls']},
\ 'whitelist': ['go'],
\ })
autocmd BufWritePre *.go LspDocumentFormatSync
endif
if executable('go-langserver')
au User lsp_setup call lsp#register_server({
\ 'name': 'go-langserver',
\ 'cmd': {server_info->['go-langserver', '-gocodecompletion']},
\ 'whitelist': ['go'],
\ })
autocmd BufWritePre *.go LspDocumentFormatSync
endif
inoremap <expr> <CR> pumvisible() ? asyncomplete#close_popup() . "\<CR>" : "\<CR>"
inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
My vim version: Vi IMproved 8.2 macOS version.
Hm... I checked with running gopls
and go-langserver
both.
But has no problem...
Could you paste the your vimrc that includes other plugins section.
@Caratpine Can you try using vim-lsp-settings. I just sent a PR that will auto enable go imports. https://github.com/mattn/vim-lsp-settings/pull/68.
I would suggest you to disable Plug 'fatih/vim-go', {'tag': '*'}
.
Plug 'prabirshrestha/async.vim'
Plug 'prabirshrestha/asyncomplete.vim'
Plug 'prabirshrestha/asyncomplete-lsp.vim'
Plug 'prabirshrestha/vim-lsp'
Plug 'mattn/vim-lsp-settings'
autocmd BufWritePre *.go LspDocumentFormatSync
I would also suggest you to use autocmd User lsp_buffer_enabled
which is documented in README.md
Hm... I checked your vimrc in Vim8.1. But I have no problem, Sorry I can't understood the reason...
Hi, prabirshrestha
I want this effect.
But it's like this
My .vimrc
How can I do? thanks :-)