|
| 1 | +" Author: Ben Boeckel <github@me.benboeckel.net> |
| 2 | +" Description: TOML Formatter / Linter / Language Server |
| 3 | + |
| 4 | +callale#Set('toml_tombi_executable','tombi') |
| 5 | +callale#Set('toml_tombi_lsp_options','') |
| 6 | + |
| 7 | +function!ale_linters#toml#tombi#GetCommand(buffer)abort |
| 8 | +letl:options=ale#Var(a:buffer,'toml_tombi_lsp_options') |
| 9 | + |
| 10 | +return'%e lsp' |
| 11 | +\ . (empty(l:options) ?'' :'' .l:options) |
| 12 | +endfunction |
| 13 | + |
| 14 | +function!ale_linters#toml#tombi#GetProjectRoot(buffer)abort |
| 15 | +" Try to find nearest tombi.toml |
| 16 | +letl:tombiconfig_file=ale#path#FindNearestFile(a:buffer,'tombi.toml') |
| 17 | + |
| 18 | +if!empty(l:tombiconfig_file) |
| 19 | +returnfnamemodify(l:tombiconfig_file .'/',':p:h:h') |
| 20 | +endif |
| 21 | + |
| 22 | +" Try to find nearest pyproject.toml |
| 23 | +letl:pyproject_file=ale#path#FindNearestFile(a:buffer,'pyproject.toml') |
| 24 | + |
| 25 | +if!empty(l:pyproject_file) |
| 26 | +returnfnamemodify(l:pyproject_file .'/',':p:h:h') |
| 27 | +endif |
| 28 | + |
| 29 | +" Try to find nearest `git` directory |
| 30 | +letl:gitdir=ale#path#FindNearestFile(a:buffer,'.git') |
| 31 | + |
| 32 | +if!empty(l:gitdir) |
| 33 | +returnfnamemodify(l:gitdir .'/',':p:h:h') |
| 34 | +endif |
| 35 | + |
| 36 | +return'' |
| 37 | +endfunction |
| 38 | + |
| 39 | +callale#linter#Define('toml', { |
| 40 | +\'name':'tombi', |
| 41 | +\'lsp':'stdio', |
| 42 | +\'executable': {b->ale#Var(b,'toml_tombi_executable')}, |
| 43 | +\'command':function('ale_linters#toml#tombi#GetCommand'), |
| 44 | +\'project_root':function('ale_linters#toml#tombi#GetProjectRoot'), |
| 45 | +\}) |