Skip to content

Commit 10ff263

Browse files
committed
Revert "Do fmt and ast-check steps separately"
This reverts commit 29ceb12.
1 parent 0762d89 commit 10ff263

File tree

3 files changed

+6
-62
lines changed

3 files changed

+6
-62
lines changed

README.md

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,6 @@ This plugin enables automatic code formatting on save by default using
3737
let g:zig_fmt_autosave = 0
3838
```
3939

40-
Additionally, `zig ast-check` is run after formatting, to disable this,
41-
set the following:
42-
43-
```
44-
let g:zig_ast_check_autosave = 0
45-
```
46-
47-
The above `zig fmt` and `zig ast-check` are done in separate steps, to do them
48-
in one step (as `zig fmt --ast-check`) set the following:
49-
50-
```
51-
let g:zig_fmt_ast_check_autosave = 1
52-
```
53-
5440
The default compiler which gets used by `:make` (`:help :compiler` for details)
5541
is `zig_build` and it runs `zig build`. The other options are:
5642
* `:compiler zig_test` which runs `zig test` on the current file.

autoload/zig/fmt.vim

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
" Use of this source code is governed by a BSD-style
55
" license that can be found in the LICENSE file.
66

7-
function! zig#fmt#Format(do_astcheck) abort
7+
function! zig#fmt#Format() abort
88
" Save cursor position and many other things.
99
let view = winsaveview()
1010

@@ -13,10 +13,7 @@ function! zig#fmt#Format(do_astcheck) abort
1313
return
1414
endif
1515

16-
let cmdline = 'zig fmt --stdin'
17-
if a:do_astcheck
18-
let cmdline .= ' --ast-check'
19-
endif
16+
let cmdline = 'zig fmt --stdin --ast-check'
2017
let current_buf = bufnr('')
2118

2219
" The formatted code is output on stdout, the errors go on stderr.
@@ -80,38 +77,6 @@ function! zig#fmt#Format(do_astcheck) abort
8077
syntax sync fromstart
8178
endfunction
8279

83-
function! zig#fmt#Astcheck() abort
84-
if !executable('zig')
85-
echohl Error | echomsg "no zig binary found in PATH" | echohl None
86-
return
87-
endif
88-
89-
let cmdline = 'zig ast-check'
90-
let current_buf = bufnr('')
91-
if exists('*systemlist')
92-
silent let out = systemlist(cmdline, current_buf)
93-
else
94-
silent let out = split(system(cmdline, current_buf))
95-
endif
96-
let err = v:shell_error
97-
98-
if err == 0
99-
call setloclist(0, [], 'r')
100-
lclose
101-
else
102-
let errors = s:parse_errors(expand('%'), out)
103-
104-
call setloclist(0, [], 'r', {
105-
\ 'title': 'Errors',
106-
\ 'items': errors,
107-
\ })
108-
109-
let max_win_height = get(g:, 'zig_fmt_max_window_height', 5)
110-
let win_height = min([max_win_height, len(errors)])
111-
execute 'silent! lwindow ' . win_height
112-
endif
113-
endfunction
114-
11580
" parse_errors parses the given errors and returns a list of parsed errors
11681
function! s:parse_errors(filename, lines) abort
11782
" list of errors to be put into location list

plugin/zig.vim

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,15 @@ if exists("g:zig_loaded")
33
endif
44
let g:zig_loaded = 1
55

6-
function! s:on_save()
7-
if get(g:, "zig_fmt_ast_check_autosave", 0)
8-
call zig#fmt#Format(v:true)
9-
else
10-
if get(g:, "zig_fmt_autosave", 1)
11-
call zig#fmt#Format(v:false)
12-
endif
13-
if get(g:, "zig_ast_check_autosave", 1)
14-
call zig#fmt#Astcheck()
15-
endif
6+
function! s:fmt_autosave()
7+
if get(g:, "zig_fmt_autosave", 1)
8+
call zig#fmt#Format()
169
endif
1710
endfunction
1811

1912
augroup vim-zig
2013
autocmd!
21-
autocmd BufWritePre *.zig call s:on_save()
14+
autocmd BufWritePre *.zig call s:fmt_autosave()
2215
augroup end
2316

2417
" vim: sw=2 ts=2 et

0 commit comments

Comments
 (0)