]> git.madduck.net Git - etc/vim.git/blob - autoload/ale/handlers/redpen.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 / redpen.vim
1 " Author: rhysd https://rhysd.github.io
2 " Description: Redpen, a proofreading tool (http://redpen.cc)
3
4 function! ale#handlers#redpen#HandleRedpenOutput(buffer, lines) abort
5     " Only one file was passed to redpen. So response array has only one
6     " element.
7     let l:res = get(ale#util#FuzzyJSONDecode(a:lines, []), 0, {})
8     let l:output = []
9
10     for l:err in get(l:res, 'errors', [])
11         let l:item = {
12         \   'text': l:err.message,
13         \   'type': 'W',
14         \   'code': l:err.validator,
15         \}
16
17         if has_key(l:err, 'startPosition')
18             let l:item.lnum = l:err.startPosition.lineNum
19             let l:item.col = l:err.startPosition.offset + 1
20
21             if has_key(l:err, 'endPosition')
22                 let l:item.end_lnum = l:err.endPosition.lineNum
23                 let l:item.end_col = l:err.endPosition.offset
24             endif
25         else
26             " Fallback to a whole sentence region when a region is not
27             " specified by the error.
28             let l:item.lnum = l:err.lineNum
29             let l:item.col = l:err.sentenceStartColumnNum + 1
30         endif
31
32         " Adjust column number for multibyte string
33         let l:line = getline(l:item.lnum)
34
35         if l:line is# ''
36             let l:line = l:err.sentence
37         endif
38
39         let l:line = split(l:line, '\zs')
40
41         if l:item.col >= 2
42             let l:col = 0
43
44             for l:strlen in map(l:line[0:(l:item.col - 2)], 'strlen(v:val)')
45                 let l:col = l:col + l:strlen
46             endfor
47
48             let l:item.col = l:col + 1
49         endif
50
51         if has_key(l:item, 'end_col')
52             let l:col = 0
53
54             for l:strlen in map(l:line[0:(l:item.end_col - 1)], 'strlen(v:val)')
55                 let l:col = l:col + l:strlen
56             endfor
57
58             let l:item.end_col = l:col
59         endif
60
61         call add(l:output, l:item)
62     endfor
63
64     return l:output
65 endfunction