preservim / tagbar

Vim plugin that displays tags in a window, ordered by scope
https://preservim.github.io/tagbar
Other
6.12k stars 486 forks source link

Error when viewing a javascript file #533

Open ianchanning opened 5 years ago

ianchanning commented 5 years ago

I'm using Vim 8.1 on Ubuntu 18.04

I get the following error every few seconds when viewing a javascript file. It is using various ES7 syntax constructs, so it could be that the tags are invalid.

Error detected while processing function <SNR>126_AutoUpdate[63]..<SNR>126_ProcessFile[84]..<SNR>126_ParseTagline:
line    3:
E684: List index out of range: 1

I thought perhaps my tags were out of date so made sure they were up-to-date. Other files in the same directory with similar syntax show the tags ok.

On the very first opening of the file (after I close and reopen Vim) I get this error:

Error detected while processing function <SNR>118_AutoUpdate[63]..<SNR>118_ProcessFile[84]..<SNR>118_ParseTagline:
line   51:
E716: Key not present in Dictionary: kind) && tagname =~# '\V' . escape(a:typeinfo.sro, '\')
E116: Invalid arguments for function has_key(a:typeinfo.kind2scope, fielddict.kind) && tagname =~# '\V' . escape(a:typeinfo.sro, '\')

But after the first time I don't see that error again.

Debug info

My :version:

VIM - Vi IMproved 8.1 (2018 May 18, compiled Mar 27 2019 09:36:25)
Included patches: 1-1140
Modified by jonathon.fernyhough@york.ac.uk
Compiled by jonathon.fernyhough@york.ac.uk
Huge version with GTK3 GUI.  Features included (+) or not (-):
+acl               +cmdline_compl     +emacs_tags        +insert_expand     +modify_fname      +netbeans_intg     +ruby              +terminfo          +vreplace
+arabic            +cmdline_hist      +eval              +job               +mouse             +num64             +scrollbind        +termresponse      +wildignore
+autocmd           +cmdline_info      +ex_extra          +jumplist          +mouseshape        +packages          +signs             +textobjects       +wildmenu
+autochdir         +comments          +extra_search      +keymap            +mouse_dec         +path_extra        +smartindent       +textprop          +windows
-autoservername    +conceal           -farsi             +lambda            +mouse_gpm         +perl              +startuptime       +timers            +writebackup
+balloon_eval      +cryptv            +file_in_path      +langmap           -mouse_jsbterm     +persistent_undo   +statusline        +title             +X11
+balloon_eval_term +cscope            +find_in_path      +libcall           +mouse_netterm     +postscript        -sun_workshop      +toolbar           -xfontset
+browse            +cursorbind        +float             +linebreak         +mouse_sgr         +printer           +syntax            +user_commands     +xim
++builtin_terms    +cursorshape       +folding           +lispindent        -mouse_sysmouse    +profile           +tag_binary        +vartabs           +xpm
+byte_offset       +dialog_con_gui    -footer            +listcmds          +mouse_urxvt       -python            -tag_old_static    +vertsplit         +xsmp_interact
+channel           +diff              +fork()            +localmap          +mouse_xterm       +python3           -tag_any_white     +virtualedit       +xterm_clipboard
+cindent           +digraphs          +gettext           +lua               +multi_byte        +quickfix          +tcl               +visual            -xterm_save
+clientserver      +dnd               -hangul_input      +menu              +multi_lang        +reltime           +termguicolors     +visualextra
+clipboard         -ebcdic            +iconv             +mksession         -mzscheme          +rightleft         +terminal          +viminfo
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  system gvimrc file: "$VIM/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  -pthread -I/usr/include/gtk-3.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-
1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -I/usr/include/gtk-3.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I
/usr/include/pango-1.0 -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/freetype2 -I/usr/i
nclude/libpng16 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng16 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -Wdate-time  -g -O2 -fdebug-prefix
-map=/build/vim-34suZO/vim-8.1.1140=. -fstack-protector-strong -Wformat -Werror=format-security -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc   -L. -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -fstack-protector -rdynamic -Wl,-export-dynamic -Wl,-E  -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now
-Wl,--as-needed -o vim   -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lSM -lICE -lXpm
-lXt -lX11 -lXdmcp -lSM -lICE  -lm -ltinfo -lnsl  -lselinux  -lacl -lattr -lgpm -ldl  -L/usr/lib -llua5.2 -Wl,-E  -fstack-protector-strong -L/usr/local/lib  -L/usr/lib/x86_6
4-linux-gnu/perl/5.26/CORE -lperl -ldl -lm -lpthread -lcrypt  -L/usr/lib/python3.6/config-3.6m-x86_64-linux-gnu -lpython3.6m -lpthread -ldl -lutil -lm -L/usr/lib/x86_64-linu
x-gnu -ltcl8.6 -ldl -lz -lpthread -lm -lruby-2.5 -lpthread -lgmp -ldl -lcrypt -lm

I'm using Vundle and I have the following plugins installed:

Plugin 'VundleVim/Vundle.vim'
Plugin 'altercation/vim-colors-solarized'
Plugin 'lifepillar/vim-solarized8'
Plugin 'tpope/vim-sensible'
Plugin 'tpope/vim-fugitive'
Plugin 'tpope/vim-surround'
Plugin 'tpope/vim-unimpaired'
Plugin 'tpope/vim-obsession'
Plugin 'tpope/vim-vinegar'
Plugin 'tpope/vim-commentary'
Plugin 'tpope/vim-repeat'
Plugin 'tpope/vim-dadbod'
Plugin 'tpope/vim-jdaddy'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
Plugin 'jremmen/vim-ripgrep'
Plugin 'junegunn/fzf'
Plugin 'junegunn/fzf.vim'
Plugin 'KabbAmine/zeavim.vim'
Plugin 'vim-scripts/cream-showinvisibles' "appeared to cause slowdown on Eee
Plugin 'w0rp/ale'
Plugin 'junegunn/goyo.vim'
Plugin 'Raimondi/delimitMate' "this caused minor slowdown/refreshing issues on my Eee
Plugin 'ervandew/supertab'
Plugin 'majutsushi/tagbar' " Browsing tags
Plugin 'skywind3000/asyncrun.vim'
Plugin 'pangloss/vim-javascript'
Plugin 'mxw/vim-jsx'
Plugin 'jparise/vim-graphql'
Plugin 'heavenshell/vim-jsdoc'
Plugin 'plasticboy/vim-markdown'
Plugin 'suan/vim-instant-markdown'
nganhkhoa commented 5 years ago

Ouch, I have this too, and I still don't know how. Using NVim here.

jfly commented 5 years ago

@isthisnagee and I just spent too much time looking into this, and maybe figured something out!

We used :TagbarDebug and discovered that the output of ctags looks like this (a snippet):

regionsFolded   /tmp/vOxOQei/10.js      /^        const [regionsVisible, regionsFolded] = _.partition(regions, region =>$/;"    C       line:899
regionsToShow   /tmp/vOxOQei/10.js      /^        const regionsToShow = _.sortBy(regionsVisible, 'name');$/;"   C       line:902
foldedRegionNames       /tmp/vOctags-og: Warning: ignoring null tag in /tmp/vOxOQei/10.js(line: 986)
xOQei/10.js     /^        const foldedRegionNames = _.sortBy(regionsFolded, 'name').map($/;"    C       line:903
hasOverrides    /tmp/vOxOQei/10.js      /^        const hasOverrides =$/;"      C       line:988
allowSubmitWithOverrides        /tmp/vOxOQei/10.js      /^        const allowSubmitWithOverrides =$/;"  C       line:994

For the record, when I invoke ctags on certain js files, I get this warning (if you do not, I don't think you'll get any problems):

$ cat /tmp/foo.js
if (true) {
    this[0] = function() {};
}
$ ctags -f - /tmp/foo.js
ctags: Warning: ignoring null tag in /tmp/foo.js(line: 2)

The problem seems to be that this invocation of system in tagbar captures both stderr and stdout, and there are no guarantees about how they will get interleaved. Then, when we try to parse the ctags contents, it won't necessarily be a valid ctags file, and we crash in ProcessFile.

Some ideas:

zabil commented 4 years ago

I have this issue only when using universal-ctags this issue is not there when I switch back to exuberant ctags.