summaryrefslogtreecommitdiff
path: root/ale_linters/v
diff options
context:
space:
mode:
authorfiatjaf <fiatjaf@alhur.es>2021-03-26 03:38:57 -0300
committerGitHub <noreply@github.com>2021-03-26 15:38:57 +0900
commit655f0070cd2ce575f81092d1faac739fd116b515 (patch)
treea4356862b0137006eaed26706bacdd3026fcea22 /ale_linters/v
parentb1f95dc4fb15efb1d5238845c99548f2906e2ba3 (diff)
downloadale-655f0070cd2ce575f81092d1faac739fd116b515.zip
Add support for V: "v" (compiler) and "vfmt" fixer. (#3622)
* v: add "v fmt" fixer. * v: add "v" (build) linter. * v: fix vlint complaints and add documentation. * v: add tests. * v: use ale#Pad().
Diffstat (limited to 'ale_linters/v')
-rw-r--r--ale_linters/v/v.vim82
1 files changed, 82 insertions, 0 deletions
diff --git a/ale_linters/v/v.vim b/ale_linters/v/v.vim
new file mode 100644
index 00000000..afa98c56
--- /dev/null
+++ b/ale_linters/v/v.vim
@@ -0,0 +1,82 @@
+" Author: fiatjaf <fiatjaf@alhur.es>
+" Description: v build for V files
+
+call ale#Set('v_v_executable', 'v')
+call ale#Set('v_v_options', '')
+
+function! ale_linters#v#v#GetCommand(buffer) abort
+ let l:options = ale#Var(a:buffer, 'v_v_options')
+
+ " Run v in local directory with relative path
+ let l:command = ale#Var(a:buffer, 'v_v_executable')
+ \ . ale#Pad(l:options)
+ \ . ' .' . ' -o /tmp/vim-ale-v'
+
+ return l:command
+endfunction
+
+function! ale_linters#v#v#Handler(buffer, lines) abort
+ let l:dir = expand('#' . a:buffer . ':p:h')
+ let l:output = []
+
+ " Matches patterns like the following:
+ "
+ " ./const.v:4:3: warning: const names cannot contain uppercase letters, use snake_case instead
+ " 2 |
+ " 3 | const (
+ " 4 | BUTTON_TEXT = 'OK'
+ " | ~~~~~~~~~~~
+ " 5 | )
+ " ./main.v:4:8: warning: module 'os' is imported but never used
+ " 2 |
+ " 3 | import ui
+ " 4 | import os
+ " | ~~
+ " 5 |
+ " 6 | const (
+ " ./main.v:20:10: error: undefined ident: `win_widt`
+ " 18 | mut app := &App{}
+ " 19 | app.window = ui.window({
+ " 20 | width: win_widt
+ " | ~~~~~~~~
+ " 21 | height: win_height
+ " 22 | title: 'Counter'
+ let l:current = {}
+
+ for l:line in a:lines
+ " matches basic error description
+ let l:match = matchlist(l:line,
+ \ '\([^:]\+\):\([^:]\+\):\([^:]\+\): \([^:]\+\): \(.*\)')
+
+ if !empty(l:match)
+ let l:current = {
+ \ 'filename': ale#path#GetAbsPath(l:dir, l:match[1]),
+ \ 'lnum': l:match[2] + 0,
+ \ 'col': l:match[3] + 0,
+ \ 'text': l:match[5],
+ \ 'type': l:match[4] is# 'error' ? 'E' : 'W',
+ \}
+ call add(l:output, l:current)
+ continue
+ endif
+
+ " try to get information about the ending column
+ let l:tildematch = matchstr(l:line, '\~\+')
+
+ if !empty(l:tildematch)
+ let l:current['end_col'] = l:current['col'] + len(l:tildematch)
+ endif
+ endfor
+
+ return l:output
+endfunction
+
+call ale#linter#Define('v', {
+\ 'name': 'v',
+\ 'aliases': [],
+\ 'executable': {b -> ale#Var(b, 'v_v_executable')},
+\ 'command': function('ale_linters#v#v#GetCommand'),
+\ 'output_stream': 'stderr',
+\ 'callback': 'ale_linters#v#v#Handler',
+\ 'lint_file': 1,
+\})