mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-08 21:44:47 +08:00
tombi: support its LSP (#5022)
* tombi: support its LSP * tombi: support linting and formatting
This commit is contained in:
45
ale_linters/toml/tombi.vim
Normal file
45
ale_linters/toml/tombi.vim
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
" Author: Ben Boeckel <github@me.benboeckel.net>
|
||||||
|
" Description: TOML Formatter / Linter / Language Server
|
||||||
|
|
||||||
|
call ale#Set('toml_tombi_executable', 'tombi')
|
||||||
|
call ale#Set('toml_tombi_lsp_options', '')
|
||||||
|
|
||||||
|
function! ale_linters#toml#tombi#GetCommand(buffer) abort
|
||||||
|
let l:options = ale#Var(a:buffer, 'toml_tombi_lsp_options')
|
||||||
|
|
||||||
|
return '%e lsp'
|
||||||
|
\ . (empty(l:options) ? '' : ' ' . l:options)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! ale_linters#toml#tombi#GetProjectRoot(buffer) abort
|
||||||
|
" Try to find nearest tombi.toml
|
||||||
|
let l:tombiconfig_file = ale#path#FindNearestFile(a:buffer, 'tombi.toml')
|
||||||
|
|
||||||
|
if !empty(l:tombiconfig_file)
|
||||||
|
return fnamemodify(l:tombiconfig_file . '/', ':p:h:h')
|
||||||
|
endif
|
||||||
|
|
||||||
|
" Try to find nearest pyproject.toml
|
||||||
|
let l:pyproject_file = ale#path#FindNearestFile(a:buffer, 'pyproject.toml')
|
||||||
|
|
||||||
|
if !empty(l:pyproject_file)
|
||||||
|
return fnamemodify(l:pyproject_file . '/', ':p:h:h')
|
||||||
|
endif
|
||||||
|
|
||||||
|
" Try to find nearest `git` directory
|
||||||
|
let l:gitdir = ale#path#FindNearestFile(a:buffer, '.git')
|
||||||
|
|
||||||
|
if !empty(l:gitdir)
|
||||||
|
return fnamemodify(l:gitdir . '/', ':p:h:h')
|
||||||
|
endif
|
||||||
|
|
||||||
|
return ''
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
call ale#linter#Define('toml', {
|
||||||
|
\ 'name': 'tombi',
|
||||||
|
\ 'lsp': 'stdio',
|
||||||
|
\ 'executable': {b -> ale#Var(b, 'toml_tombi_executable')},
|
||||||
|
\ 'command': function('ale_linters#toml#tombi#GetCommand'),
|
||||||
|
\ 'project_root': function('ale_linters#toml#tombi#GetProjectRoot'),
|
||||||
|
\})
|
||||||
@@ -732,6 +732,16 @@ let s:default_registry = {
|
|||||||
\ 'suggested_filetypes': ['roc'],
|
\ 'suggested_filetypes': ['roc'],
|
||||||
\ 'description': 'Annotates all top-level definitions in Roc files.',
|
\ 'description': 'Annotates all top-level definitions in Roc files.',
|
||||||
\ },
|
\ },
|
||||||
|
\ 'tombi_format': {
|
||||||
|
\ 'function': 'ale#fixers#tombi_format#Fix',
|
||||||
|
\ 'suggested_filetypes': ['toml'],
|
||||||
|
\ 'description': 'Formats TOML files',
|
||||||
|
\ },
|
||||||
|
\ 'tombi_lint': {
|
||||||
|
\ 'function': 'ale#fixers#tombi_lint#Fix',
|
||||||
|
\ 'suggested_filetypes': ['toml'],
|
||||||
|
\ 'description': 'Lints TOML files',
|
||||||
|
\ },
|
||||||
\}
|
\}
|
||||||
|
|
||||||
" Reset the function registry to the default entries.
|
" Reset the function registry to the default entries.
|
||||||
|
|||||||
16
autoload/ale/fixers/tombi_format.vim
Normal file
16
autoload/ale/fixers/tombi_format.vim
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
" Author: Ben Boeckel <github@me.benboeckel.net>
|
||||||
|
" Description: Integration of tombi formatting with ALE.
|
||||||
|
|
||||||
|
call ale#Set('toml_tombi_executable', 'tombi')
|
||||||
|
call ale#Set('toml_tombi_format_options', '')
|
||||||
|
|
||||||
|
function! ale#fixers#tombi_format#Fix(buffer) abort
|
||||||
|
let l:executable = ale#Var(a:buffer, 'toml_tombi_executable')
|
||||||
|
let l:options = ale#Var(a:buffer, 'toml_tombi_format_options')
|
||||||
|
|
||||||
|
return {
|
||||||
|
\ 'command': ale#Escape(l:executable)
|
||||||
|
\ . ' format'
|
||||||
|
\ . (empty(l:options) ? '' : ' ' . l:options),
|
||||||
|
\}
|
||||||
|
endfunction
|
||||||
16
autoload/ale/fixers/tombi_lint.vim
Normal file
16
autoload/ale/fixers/tombi_lint.vim
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
" Author: Ben Boeckel <github@me.benboeckel.net>
|
||||||
|
" Description: Integration of tombi linting with ALE.
|
||||||
|
|
||||||
|
call ale#Set('toml_tombi_executable', 'tombi')
|
||||||
|
call ale#Set('toml_tombi_lint_options', '')
|
||||||
|
|
||||||
|
function! ale#fixers#tombi_lint#Fix(buffer) abort
|
||||||
|
let l:executable = ale#Var(a:buffer, 'toml_tombi_executable')
|
||||||
|
let l:options = ale#Var(a:buffer, 'toml_tombi_lint_options')
|
||||||
|
|
||||||
|
return {
|
||||||
|
\ 'command': ale#Escape(l:executable)
|
||||||
|
\ . ' lint'
|
||||||
|
\ . (empty(l:options) ? '' : ' ' . l:options),
|
||||||
|
\}
|
||||||
|
endfunction
|
||||||
@@ -698,6 +698,7 @@ Notes:
|
|||||||
* `thriftcheck`
|
* `thriftcheck`
|
||||||
* TOML
|
* TOML
|
||||||
* `dprint`
|
* `dprint`
|
||||||
|
* `tombi`
|
||||||
* TypeScript
|
* TypeScript
|
||||||
* `biome`
|
* `biome`
|
||||||
* `cspell`
|
* `cspell`
|
||||||
|
|||||||
@@ -8,5 +8,58 @@ dprint *ale-toml-dprint*
|
|||||||
See |ale-dprint-options| and https://dprint.dev/plugins/toml
|
See |ale-dprint-options| and https://dprint.dev/plugins/toml
|
||||||
|
|
||||||
|
|
||||||
|
===============================================================================
|
||||||
|
tombi *ale-toml-tombi*
|
||||||
|
|
||||||
|
`'tombi'` is a TOML formatter, linter, and language server.
|
||||||
|
|
||||||
|
*ale-options.toml_tombi_executable*
|
||||||
|
*g:ale_toml_tombi_executable*
|
||||||
|
*b:ale_toml_tombi_executable*
|
||||||
|
toml_tombi_executable
|
||||||
|
g:ale_toml_tombi_executable
|
||||||
|
Type: |String|
|
||||||
|
Default: `'tombi'`
|
||||||
|
|
||||||
|
This variable can be modified to change the executable path for
|
||||||
|
`tombi`.
|
||||||
|
|
||||||
|
|
||||||
|
*ale-options.toml_tombi_lsp_options*
|
||||||
|
*g:ale_toml_tombi_lsp_options*
|
||||||
|
*b:ale_toml_tombi_lsp_options*
|
||||||
|
toml_tombi_lsp_options
|
||||||
|
g:ale_toml_tombi_lsp_options
|
||||||
|
Type: |String|
|
||||||
|
Default: `''`
|
||||||
|
|
||||||
|
This variable can be modified to provide options when using `tombi` as an
|
||||||
|
LSP server.
|
||||||
|
|
||||||
|
|
||||||
|
*ale-options.toml_tombi_format_options*
|
||||||
|
*g:ale_toml_tombi_format_options*
|
||||||
|
*b:ale_toml_tombi_format_options*
|
||||||
|
toml_tombi_format_options
|
||||||
|
g:ale_toml_tombi_format_options
|
||||||
|
Type: |String|
|
||||||
|
Default: `''`
|
||||||
|
|
||||||
|
This variable can be modified to provide options when using `tombi` as a
|
||||||
|
formatter.
|
||||||
|
|
||||||
|
|
||||||
|
*ale-options.toml_tombi_lint_options*
|
||||||
|
*g:ale_toml_tombi_lint_options*
|
||||||
|
*b:ale_toml_tombi_lint_options*
|
||||||
|
toml_tombi_lint_options
|
||||||
|
g:ale_toml_tombi_lint_options
|
||||||
|
Type: |String|
|
||||||
|
Default: `''`
|
||||||
|
|
||||||
|
This variable can be modified to provide options when using `tombi` as a
|
||||||
|
linter.
|
||||||
|
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
|
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
|
||||||
|
|||||||
@@ -3928,6 +3928,7 @@ documented in additional help files.
|
|||||||
thriftcheck...........................|ale-thrift-thriftcheck|
|
thriftcheck...........................|ale-thrift-thriftcheck|
|
||||||
toml....................................|ale-toml-options|
|
toml....................................|ale-toml-options|
|
||||||
dprint................................|ale-toml-dprint|
|
dprint................................|ale-toml-dprint|
|
||||||
|
tombi.................................|ale-toml-tombi|
|
||||||
typescript..............................|ale-typescript-options|
|
typescript..............................|ale-typescript-options|
|
||||||
biome.................................|ale-typescript-biome|
|
biome.................................|ale-typescript-biome|
|
||||||
cspell................................|ale-typescript-cspell|
|
cspell................................|ale-typescript-cspell|
|
||||||
|
|||||||
@@ -707,6 +707,7 @@ formatting.
|
|||||||
* [thriftcheck](https://github.com/pinterest/thriftcheck)
|
* [thriftcheck](https://github.com/pinterest/thriftcheck)
|
||||||
* TOML
|
* TOML
|
||||||
* [dprint](https://dprint.dev)
|
* [dprint](https://dprint.dev)
|
||||||
|
* [tombi](https://tombi-toml.github.io/tombi/)
|
||||||
* TypeScript
|
* TypeScript
|
||||||
* [biome](https://biomejs.dev/)
|
* [biome](https://biomejs.dev/)
|
||||||
* [cspell](https://github.com/streetsidesoftware/cspell/tree/main/packages/cspell)
|
* [cspell](https://github.com/streetsidesoftware/cspell/tree/main/packages/cspell)
|
||||||
|
|||||||
33
test/fixers/test_tombi_format_fixer_callback.vader
Normal file
33
test/fixers/test_tombi_format_fixer_callback.vader
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
Before:
|
||||||
|
Save g:ale_toml_tombi_executable
|
||||||
|
Save g:ale_toml_tombi_format_options
|
||||||
|
|
||||||
|
" Use an invalid global executable, so we don't match it.
|
||||||
|
let g:ale_toml_tombi_executable = 'xxxinvalid'
|
||||||
|
let g:ale_toml_tombi_format_options = ''
|
||||||
|
|
||||||
|
call ale#test#SetDirectory('/testplugin/test/fixers')
|
||||||
|
|
||||||
|
After:
|
||||||
|
Restore
|
||||||
|
|
||||||
|
call ale#test#RestoreDirectory()
|
||||||
|
|
||||||
|
Execute(The tombi format callback should return the correct default values):
|
||||||
|
|
||||||
|
AssertEqual
|
||||||
|
\ {
|
||||||
|
\ 'command': ale#Escape('xxxinvalid') . ' format',
|
||||||
|
\ },
|
||||||
|
\ ale#fixers#tombi_format#Fix(bufnr(''))
|
||||||
|
|
||||||
|
Execute(The tombi format callback should include custom options):
|
||||||
|
let g:ale_toml_tombi_format_options = "--offline"
|
||||||
|
|
||||||
|
AssertEqual
|
||||||
|
\ {
|
||||||
|
\ 'command': ale#Escape('xxxinvalid')
|
||||||
|
\ . ' format'
|
||||||
|
\ . ' ' . g:ale_toml_tombi_format_options
|
||||||
|
\ },
|
||||||
|
\ ale#fixers#tombi_format#Fix(bufnr(''))
|
||||||
33
test/fixers/test_tombi_lint_fixer_callback.vader
Normal file
33
test/fixers/test_tombi_lint_fixer_callback.vader
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
Before:
|
||||||
|
Save g:ale_toml_tombi_executable
|
||||||
|
Save g:ale_toml_tombi_lint_options
|
||||||
|
|
||||||
|
" Use an invalid global executable, so we don't match it.
|
||||||
|
let g:ale_toml_tombi_executable = 'xxxinvalid'
|
||||||
|
let g:ale_toml_tombi_lint_options = ''
|
||||||
|
|
||||||
|
call ale#test#SetDirectory('/testplugin/test/fixers')
|
||||||
|
|
||||||
|
After:
|
||||||
|
Restore
|
||||||
|
|
||||||
|
call ale#test#RestoreDirectory()
|
||||||
|
|
||||||
|
Execute(The tombi lint callback should return the correct default values):
|
||||||
|
|
||||||
|
AssertEqual
|
||||||
|
\ {
|
||||||
|
\ 'command': ale#Escape('xxxinvalid') . ' lint',
|
||||||
|
\ },
|
||||||
|
\ ale#fixers#tombi_lint#Fix(bufnr(''))
|
||||||
|
|
||||||
|
Execute(The tombi lint callback should include custom options):
|
||||||
|
let g:ale_toml_tombi_lint_options = "--offline"
|
||||||
|
|
||||||
|
AssertEqual
|
||||||
|
\ {
|
||||||
|
\ 'command': ale#Escape('xxxinvalid')
|
||||||
|
\ . ' lint'
|
||||||
|
\ . ' ' . g:ale_toml_tombi_lint_options
|
||||||
|
\ },
|
||||||
|
\ ale#fixers#tombi_lint#Fix(bufnr(''))
|
||||||
23
test/linter/test_toml_tombi.vader
Normal file
23
test/linter/test_toml_tombi.vader
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
Before:
|
||||||
|
call ale#assert#SetUpLinterTest('toml', 'tombi')
|
||||||
|
|
||||||
|
After:
|
||||||
|
call ale#assert#TearDownLinterTest()
|
||||||
|
|
||||||
|
Execute(The default executable path should be correct):
|
||||||
|
AssertLinter 'tombi', ale#Escape('tombi') . ' lsp'
|
||||||
|
|
||||||
|
Execute(The project root should be detected correctly with a configuration file):
|
||||||
|
call ale#test#SetFilename('../test-files/toml/tombi/tombitoml/subdir/file.ext')
|
||||||
|
|
||||||
|
AssertLSPProject ale#path#Simplify(g:dir . '/../test-files/toml/tombi/tombitoml')
|
||||||
|
|
||||||
|
Execute(The project root should be detected correctly in Python projects):
|
||||||
|
call ale#test#SetFilename('../test-files/toml/tombi/pyprojecttoml/subdir/file.ext')
|
||||||
|
|
||||||
|
AssertLSPProject ale#path#Simplify(g:dir . '/../test-files/toml/tombi/pyprojecttoml')
|
||||||
|
|
||||||
|
Execute(The project root should be empty when no project files can be detected):
|
||||||
|
call ale#test#SetFilename('../test-files/dummy')
|
||||||
|
|
||||||
|
AssertLSPProject ''
|
||||||
0
test/test-files/toml/tombi/tombitoml/tombi.toml
Normal file
0
test/test-files/toml/tombi/tombitoml/tombi.toml
Normal file
Reference in New Issue
Block a user