summaryrefslogtreecommitdiff
path: root/ale_linters/nix/nix.vim
diff options
context:
space:
mode:
authorMaximilian Bosch <maximilian@mbosch.me>2020-07-06 20:01:52 +0200
committerMaximilian Bosch <maximilian@mbosch.me>2021-01-24 22:54:02 +0100
commit72dbd7f648e90c1a9e73234719458c73b0b415dc (patch)
treec1c1aafb9835fb686e23e3ee999e82b61f5eb422 /ale_linters/nix/nix.vim
parent9a1e91e075abf386e8c6fd620ec0835e566a7db1 (diff)
downloadale-72dbd7f648e90c1a9e73234719458c73b0b415dc.zip
Update error-parser for `nix-instantiate` on Nix 2.4+
In the (unreleased) Nix 2.4 the error-messages have been reformatted[1]. This patch aims to retain proper `.nix`-support in `ale`, for both stable Nix (2.3 and older) and unstable Nix (2.4 and newer). [1] https://github.com/NixOS/nix/pull/3590
Diffstat (limited to 'ale_linters/nix/nix.vim')
-rw-r--r--ale_linters/nix/nix.vim57
1 files changed, 47 insertions, 10 deletions
diff --git a/ale_linters/nix/nix.vim b/ale_linters/nix/nix.vim
index 0a0c5c3e..3d91a9ec 100644
--- a/ale_linters/nix/nix.vim
+++ b/ale_linters/nix/nix.vim
@@ -1,18 +1,51 @@
" Author: Alistair Bill <@alibabzo>
+" Author: Maximilian Bosch <maximilian@mbosch.me>
" Description: nix-instantiate linter for nix files
+function! ale_linters#nix#nix#Command(buffer, output, meta) abort
+ let l:version = a:output[0][22:]
+
+ if l:version =~# '^\(2.4\|3\).*'
+ return 'nix-instantiate --log-format internal-json --parse -'
+ else
+ return 'nix-instantiate --parse -'
+ endif
+endfunction
+
function! ale_linters#nix#nix#Handle(buffer, lines) abort
- let l:pattern = '^\(.\+\): \(.\+\), at .*:\(\d\+\):\(\d\+\)$'
let l:output = []
- for l:match in ale#util#GetMatches(a:lines, l:pattern)
- call add(l:output, {
- \ 'lnum': l:match[3] + 0,
- \ 'col': l:match[4] + 0,
- \ 'text': l:match[1] . ': ' . l:match[2],
- \ 'type': l:match[1] =~# '^error' ? 'E' : 'W',
- \})
- endfor
+ if empty(a:lines)
+ return l:output
+ endif
+
+ if a:lines[0] =~# '^@nix .*'
+ for l:line in a:lines
+ if l:line =~# '^@nix .*'
+ let l:result = json_decode(strpart(l:line, 4))
+
+ if has_key(l:result, 'column')
+ call add(l:output, {
+ \ 'type': 'E',
+ \ 'lnum': l:result.line,
+ \ 'col': l:result.column,
+ \ 'text': l:result.raw_msg
+ \})
+ endif
+ endif
+ endfor
+ else
+ let l:pattern = '^\(.\+\): \(.\+\) at .*:\(\d\+\):\(\d\+\)$'
+
+ for l:match in ale#util#GetMatches(a:lines, l:pattern)
+ call add(l:output, {
+ \ 'lnum': l:match[3] + 0,
+ \ 'col': l:match[4] + 0,
+ \ 'text': l:match[1] . ': ' . substitute(l:match[2], ',$', '', ''),
+ \ 'type': l:match[1] =~# '^error' ? 'E' : 'W',
+ \})
+ endfor
+ endif
return l:output
endfunction
@@ -21,6 +54,10 @@ call ale#linter#Define('nix', {
\ 'name': 'nix',
\ 'output_stream': 'stderr',
\ 'executable': 'nix-instantiate',
-\ 'command': 'nix-instantiate --parse -',
+\ 'command': {buffer -> ale#command#Run(
+\ buffer,
+\ 'nix-instantiate --version',
+\ function('ale_linters#nix#nix#Command')
+\ )},
\ 'callback': 'ale_linters#nix#nix#Handle',
\})