ziglang / zig.vim

Vim configuration for Zig
MIT License
466 stars 59 forks source link

Location list is always empty upon saving a file with an error #48

Closed hovsater closed 3 years ago

hovsater commented 3 years ago

Whenever I save a Zig file that's in a broken state, the location list opens but doesn't contain any errors. It's always empty.

This is on macOS, version 11.2.1 using the latest version of this plugin.

$ vim --version
VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Mar 16 2021 10:55:44)
macOS version - x86_64
Included patches: 1-2608
Compiled by root@Kevins-MacBook-Pro.local
Huge version without GUI.  Features included (+) or not (-):
+acl               -farsi             +mouse_sgr         +tag_binary
+arabic            +file_in_path      -mouse_sysmouse    -tag_old_static
+autocmd           +find_in_path      +mouse_urxvt       -tag_any_white
+autochdir         +float             +mouse_xterm       -tcl
-autoservername    +folding           +multi_byte        +termguicolors
-balloon_eval      -footer            +multi_lang        +terminal
+balloon_eval_term +fork()            -mzscheme          +terminfo
-browse            +gettext           -netbeans_intg     +termresponse
++builtin_terms    -hangul_input      +num64             +textobjects
+byte_offset       +iconv             +packages          +textprop
+channel           +insert_expand     +path_extra        +timers
+cindent           +ipv6              +perl              +title
-clientserver      +job               +persistent_undo   -toolbar
+clipboard         +jumplist          +popupwin          +user_commands
+cmdline_compl     +keymap            +postscript        +vartabs
+cmdline_hist      +lambda            +printer           +vertsplit
+cmdline_info      +langmap           +profile           +virtualedit
+comments          +libcall           -python            +visual
+conceal           +linebreak         +python3           +visualextra
+cryptv            +lispindent        +quickfix          +viminfo
+cscope            +listcmds          +reltime           +vreplace
+cursorbind        +localmap          +rightleft         +wildignore
+cursorshape       +lua               +ruby              +wildmenu
+dialog_con        +menu              +scrollbind        +windows
+diff              +mksession         +signs             +writebackup
+digraphs          +modify_fname      +smartindent       -X11
-dnd               +mouse             -sound             -xfontset
-ebcdic            -mouseshape        +spell             -xim
+emacs_tags        +mouse_dec         +startuptime       -xpm
+eval              -mouse_gpm         +statusline        -xsmp
+ex_extra          -mouse_jsbterm     -sun_workshop      -xterm_clipboard
+extra_search      +mouse_netterm     +syntax            -xterm_save
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/Users/kevinsjoberg/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DMACOS_X -DMACOS_X_DARWIN -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 
Linking: gcc -L. -L/Users/kevinsjoberg/.asdf/installs/ruby/3.0.0/lib -fstack-protector-strong -L/usr/local/lib -L/usr/local/lib -o vim -lm -lncurses -liconv -lintl -framework AppKit -L/Users/kevinsjoberg/.asdf/installs/lua/5.4.2/lib -llua -fstack-protector-strong -L/System/Library/Perl/5.28/darwin-thread-multi-2level/CORE -lperl -L/Users/kevinsjoberg/.asdf/installs/python/3.9.2/lib/python3.9/config-3.9-darwin -lpython3.9 -lintl -framework CoreFoundation -lruby.3.0 -L/Users/kevinsjoberg/.asdf/installs/ruby/3.0.0/lib 
LemonBoy commented 3 years ago

What's the output of :mess after writing the file? Can you show the code you're trying to save?

hovsater commented 3 years ago

Consider a file named example.zig with the following contents:

const std = @import("std");

pub fn main() !void {
    try std.io.getStdOut().writer().print("hello, world!\n", .{})
}

saving it in Vim causes the location list to open but show no errors. The actual error from running zig run example.zig is:

~/code/zig $ zig run example.zig 
./example.zig:5:1: error: expected token ';', found '}'
}
^

The output of :mess after saving the file is:

zig fmt returned error
"example.zig" 5L, 119B written
LemonBoy commented 3 years ago

The output of :mess after saving the file is:

Is that all? There must be something else before that.

What's the output of :echo executable('zig')?

hovsater commented 3 years ago

@LemonBoy this is the entire :mess buffer:

Messages maintainer: Bram Moolenaar <Bram@vim.org>
"example.zig" 5L, 119B
zig fmt returned error
"example.zig" 5L, 119B written

The output of :echo executable('zig') is 1. Formatting also works correctly upon save if the file doesn't contain any errors.

LemonBoy commented 3 years ago

The plot thickens. Can you dump the list of errors here and the contents of stderr_file? Somehow the data returned by zig fmt is being lost.

hovsater commented 3 years ago

Sure thing.

Contents of the stderr_file:

['<stdin>:5:1: error: expected '';'', found ''}''']

Contents of the errors variable:

[{'lnum': '5', 'col': '1', 'filename': 'example.zig', 'text': ': error: expected '';'', found ''}'''}]
LemonBoy commented 3 years ago

The parameters look correct :\ One more check, what's the output of :echo getloclist(0) after the loclist opens? Do you have some other plugin that may be interfering with this one?

hovsater commented 3 years ago

Oh, I think I found the culprit. It's ALE!

I guess, setting g:zig_fmt_parse_errors to 0 will solve the problem, since I do error handling with ALE. 🙂

Thanks for taking the time to debug this with me. Really appreciate it.

LemonBoy commented 3 years ago

You've beat me to the punch, setting zig_fmt_parse_errors does indeed stop the plugin from parsing the error messages.

Thanks for taking the time to debug this with me. Really appreciate it.

Np, thanks for using zig (and zig.vim) :)