autozimu / LanguageClient-neovim

Language Server Protocol (LSP) support for vim and neovim.
MIT License
3.55k stars 274 forks source link

Wrong completion position using gopls when package that hasn't been imported #987

Closed jiahaowu closed 4 years ago

jiahaowu commented 4 years ago

Describe the bug

LanguageClient-neovim works fine with the other languages. The issue is specific about golang. When completing golang using lsp server gopls, the completion is always one line above the expected location when the package is not imported before hand.

This case is tricky because gopls will automatically import library at the top. It looks like that the completion function isn't aware of such change and added completion to original row. Here is a gif record of this behavior.

Peek 2020-03-10 17-42

Environment

Features: +acl +iconv -jemalloc +tui See ":help feature-compile"

system vimrc file: "$VIM/sysinit.vim" fall-back for $VIM: "/usr/share/nvim"

Run :checkhealth for more info


- This plugin version (`git rev-parse --short HEAD`): `222e250`
- This plugin's binary version (`bin/languageclient --version`): languageclient 0.1.156
- Minimal vimrc content (A minimal vimrc is the smallest vimrc that could
  reproduce the issue. Refer to an example [here][min-vimrc.vim]):

call plug#begin('~/.vim/plugged') Plug 'autozimu/LanguageClient-neovim', { \ 'branch': 'next', \ 'do': 'bash install.sh', \ }

Plug 'ncm2/ncm2' call plug#end()

let g:LanguageClient_serverCommands = { \ 'go': ['gopls'], \ } " enable ncm2 for all buffers autocmd BufEnter * call ncm2#enable_for_buffer()


- Language server link and version:

golang.org/x/tools/gopls v0.3.3 golang.org/x/tools/gopls@v0.3.3 h1:mTFqRDJQmpSsgDDWvbtGnSva1z9uX2XcDszSWa6DhBQ=


[min-vimrc.vim]: https://github.com/autozimu/LanguageClient-neovim/blob/next/min-vimrc.vim

## To Reproduce
Steps to reproduce the behavior:
1. Create a dummy project using the following go code\

package exp

func exp() { }


1. Start vim, `nvim -u min-vimrc.vim` ...
1. Edit : try to `insert fmt.Println` and when you type the next parenthesis
1. Execute: type the "("
1. See error: the cursor goes to the line above and completion is inserted at wrong position.

## Current behavior
The cursor goes to the line above and completion is inserted at wrong position.

## Expected behavior
The cursor should stay at the line where I trigger the completion.

## Screenshots
Attached above.

## Additional context
gopls automatically adds imported package at the beginning.
donotnoot commented 4 years ago

dupe: https://github.com/autozimu/LanguageClient-neovim/issues/914

ANtlord commented 4 years ago

Is it fixed? I get the issue still in spite of today upgrade of the plugin. Should I change some settings?

jiahaowu commented 4 years ago

You need to compile the languageClient from source to get the fix.