Repository: autozimu/LanguageClient-neovim

Issue #914: Cursor jumps when clangd automatically inserts headers
Created: 2019-11-10T22:10:26Z
Did you upgrade to latest plugin version?
Yes
Did you upgrade to/compile latest binary? Run shell command
bin/languageclient --version to get its version number.

I compiled the latest master

(Neovim users only) Did you check output of :checkhealth LanguageClient?
Everything healthy
Did you check troubleshooting?
Yes

Describe the bug
Clangd has the following CLI option:
  --header-insertion=<value>      - Add #include directives when accepting code completions
    =iwyu                         -   Include what you use. Insert the owning header for top-level symbols, unless the header is alread

When it automatically includes a header an additional line gets inserted at the top of the file. So my cursor should move one line down in document but it stays at the same position.
Because of that I start editing the previous line in the document.
Environment

neovim/vim version (nvim --version or vim --version):

NVIM v0.5.0-144-g568900806
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: /usr/bin/gcc-5 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -O2 -g -DMIN_LOG_LEVEL=3 -Og -g -Wall -Wextra -pedantic -Wno-unused-p
arameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wvla -fstack-protector-strong -fdiagnostics-color=a
uto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -I/home/travis/build/neovim/bot
-ci/build/neovim/build/config -I/home/travis/build/neovim/bot-ci/build/neovim/src -I/home/travis/build/neovim/bot-ci/build/neovim/.deps
/usr/include -I/usr/include -I/home/travis/build/neovim/bot-ci/build/neovim/build/src/nvim/auto -I/home/travis/build/neovim/bot-ci/buil
d/neovim/build/include
Compiled by travis@travis-job-3c2d1eac-da9f-48a2-905f-74efb0c9d5e5

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

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



This plugin version (git rev-parse --short HEAD):
dd45e31
This plugin's binary version (bin/languageclient --version):
built from dd45e31
language server: clangd-10 (https://apt.llvm.org/)
Minimal vimrc content (A minimal vimrc is the smallest vimrc that could
reproduce the issue. Refer to an example here):

call plug#begin('~/.local/share/nvim/plugged2')

Plug 'autozimu/LanguageClient-neovim', {
    \ 'branch': 'next',
    \ 'do': 'bash install.sh',
    \ }
if has('nvim')
  Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
else
  Plug 'Shougo/deoplete.nvim'
  Plug 'roxma/nvim-yarp'
  Plug 'roxma/vim-hug-neovim-rpc'
endif

call plug#end()


augroup filetype_rust
      autocmd!
      autocmd BufReadPost *.cpp setlocal filetype=cpp
augroup END

autocmd FileType * call deoplete#custom#option('auto_complete', v:true)


" Always draw sign column. Prevent buffer moving when adding/deleting sign.
 set signcolumn=yes

let g:deoplete#enable_at_startup = 1
 let g:LanguageClient_serverCommands = {
     \ 'cpp': ['clangd-10', '--clang-tidy', '--header-insertion=iwyu', '--background-index', '--suggest-missing-includes']
         \ }
 let $RUST_BACKTRACE = 1
 let g:LanguageClient_loggingLevel = 'INFO'
 let g:LanguageClient_virtualTextPrefix = ''
 let g:LanguageClient_loggingFile = expand('~/.local/share/nvim/LanguageClient.log')
 let g:LanguageClient_serverStderr = expand('~/.local/share/nvim/LanguageServer.log')


To Reproduce
Create the following file and start the language server:
  #include <string>                                                
  auto main() -> int                                    
  {                                                                                                                               
          auto foo = std::make
  }                                                                                                               

Then complete for instance to std::make_signed. After entering the opening paren iwyu (inlude what you use) automatically inserts the indirectly used header but the cursor will jump one line.
  #include <string>                       
  #include <type_traits>                                
  auto main() -> int                                    
  {<<< cursor position will be here                                                                                                                               
✖         auto foo = std::make_signed( Use of class template 'make_signed' requires template arguments                                                               
✖ } Expected expression                                                                                          
                           

Current behavior
Cursor jumps one line
Expected behavior
Cursor position should be changed when the language server changed the document.
Screenshots
N/A
Additional context
Don't know whether this bug is specific to the clangd version.

Duplicate issue #987: Wrong completion position using gopls when package that hasn't been imported
Created: 2020-03-11T01:00:23Z
Did you upgrade to latest plugin version? Yes


Did you upgrade to/compile latest binary? Run shell command
languageclient 0.1.156


(Neovim users only) Did you check output of :checkhealth LanguageClient?
Yes, everything looks fine


health#LanguageClient#check
========================================================================
  - OK: binary found: /home/jiahao/.vim/plugged/LanguageClient-neovim/bin/languageclient
  - OK: languageclient 0.1.156 
  - INFO: Floating window is not supported. Preview window will be used for hover


Did you check [troubleshooting]?
[troubleshooting]: https://github.com/autozimu/LanguageClient-neovim/blob/next/INSTALL.md#6-troubleshooting Yes

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.

Environment

neovim/vim version

NVIM v0.3.8
Build type: Release
LuaJIT 2.1.0-beta3
Compilation: /usr/bin/cc -g -O2 -fdebug-prefix-map=/build/neovim-Bljd1N/neovim-0.3.8=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=1 -DDISABLE_LOG -Wdate-time -D_FORTIFY_SOURCE=1 -Wconversion -O2 -DNDEBUG -DMIN_LOG_LEVEL=3 -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fdiagnostics-color=auto -Wno-array-bounds -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -I/build/neovim-Bljd1N/neovim-0.3.8/build/config -I/build/neovim-Bljd1N/neovim-0.3.8/src -I/usr/include -I/build/neovim-Bljd1N/neovim-0.3.8/build/src/nvim/auto -I/build/neovim-Bljd1N/neovim-0.3.8/build/include
Compiled by team+vim@tracker.debian.org

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):

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=

To Reproduce
Steps to reproduce the behavior:

Create a dummy project using the following go code\

package exp

func exp() {
}



Start vim, nvim -u min-vimrc.vim ...
Edit : try to insert fmt.Println and when you type the next parenthesis
Execute: type the "("
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.

Closing comment (2020-03-12T12:17:41Z): dupe: #914