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 #827: additionalTextEdits above the cursor don't move the cursor down to the line where it used to be
Created: 2019-05-24T21:33:12Z
Describe the bug
When clangd inserts a header automatically, the cursor will stay on the same line number, even though all the text above the cursor has shifted down. So it feels like the cursor suddenly moved up.
Environment


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


This plugin version (git rev-parse --short HEAD): 41c948e


This plugin's binary version (bin/languageclient --version): 0.1.146


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

" I use this for python, you probably don't need it
Plug 'roxma/python-support.nvim'

Plug 'autozimu/LanguageClient-neovim', {
    \ 'branch': 'next',
    \ 'do': 'bash install.sh',
    \ }
let g:LanguageClient_serverCommands = {
    \ 'c': ['clangd'],
    \ 'cpp': ['clangd'],
    \ }
let g:LanguageClient_loggingLevel = 'INFO'
let g:LanguageClient_loggingFile =  expand('~/.local/share/nvim/LanguageClient.log')
let g:LanguageClient_serverStderr = expand('~/.local/share/nvim/LanguageServer.log')

Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
let g:deoplete#enable_at_startup = 1

call plug#end()

set number


Language server link and version: clangd trunk


To Reproduce
Steps to reproduce the behavior:

Start vim with clangd
Trigger clangd automatic header insertion

Current behavior
The cursor stays on the same line number, which makes it feel like it moved it up a line.
Expected behavior
The cursor should move to the next line number because the text above it has shifted down a line.

Closing comment (2020-02-27T17:51:31Z): Duplicate #914