Skip to content

Commit 41c26d6

Browse files
g-w1haze
authored andcommitted
use --ast-check in the fmt command
1 parent c339f13 commit 41c26d6

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

autoload/zig/fmt.vim

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function! zig#fmt#Format() abort
1313
return
1414
endif
1515

16-
let cmdline = 'zig fmt --stdin'
16+
let cmdline = 'zig fmt --stdin --ast-check'
1717
let current_buf = bufnr('')
1818

1919
" The formatted code is output on stdout, the errors go on stderr.
@@ -22,8 +22,19 @@ function! zig#fmt#Format() abort
2222
else
2323
silent let out = split(system(cmdline, current_buf))
2424
endif
25+
if len(out) == 1
26+
if out[0] == "error: unrecognized parameter: '--ast-check'"
27+
let cmdline = 'zig fmt --stdin'
28+
if exists('*systemlist')
29+
silent let out = systemlist(cmdline, current_buf)
30+
else
31+
silent let out = split(system(cmdline, current_buf))
32+
endif
33+
endif
34+
endif
2535
let err = v:shell_error
2636

37+
2738
if err == 0
2839
" remove undo point caused via BufWritePre.
2940
try | silent undojoin | catch | endtry

0 commit comments

Comments
 (0)