|
| 1 | +" Author: Vivian De Smedt <vds2212@gmail.com>, Adrian Vollmer <computerfluesterer@protonmail.com> |
| 2 | +" Description: Adds support for djlint |
| 3 | +" |
| 4 | +function! ale#handlers#djlint#GetExecutable(buffer) abort |
| 5 | + return ale#Var(a:buffer, 'html_djlint_executable') |
| 6 | +endfunction |
| 7 | + |
| 8 | +function! ale#handlers#djlint#GetCommand(buffer) abort |
| 9 | + let l:executable = ale#handlers#djlint#GetExecutable(a:buffer) |
| 10 | + |
| 11 | + let l:options = ale#Var(a:buffer, 'html_djlint_options') |
| 12 | + |
| 13 | + let l:profile = '' |
| 14 | + let l:filetypes = split(getbufvar(a:buffer, '&filetype'), '\.') |
| 15 | + |
| 16 | + " Append the --profile flag depending on the current filetype (unless it's |
| 17 | + " already set in g:html_djlint_options). |
| 18 | + if match(l:options, '--profile') == -1 |
| 19 | + let l:djlint_profiles = { |
| 20 | + \ 'html': 'html', |
| 21 | + \ 'htmldjango': 'django', |
| 22 | + \ 'jinja': 'jinja', |
| 23 | + \ 'nunjucks': 'nunjucks', |
| 24 | + \ 'handlebars': 'handlebars', |
| 25 | + \ 'gohtmltmpl': 'golang', |
| 26 | + \ 'htmlangular': 'angular', |
| 27 | + \} |
| 28 | + |
| 29 | + for l:filetype in l:filetypes |
| 30 | + if has_key(l:djlint_profiles, l:filetype) |
| 31 | + let l:profile = l:djlint_profiles[l:filetype] |
| 32 | + break |
| 33 | + endif |
| 34 | + endfor |
| 35 | + endif |
| 36 | + |
| 37 | + if !empty(l:profile) |
| 38 | + let l:options = (!empty(l:options) ? l:options . ' ' : '') . '--profile ' . l:profile |
| 39 | + endif |
| 40 | + |
| 41 | + return ale#Escape(l:executable) |
| 42 | + \ . (!empty(l:options) ? ' ' . l:options : '') . ' %s' |
| 43 | +endfunction |
| 44 | + |
| 45 | +function! ale#handlers#djlint#Handle(buffer, lines) abort |
| 46 | + let l:output = [] |
| 47 | + let l:pattern = '\v^([A-Z]\d+) (\d+):(\d+) (.*)$' |
| 48 | + let l:i = 0 |
| 49 | + |
| 50 | + for l:match in ale#util#GetMatches(a:lines, l:pattern) |
| 51 | + let l:i += 1 |
| 52 | + let l:item = { |
| 53 | + \ 'lnum': l:match[2] + 0, |
| 54 | + \ 'col': l:match[3] + 0, |
| 55 | + \ 'vcol': 1, |
| 56 | + \ 'text': l:match[4], |
| 57 | + \ 'code': l:match[1], |
| 58 | + \ 'type': 'W', |
| 59 | + \} |
| 60 | + call add(l:output, l:item) |
| 61 | + endfor |
| 62 | + |
| 63 | + return l:output |
| 64 | +endfunction |
0 commit comments