|
| 1 | +" Author: Evan Chen <evan@evanchen.cc> |
| 2 | +" Description: Fast Markdown linter and formatter written in Rust |
| 3 | + |
| 4 | + |
| 5 | +call ale#Set('markdown_rumdl_executable', 'rumdl') |
| 6 | +call ale#Set('markdown_rumdl_options', '') |
| 7 | + |
| 8 | +function! ale_linters#markdown#rumdl#GetProjectRoot(buffer) abort |
| 9 | + let l:dotconfig = ale#path#FindNearestFile(a:buffer, '.rumdl.toml') |
| 10 | + let l:config = ale#path#FindNearestFile(a:buffer, 'rumdl.toml') |
| 11 | + |
| 12 | + if !empty(l:dotconfig) && !empty(l:config) |
| 13 | + let l:nearest = len(l:dotconfig) >= len(l:config) ? l:dotconfig : l:config |
| 14 | + |
| 15 | + return fnamemodify(l:nearest, ':h') |
| 16 | + elseif !empty(l:dotconfig) |
| 17 | + return fnamemodify(l:dotconfig, ':h') |
| 18 | + elseif !empty(l:config) |
| 19 | + return fnamemodify(l:config, ':h') |
| 20 | + endif |
| 21 | + |
| 22 | + " Try to find nearest pyproject.toml |
| 23 | + let l:pyproject_file = ale#path#FindNearestFile(a:buffer, 'pyproject.toml') |
| 24 | + |
| 25 | + if !empty(l:pyproject_file) |
| 26 | + return fnamemodify(l:pyproject_file . '/', ':p:h:h') |
| 27 | + endif |
| 28 | + |
| 29 | + " Try to find nearest `git` directory |
| 30 | + let l:gitdir = ale#path#FindNearestFile(a:buffer, '.git') |
| 31 | + |
| 32 | + if !empty(l:gitdir) |
| 33 | + return fnamemodify(l:gitdir . '/', ':p:h:h') |
| 34 | + endif |
| 35 | + |
| 36 | + return fnamemodify(bufname(a:buffer), ':p:h') |
| 37 | +endfunction |
| 38 | + |
| 39 | +call ale#linter#Define('markdown', { |
| 40 | +\ 'name': 'rumdl', |
| 41 | +\ 'lsp': 'stdio', |
| 42 | +\ 'executable': {b -> ale#Var(b, 'markdown_rumdl_executable')}, |
| 43 | +\ 'command': {b -> ale#Escape(ale#Var(b, 'markdown_rumdl_executable')) |
| 44 | +\ . ' server --stdio' |
| 45 | +\ . ale#Pad(ale#Var(b, 'markdown_rumdl_options'))}, |
| 46 | +\ 'project_root': function('ale_linters#markdown#rumdl#GetProjectRoot'), |
| 47 | +\ 'language': 'markdown', |
| 48 | +\}) |
0 commit comments