]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/ale_linters/nim/nimcheck.vim

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Merge commit '76265755a1add77121c8f9dabb3e9bb70fe9a972' as '.vim/bundle/ale'
[etc/vim.git] / .vim / bundle / ale / ale_linters / nim / nimcheck.vim
1 " Author: Baabelfish
2 " Description: Typechecking for nim files
3
4 let s:end_col_patterns = [
5 \   '\v''([^'']+)'' is declared but not used.*',
6 \   '\videntifier expected, but found ''([^'']+)''',
7 \   '\vimported and not used: ''([^'']+)''.*',
8 \   '\vundeclared identifier: ''([^'']+)''',
9 \   '\v''([^'']+)'' cannot be assigned to',
10 \   '\vredefinition of ''([^'']+)'';',
11 \]
12
13 function! ale_linters#nim#nimcheck#Handle(buffer, lines) abort
14     let l:buffer_filename = fnamemodify(bufname(a:buffer), ':p:t')
15     let l:pattern = '^\(.\+\.nim\)(\(\d\+\), \(\d\+\)) \(.\+\)'
16     let l:output = []
17
18     for l:match in ale#util#GetMatches(a:lines, l:pattern)
19         " Only show errors of the current buffer
20         " NOTE: Checking filename only is OK because nim enforces unique
21         "       module names.
22         let l:temp_buffer_filename = fnamemodify(l:match[1], ':p:t')
23
24         if l:buffer_filename isnot# '' && l:temp_buffer_filename isnot# l:buffer_filename
25             continue
26         endif
27
28         let l:item = {
29         \   'lnum': l:match[2] + 0,
30         \   'col': l:match[3] + 0,
31         \   'text': l:match[4],
32         \   'type': 'W',
33         \}
34
35         " Extract error type from message of type 'Error: Some error message'
36         let l:error_match = matchlist(l:item.text, '^\(.\{-}\): \(.\+\)$')
37
38         if !empty(l:error_match)
39             if l:error_match[1] is# 'Error'
40                 let l:item.type = 'E'
41                 let l:item.text = l:error_match[2]
42             elseif l:error_match[1] is# 'Warning'
43             \|| l:error_match[1] is# 'Hint'
44                 let l:item.text = l:error_match[2]
45             endif
46         endif
47
48         let l:code_match = matchlist(l:item.text, '\v^(.+) \[([^ \[]+)\]$')
49
50         if !empty(l:code_match)
51             let l:item.text = l:code_match[1]
52             let l:item.code = l:code_match[2]
53         endif
54
55         " Find position end_col.
56         for l:col_match in ale#util#GetMatches(l:item.text, s:end_col_patterns)
57             let l:item.end_col = l:item.col + len(l:col_match[1]) - 1
58         endfor
59
60         call add(l:output, l:item)
61     endfor
62
63     return l:output
64 endfunction
65
66
67 function! ale_linters#nim#nimcheck#GetCommand(buffer) abort
68     return 'nim check --verbosity:0 --colors:off --listFullPaths %s'
69 endfunction
70
71
72 call ale#linter#Define('nim', {
73 \    'name': 'nimcheck',
74 \    'executable': 'nim',
75 \    'output_stream': 'both',
76 \    'command': function('ale_linters#nim#nimcheck#GetCommand'),
77 \    'callback': 'ale_linters#nim#nimcheck#Handle',
78 \    'lint_file': 1,
79 \})