|
| 1 | +if !exists('g:ale_swift_swiftpm_executable') |
| 2 | + let g:ale_swift_swiftpm_executable = 'swift' |
| 3 | +endif |
| 4 | + |
| 5 | +if !exists('g:ale_swift_swiftpm_arguments') |
| 6 | + let g:ale_swift_swiftpm_arguments = 'build' |
| 7 | +endif |
| 8 | + |
| 9 | +function! ale_linters#swift#swiftpm#GetExecutable(buffer) |
| 10 | + if !filereadable('Package.swift') |
| 11 | + return '' |
| 12 | + endif |
| 13 | + |
| 14 | + return g:ale_swift_swiftpm_executable |
| 15 | +endfunction |
| 16 | + |
| 17 | +function! ale_linters#swift#swiftpm#GetCommand(buffer) |
| 18 | + return g:ale_swift_swiftpm_executable |
| 19 | + \ . ' ' |
| 20 | + \ . g:ale_swift_swiftpm_arguments |
| 21 | +endfunction |
| 22 | + |
| 23 | +function! ale_linters#swift#swiftpm#Handle(buffer, lines) |
| 24 | + " Match and ignore file path (anything but :) |
| 25 | + " Match and capture line number |
| 26 | + " Match and capture column number |
| 27 | + " Match and capture anything in the message |
| 28 | + let l:pattern = '^[^:]\+:\(\d\+\):\(\d\+\):\s*error:\s*\(.*\)$' |
| 29 | + let l:output = [] |
| 30 | + |
| 31 | + for l:line in a:lines |
| 32 | + let l:match = matchlist(l:line, l:pattern) |
| 33 | + |
| 34 | + if len(l:match) == 0 |
| 35 | + continue |
| 36 | + endif |
| 37 | + |
| 38 | + let l:line_number = l:match[1] |
| 39 | + let l:column = l:match[2] |
| 40 | + let l:text = l:match[3] |
| 41 | + |
| 42 | + call add(l:output, { |
| 43 | + \ 'bufnr': a:buffer, |
| 44 | + \ 'lnum': l:line_number, |
| 45 | + \ 'vcol': 0, |
| 46 | + \ 'col': l:column, |
| 47 | + \ 'text': l:text, |
| 48 | + \ 'type': 'E', |
| 49 | + \ }) |
| 50 | + endfor |
| 51 | + |
| 52 | + return l:output |
| 53 | +endfunction |
| 54 | + |
| 55 | +call ale#linter#Define('swift', { |
| 56 | + \ 'name': 'swiftpm', |
| 57 | + \ 'executable_callback': 'ale_linters#swift#swiftpm#GetExecutable', |
| 58 | + \ 'command_callback': 'ale_linters#swift#swiftpm#GetCommand', |
| 59 | + \ 'callback': 'ale_linters#swift#swiftpm#Handle', |
| 60 | + \ }) |
0 commit comments