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.
1 " Author: Vincent (wahrwolf [at] wolfpit.net)
2 " Description: languagetool for markdown files
4 call ale#Set('languagetool_executable', 'languagetool')
5 call ale#Set('languagetool_options', '--autoDetect')
7 function! ale#handlers#languagetool#GetExecutable(buffer) abort
8 return ale#Var(a:buffer, 'languagetool_executable')
11 function! ale#handlers#languagetool#GetCommand(buffer) abort
12 let l:executable = ale#handlers#languagetool#GetExecutable(a:buffer)
13 let l:options = ale#Var(a:buffer, 'languagetool_options')
15 return ale#Escape(l:executable)
16 \ . (empty(l:options) ? '' : ' ' . l:options) . ' %s'
19 function! ale#handlers#languagetool#HandleOutput(buffer, lines) abort
21 " 1.) Line 5, column 1, Rule ID:
22 let l:head_pattern = '^\v.+.\) Line (\d+), column (\d+), Rule ID. (.+)$'
23 let l:head_matches = ale#util#GetMatches(a:lines, l:head_pattern)
26 " Message: Did you forget a comma after a conjunctive/linking adverb?
27 let l:message_pattern = '^\vMessage. (.+)$'
28 let l:message_matches = ale#util#GetMatches(a:lines, l:message_pattern)
32 let l:markers_pattern = '^\v *(\^+) *$'
33 let l:markers_matches = ale#util#GetMatches(a:lines, l:markers_pattern)
38 " Okay tbh I was to lazy to figure out a smarter solution here
39 " We just check that the arrays are same sized and merge everything
43 while l:i < len(l:head_matches)
45 \ (len(l:head_matches) == len(l:markers_matches))
46 \ && (len(l:head_matches) == len(l:message_matches))
49 \ 'lnum' : str2nr(l:head_matches[l:i][1]),
50 \ 'col' : str2nr(l:head_matches[l:i][2]),
51 \ 'end_col' : str2nr(l:head_matches[l:i][2]) + len(l:markers_matches[l:i][1])-1,
53 \ 'code' : l:head_matches[l:i][3],
54 \ 'text' : l:message_matches[l:i][1]
56 call add(l:output, l:item)
63 " Define the languagetool linter for a given filetype.
65 " - Add language detection settings based on user env (for mothertongue)
67 " - Add config options for rules
68 function! ale#handlers#languagetool#DefineLinter(filetype) abort
69 call ale#linter#Define(a:filetype, {
70 \ 'name': 'languagetool',
71 \ 'executable': function('ale#handlers#languagetool#GetExecutable'),
72 \ 'command': function('ale#handlers#languagetool#GetCommand'),
73 \ 'output_stream': 'stdout',
74 \ 'callback': 'ale#handlers#languagetool#HandleOutput',