vim-matchup icon indicating copy to clipboard operation
vim-matchup copied to clipboard

Suspicious interaction between vim-matchup and YCM

Open Aster89 opened this issue 2 years ago • 8 comments

Explain the issue

I think this issue is a consequence of an interaction between YouCompleteMe and vim-matchup. I've posted a question on vi.stackexchange, but that hasn't helped yet.

  1. What vim version are you using? 8.2 same as in #183.
  2. Steps to reproduce: having YouCompleteMe and vim-matchup plugins, and simply writing stuff in an existing HTML comment, so within <!-- here -->.
  3. Expected behavior: the comment is written.
  4. Observed behavior: while I write, frequently the comment gets deleted from the !-- part (the < survives) to the last letter I've written.

Minimal working example

Please provide a minimal working example, e.g.,

Unfortunately I haven't been able to find an exact way to reproduce it, but typing letters and spaces in a comment sooner or later triggers the issue. I suspect the interaction with YouCompleteMe is fundamental to the problem. As you can see in the screencast below. While I'm typing there's a pum from YCM that pops up at the ! of <!--. Sometimes it's harmful, but sometimes it results in the text being deleted leftward up to that point.

asciicast

Some key points in the video:

  • at the time 00:09 the prolem happens (afterwards I press u to restore the !-- part of the comment)
  • at around 00:21-00:22 there's a moment you'll see a pum flashing under the ! of <!--. I haven't been able to pause the screencast at that exact moment, but I think that's strongly related to the issue.

Minimal vimrc file

Please provide a minimal vimrc file that reproduces the issue. The following should often suffice:

if empty(glob('~/.vim/autoload/plug.vim'))
  silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
    \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
  au VimEnter * PlugInstall --sync | source $MYVIMRC
endif
call plug#begin('~/.vim/plugged')

Plug 'Valloric/YouCompleteMe'
Plug 'andymass/vim-matchup'
call plug#end()

syntax enable

let g:ycm_complete_in_comments = 1

Aster89 avatar Oct 10 '21 09:10 Aster89

With some help in YCM gitter room I've found out that I can run

:augroup matchup_matchparen
:au! matchup_matchparen TextChangedI
:au! matchup_matchparen TextChangedP
:augroup END

and issue persists. If I also run either this

:augroup matchup_matchparen
:au! matchup_matchparen CursorMovedI
:augroup END

or this

:augroup ycmcompletemecursormove
:au! ycmcompletemecursormove TextChangedI
:augroup END

then it disappears.

So it looks like there's some interaction between call s:matchparen.highlight_deferred() and YCM's pum.

Aster89 avatar Oct 10 '21 10:10 Aster89

I didn't know, but in YCM chat room I've been made aware that if I donwload the *.cast file from asciinema and run it in the terminal via asciinema play that.cast, I can then pause with space and even step frame by frame via .. This shows the crazy jumping of the cursor that happens all the time.

Not sure anymore whether it's a YCM or vim-matchup bug.

Here's some comment from Boris Staletic:

after entering insert mode and typing c, the cursor is taken all the way behind >, then back to c. That happens on every character you insert. After the second character, YCM kicks in. After entering the second character, completion pum is visible. The cursor now doesn't just jump over to >, it jumps down to the bottom right edge of pum. You type consid and the pum disappears, the cursor is taken to the bottom right edge of the buffer! With the disappearing pum, a space was entered between consid and er.

Note that the space between consid and er happened after jumping back from the corner of the buffer.

I see you mentioned the "pum under !" in matchup's bug report. That happens after:

  1. You type er.
  2. YCM doesn't trigger for some reason.
  3. You type Space, which I guess is meant this time, after consider.
  4. Cursor disappears!
  5. YCM shows a pum under !...
  6. Cursor appears on !, explaining YCM's pum positioning.

I can see it's setting '] mark, but I have no idea what for.

Aster89 avatar Oct 10 '21 11:10 Aster89

Thanks for diving into this. I will try to trace the reproduce steps.

Is there a minimal set of match-up autocmds that can be removed like this

:augroup matchup_matchparen
:au! matchup_matchparen CursorMovedI
:augroup END

then the problem goes away? Or is it necessary to remove all of TextChangedI,TextChangedP,CursorMovedI?

andymass avatar Oct 10 '21 12:10 andymass

By the way, I really doubt the following will actually help in your case (since both match-up and YCM are asynchronous), but the existing suggestion in the help docs is:

let g:matchup_matchparen_pumvisible = 0

Curious what this would do.

andymass avatar Oct 10 '21 12:10 andymass

Or is it necessary to remove all of TextChangedI,TextChangedP,CursorMovedI?

Removing only CursorMovedI, the problem persists. Removing both TextChangedI and TextChangedP but leaving CursorMovedI active, the problem persists. Removing both CursorMovedI and TextChangedP, the problem persists. Removing both CursorMovedI and TextChangedI, the problem is solved.

Aster89 avatar Oct 10 '21 13:10 Aster89

let g:matchup_matchparen_pumvisible = 0

Curious what this would do.

The problem persists even with this line in my vimrc.

Aster89 avatar Oct 10 '21 13:10 Aster89

Unfortunately, I was able to reproduce the problem even with the proposed fix. I'll keep looking.

There's a couple of possible workarounds right now:

  1. let g:matchup_matchparen_deferred = 1 (though I am not sure if the problem still occurs with this enabled, I wasn't able to reproduce with it on)
  2. let g:matchup_matchparen_nomode = 'i' but this will disable highlighting in insert mode completely

andymass avatar Oct 10 '21 20:10 andymass

FYI I just pushed a change which should make this occurrence much more rare, although does not fix the underlying issue.

andymass avatar Oct 11 '21 01:10 andymass