andymass / vim-matchup

vim match-up: even better % :facepunch: navigate and highlight matching words :facepunch: modern matchit and matchparen. Supports both vim and neovim + tree-sitter.
https://www.vim.org/scripts/script.php?script_id=5624
MIT License
1.69k stars 71 forks source link

Buggy interaction with Vimspector #228

Closed Aster89 closed 2 years ago

Aster89 commented 2 years ago

Explain the issue

Most issues are related to bugs or problems. In these cases, you should include a minimal working example and a minimal vimrc file (see below), as well as:

  1. What vim version are you using? If using neovim, Are you using tree-sitter or classic matching?

Vim from terminal, version as follows

:ver                                                                                                                                                                                                                                                
VIM - Vi IMproved 8.2 (2019 Dec 12, compiled May 19 2022 21:27:05)
Included patches: 1-4981
Compiled by Arch Linux
Huge version with GTK3 GUI.  Features included (+) or not (-):
+acl               +channel           +cscope            +ex_extra          -hangul_input      +linebreak         +mouse_dec         -mzscheme          +profile           -sodium            +tcl/dyn           +user_commands     +wildmenu
+arabic            +cindent           +cursorbind        +extra_search      +iconv             +lispindent        +mouse_gpm         +netbeans_intg     -python            +sound             +termguicolors     +vartabs           +windows
+autocmd           +clientserver      +cursorshape       -farsi             +insert_expand     +listcmds          -mouse_jsbterm     +num64             +python3/dyn       +spell             +terminal          +vertsplit         +writebackup
+autochdir         +clipboard         +dialog_con_gui    +file_in_path      +ipv6              +localmap          +mouse_netterm     +packages          +quickfix          +startuptime       +terminfo          +vim9script        +X11
-autoservername    +cmdline_compl     +diff              +find_in_path      +job               +lua/dyn           +mouse_sgr         +path_extra        +reltime           +statusline        +termresponse      +viminfo           -xfontset
+balloon_eval      +cmdline_hist      +digraphs          +float             +jumplist          +menu              -mouse_sysmouse    +perl/dyn          +rightleft         -sun_workshop      +textobjects       +virtualedit       +xim
+balloon_eval_term +cmdline_info      +dnd               +folding           +keymap            +mksession         +mouse_urxvt       +persistent_undo   +ruby/dyn          +syntax            +textprop          +visual            -xpm
+browse            +comments          -ebcdic            -footer            +lambda            +modify_fname      +mouse_xterm       +popupwin          +scrollbind        +tag_binary        +timers            +visualextra       +xsmp_interact
++builtin_terms    +conceal           +emacs_tags        +fork()            +langmap           +mouse             +multi_byte        +postscript        +signs             -tag_old_static    +title             +vreplace          +xterm_clipboard
+byte_offset       +cryptv            +eval              +gettext           +libcall           +mouseshape        +multi_lang        +printer           +smartindent       -tag_any_white     +toolbar           +wildignore        -xterm_save
   system vimrc file: "/etc/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  system gvimrc file: "/etc/gvimrc"
    user gvimrc file: "$HOME/.gvimrc"
2nd user gvimrc file: "~/.vim/gvimrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
    system menu file: "$VIMRUNTIME/menu.vim"
  fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_GTK -I/usr/include/gtk-3.0 -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/sysprof-4 -I/usr/include/harfbuzz -I/usr/include/freetype2 -I/usr/include/lib
png16 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/fribidi -I/usr/include/cairo -I/usr/include/lzo -I/usr/include/pixman-1 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/gio-unix-2.0 -I/usr/include/cloudproviders -I/usr/include/atk-1.0 -I/usr
/include/at-spi2-atk/2.0 -I/usr/include/dbus-1.0 -I/usr/lib/dbus-1.0/include -I/usr/include/at-spi-2.0 -pthread -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -fexceptions -Wformat -Werror=format-security -fstack-clash-protection -fcf-protection -g -ffil
e-prefix-map=/build/vim/src=/usr/src/debug -flto=auto -D_REENTRANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc -L. -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -fstack-protector-strong -rdynamic -Wl,-export-dynamic -Wl,--no-as-needed -Wl,-E -Wl,-rpath,/usr/lib/perl5/5.34/core_perl/CORE -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -flto=auto
-L/usr/local/lib -o vim -lgtk-3 -lgdk-3 -lz -lpangocairo-1.0 -lpango-1.0 -lharfbuzz -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lSM -lICE -lXt -lX11 -lXdmcp -lSM -lICE -lm -ltinfo -lelf -lcanberra -lacl -lattr -l
gpm -Wl,-E -Wl,-rpath,/usr/lib/perl5/5.34/core_perl/CORE -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -flto -fstack-protector-strong -L/usr/local/lib -L/usr/lib/perl5/5.34/core_perl/CORE -lperl -lpthread -ldl -lm -lcrypt -lutil -lc -L/usr/lib -ltclst
ub8.6 -ldl -lz -lpthread -lm
  1. Steps to reproduce See the following screencast. The minimal vimrc is shown at the beginning, whereas the keys I press during the demo are recorded and shown at the end; fundamentally, I start vimspector debugger (I give it an invalid pid, but that's just to be faster, it doesn't matter) while with the cursor on a { whose closing } is out of view, then close the debugger and reopen it, this time I press Escape at the moment I should give the pid, and an error pops up. Since then (not shown in the demo), the error happens everytime the match of the token which the cursor is on, is out of view. asciicast
  2. Expected behavior See previous step
  3. Observed behavior The example above is simply the fastest way I've found to trigger the problem. But I haven't really understood what actually causes that. I just now that generally I'm bitten by it everytime I debug, after a metter of minutes. I suspect that the problem is due to the interaction of vim-matchup with the top line in the source file buffer in vimspector, which is used for the debugger buttons. Indeed, before error occurs, when I'm in that window, vim-matchup picks the wrong line on which it shows the matching token (it is shown in the screencast).

Minimal working example

See steps above

Minimal vimrc file

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

let mapleader = "\<Space>"

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 'junegunn/vim-plug'
Plug 'andymass/vim-matchup'
Plug 'puremourning/vimspector'
call plug#end()

let g:vimspector_base_dir = environ().HOME .. '/.vim/plugged/vimspector'
nnoremap <leader>ds :call vimspector#Launch()<CR>
nnoremap <leader>dq :VimspectorReset<CR>
let g:matchup_matchparen_offscreen = {'method': 'popup', 'highlight': 'OffscreenPopup', 'fullwidth': 1, 'syntax_hl': 1}
let g:matchup_matchparen_stopline = 1500
let g:matchup_delim_stopline = 9000
Aster89 commented 2 years ago

I suspect that you don't need a working vimspector setup to reproduce this.

Probably you just need to install the vimspector plugin, and just hava a .vimspector.json file in the working dir where you try to reproduce the bug. Probably it doesn't even need to be valid.

I'm happy to help if you have troubles reproducing the issue.

Aster89 commented 2 years ago

Vimspector's author helped me understand a bit more about this problem.

It turns out that the bar with the buttons is a Vim thing, named WinBar, which I didn't know of.

The misplacement of the line where the matching line is shown can be reproduced by simply running

:nnoremenu WinBar.Test :echo help

and then triggering an off-screen matchup matching, as per the screencast below.

I think that fixing that will fix the original problem I was facing.

asciicast

andymass commented 2 years ago

Thanks, your PR definitely solves the positioning issue. However, I see some other errors related to "matchup__CursorLineNr." Let me look into those.

Aster89 commented 2 years ago

I assume that, as far as you can tell, the original problem is fixed by my change?

andymass commented 2 years ago

I think so. Please let me know if you encounter further issues and I'm happy to re-open and dive deeper. Thanks again for the contribution.