]> git.madduck.net Git - etc/vim.git/blob - autoload/ale/handlers/sml.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:

Squashed '.vim/bundle/ale/' content from commit 22185c4c
[etc/vim.git] / autoload / ale / handlers / sml.vim
1 " Author: Jake Zimmerman <jake@zimmerman.io>
2 " Description: Shared functions for SML linters
3
4 " The glob to use for finding the .cm file.
5 "
6 " See :help ale-sml-smlnj for more information.
7 call ale#Set('sml_smlnj_cm_file', '*.cm')
8
9 function! ale#handlers#sml#GetCmFile(buffer) abort
10     let l:pattern = ale#Var(a:buffer, 'sml_smlnj_cm_file')
11     let l:as_list = 1
12
13     let l:cmfile = ''
14
15     for l:path in ale#path#Upwards(expand('#' . a:buffer . ':p:h'))
16         let l:results = glob(l:path . '/' . l:pattern, 0, l:as_list)
17
18         if len(l:results) > 0
19             " If there is more than one CM file, we take the first one
20             " See :help ale-sml-smlnj for how to configure this.
21             let l:cmfile = l:results[0]
22         endif
23     endfor
24
25     return l:cmfile
26 endfunction
27
28 " Only one of smlnj or smlnj-cm can be enabled at a time.
29 function! s:GetExecutable(buffer, source) abort
30     if ale#handlers#sml#GetCmFile(a:buffer) is# ''
31         " No CM file found; only allow single-file mode to be enabled
32         if a:source is# 'smlnj-file'
33             return 'sml'
34         elseif a:source is# 'smlnj-cm'
35             return ''
36         endif
37     else
38         " Found a CM file; only allow cm-file mode to be enabled
39         if a:source is# 'smlnj-file'
40             return ''
41         elseif a:source is# 'smlnj-cm'
42             return 'sml'
43         endif
44     endif
45 endfunction
46
47 function! ale#handlers#sml#GetExecutableSmlnjCm(buffer) abort
48     return s:GetExecutable(a:buffer, 'smlnj-cm')
49 endfunction
50
51 function! ale#handlers#sml#GetExecutableSmlnjFile(buffer) abort
52     return s:GetExecutable(a:buffer, 'smlnj-file')
53 endfunction
54
55 function! ale#handlers#sml#Handle(buffer, lines) abort
56     " Try to match basic sml errors
57     " TODO(jez) We can get better errorfmt strings from Syntastic
58     let l:out = []
59     let l:pattern = '^\(.*\)\:\([0-9\.]\+\)\ \(\w\+\)\:\ \(.*\)'
60     let l:pattern2 = '^\(.*\)\:\([0-9]\+\)\.\?\([0-9]\+\).* \(\(Warning\|Error\): .*\)'
61
62     for l:line in a:lines
63         let l:match2 = matchlist(l:line, l:pattern2)
64
65         if len(l:match2) != 0
66             if l:match2[1] =~# 'stdIn$'
67                 let l:loc = {'bufnr': a:buffer}
68             else
69                 let l:loc = {'filename': l:match2[1]}
70             endif
71
72             call add(l:out, extend(l:loc, {
73             \   'lnum': l:match2[2] + 0,
74             \   'col' : l:match2[3] - 1,
75             \   'text': l:match2[4],
76             \   'type': l:match2[4] =~# '^Warning' ? 'W' : 'E',
77             \}))
78             continue
79         endif
80
81         let l:match = matchlist(l:line, l:pattern)
82
83         if len(l:match) != 0
84             if l:match[1] =~# 'stdIn$'
85                 let l:loc = {'bufnr': a:buffer}
86             else
87                 let l:loc = {'filename': l:match[1]}
88             endif
89
90             call add(l:out, extend(l:loc, {
91             \   'lnum': l:match[2] + 0,
92             \   'text': l:match[3] . ': ' . l:match[4],
93             \   'type': l:match[3] is# 'error' ? 'E' : 'W',
94             \}))
95             continue
96         endif
97     endfor
98
99     return l:out
100 endfunction
101
102 " vim:ts=4:sts=4:sw=4