mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-06 12:44:23 +08:00
tombi: support toml_tombi_online flag to control remote schema fetching (#5032)
This commit is contained in:
@@ -3,6 +3,19 @@
|
|||||||
|
|
||||||
call ale#Set('toml_tombi_executable', 'tombi')
|
call ale#Set('toml_tombi_executable', 'tombi')
|
||||||
call ale#Set('toml_tombi_lsp_options', '')
|
call ale#Set('toml_tombi_lsp_options', '')
|
||||||
|
call ale#Set('toml_tombi_online', 0)
|
||||||
|
|
||||||
|
function! ale_linters#toml#tombi#GetCommand(buffer) abort
|
||||||
|
let l:offline = ''
|
||||||
|
|
||||||
|
if !ale#Var(a:buffer, 'toml_tombi_online')
|
||||||
|
let l:offline = '--offline'
|
||||||
|
endif
|
||||||
|
|
||||||
|
return '%e lsp'
|
||||||
|
\ . ale#Pad(l:offline)
|
||||||
|
\ . ale#Pad(ale#Var(a:buffer, 'toml_tombi_lsp_options'))
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! ale_linters#toml#tombi#GetProjectRoot(buffer) abort
|
function! ale_linters#toml#tombi#GetProjectRoot(buffer) abort
|
||||||
" Try to find nearest tombi.toml
|
" Try to find nearest tombi.toml
|
||||||
@@ -33,6 +46,6 @@ call ale#linter#Define('toml', {
|
|||||||
\ 'name': 'tombi',
|
\ 'name': 'tombi',
|
||||||
\ 'lsp': 'stdio',
|
\ 'lsp': 'stdio',
|
||||||
\ 'executable': {b -> ale#Var(b, 'toml_tombi_executable')},
|
\ 'executable': {b -> ale#Var(b, 'toml_tombi_executable')},
|
||||||
\ 'command': {b -> '%e lsp' . ale#Pad(ale#Var(b, 'toml_tombi_lsp_options'))},
|
\ 'command': function('ale_linters#toml#tombi#GetCommand'),
|
||||||
\ 'project_root': function('ale_linters#toml#tombi#GetProjectRoot'),
|
\ 'project_root': function('ale_linters#toml#tombi#GetProjectRoot'),
|
||||||
\})
|
\})
|
||||||
|
|||||||
@@ -3,13 +3,20 @@
|
|||||||
|
|
||||||
call ale#Set('toml_tombi_executable', 'tombi')
|
call ale#Set('toml_tombi_executable', 'tombi')
|
||||||
call ale#Set('toml_tombi_format_options', '')
|
call ale#Set('toml_tombi_format_options', '')
|
||||||
|
call ale#Set('toml_tombi_online', 0)
|
||||||
|
|
||||||
function! ale#fixers#tombi_format#Fix(buffer) abort
|
function! ale#fixers#tombi_format#Fix(buffer) abort
|
||||||
let l:executable = ale#Var(a:buffer, 'toml_tombi_executable')
|
let l:executable = ale#Var(a:buffer, 'toml_tombi_executable')
|
||||||
|
let l:offline = ''
|
||||||
|
|
||||||
|
if !ale#Var(a:buffer, 'toml_tombi_online')
|
||||||
|
let l:offline = '--offline'
|
||||||
|
endif
|
||||||
|
|
||||||
return {
|
return {
|
||||||
\ 'command': ale#Escape(l:executable)
|
\ 'command': ale#Escape(l:executable)
|
||||||
\ . ' format'
|
\ . ' format'
|
||||||
|
\ . ale#Pad(l:offline)
|
||||||
\ . ale#Pad(ale#Var(a:buffer, 'toml_tombi_format_options')),
|
\ . ale#Pad(ale#Var(a:buffer, 'toml_tombi_format_options')),
|
||||||
\}
|
\}
|
||||||
endfunction
|
endfunction
|
||||||
|
|||||||
@@ -3,13 +3,20 @@
|
|||||||
|
|
||||||
call ale#Set('toml_tombi_executable', 'tombi')
|
call ale#Set('toml_tombi_executable', 'tombi')
|
||||||
call ale#Set('toml_tombi_lint_options', '')
|
call ale#Set('toml_tombi_lint_options', '')
|
||||||
|
call ale#Set('toml_tombi_online', 0)
|
||||||
|
|
||||||
function! ale#fixers#tombi_lint#Fix(buffer) abort
|
function! ale#fixers#tombi_lint#Fix(buffer) abort
|
||||||
let l:executable = ale#Var(a:buffer, 'toml_tombi_executable')
|
let l:executable = ale#Var(a:buffer, 'toml_tombi_executable')
|
||||||
|
let l:offline = ''
|
||||||
|
|
||||||
|
if !ale#Var(a:buffer, 'toml_tombi_online')
|
||||||
|
let l:offline = '--offline'
|
||||||
|
endif
|
||||||
|
|
||||||
return {
|
return {
|
||||||
\ 'command': ale#Escape(l:executable)
|
\ 'command': ale#Escape(l:executable)
|
||||||
\ . ' lint'
|
\ . ' lint'
|
||||||
|
\ . ale#Pad(l:offline)
|
||||||
\ . ale#Pad(ale#Var(a:buffer, 'toml_tombi_lint_options')),
|
\ . ale#Pad(ale#Var(a:buffer, 'toml_tombi_lint_options')),
|
||||||
\}
|
\}
|
||||||
endfunction
|
endfunction
|
||||||
|
|||||||
@@ -25,6 +25,18 @@ g:ale_toml_tombi_executable
|
|||||||
`tombi`.
|
`tombi`.
|
||||||
|
|
||||||
|
|
||||||
|
*ale-options.toml_tombi_online*
|
||||||
|
*g:ale_toml_tombi_online*
|
||||||
|
*b:ale_toml_tombi_online*
|
||||||
|
toml_tombi_online
|
||||||
|
g:ale_toml_tombi_online
|
||||||
|
Type: |Boolean|
|
||||||
|
Default: `1`
|
||||||
|
|
||||||
|
This variable can be modified allow fetching remote schemas when using
|
||||||
|
`tombi`.
|
||||||
|
|
||||||
|
|
||||||
*ale-options.toml_tombi_lsp_options*
|
*ale-options.toml_tombi_lsp_options*
|
||||||
*g:ale_toml_tombi_lsp_options*
|
*g:ale_toml_tombi_lsp_options*
|
||||||
*b:ale_toml_tombi_lsp_options*
|
*b:ale_toml_tombi_lsp_options*
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
Before:
|
Before:
|
||||||
Save g:ale_toml_tombi_executable
|
Save g:ale_toml_tombi_executable
|
||||||
Save g:ale_toml_tombi_format_options
|
Save g:ale_toml_tombi_format_options
|
||||||
|
Save g:ale_toml_tombi_online
|
||||||
|
|
||||||
" Use an invalid global executable, so we don't match it.
|
" Use an invalid global executable, so we don't match it.
|
||||||
let g:ale_toml_tombi_executable = 'xxxinvalid'
|
let g:ale_toml_tombi_executable = 'xxxinvalid'
|
||||||
@@ -14,13 +15,20 @@ After:
|
|||||||
call ale#test#RestoreDirectory()
|
call ale#test#RestoreDirectory()
|
||||||
|
|
||||||
Execute(The tombi format callback should return the correct default values):
|
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
|
AssertEqual
|
||||||
\ {'command': ale#Escape('xxxinvalid') . ' format --offline'},
|
\ {'command': ale#Escape('xxxinvalid') . ' format --offline'},
|
||||||
\ ale#fixers#tombi_format#Fix(bufnr(''))
|
\ ale#fixers#tombi_format#Fix(bufnr(''))
|
||||||
|
|
||||||
|
Execute(The tombi format callback should obey `toml_tombi_online`):
|
||||||
|
let g:ale_toml_tombi_online = 1
|
||||||
|
|
||||||
|
AssertEqual
|
||||||
|
\ {'command': ale#Escape('xxxinvalid') . ' lint'},
|
||||||
|
\ ale#fixers#tombi_lint#Fix(bufnr(''))
|
||||||
|
|
||||||
|
Execute(The tombi format callback should include custom options):
|
||||||
|
let g:ale_toml_tombi_format_options = "--no-cache"
|
||||||
|
|
||||||
|
AssertEqual
|
||||||
|
\ {'command': ale#Escape('xxxinvalid') . ' format --offline --no-cache'},
|
||||||
|
\ ale#fixers#tombi_format#Fix(bufnr(''))
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
Before:
|
Before:
|
||||||
Save g:ale_toml_tombi_executable
|
Save g:ale_toml_tombi_executable
|
||||||
Save g:ale_toml_tombi_lint_options
|
Save g:ale_toml_tombi_lint_options
|
||||||
|
Save g:ale_toml_tombi_online
|
||||||
|
|
||||||
" Use an invalid global executable, so we don't match it.
|
" Use an invalid global executable, so we don't match it.
|
||||||
let g:ale_toml_tombi_executable = 'xxxinvalid'
|
let g:ale_toml_tombi_executable = 'xxxinvalid'
|
||||||
@@ -14,13 +15,20 @@ After:
|
|||||||
call ale#test#RestoreDirectory()
|
call ale#test#RestoreDirectory()
|
||||||
|
|
||||||
Execute(The tombi lint callback should return the correct default values):
|
Execute(The tombi lint callback should return the correct default values):
|
||||||
|
AssertEqual
|
||||||
|
\ {'command': ale#Escape('xxxinvalid') . ' lint --offline'},
|
||||||
|
\ ale#fixers#tombi_lint#Fix(bufnr(''))
|
||||||
|
|
||||||
|
Execute(The tombi lint callback should obey `toml_tombi_online`):
|
||||||
|
let g:ale_toml_tombi_online = 1
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ {'command': ale#Escape('xxxinvalid') . ' lint'},
|
\ {'command': ale#Escape('xxxinvalid') . ' lint'},
|
||||||
\ ale#fixers#tombi_lint#Fix(bufnr(''))
|
\ ale#fixers#tombi_lint#Fix(bufnr(''))
|
||||||
|
|
||||||
Execute(The tombi lint callback should include custom options):
|
Execute(The tombi lint callback should include custom options):
|
||||||
let g:ale_toml_tombi_lint_options = "--offline"
|
let g:ale_toml_tombi_lint_options = "--no-cache"
|
||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ {'command': ale#Escape('xxxinvalid') . ' lint --offline'},
|
\ {'command': ale#Escape('xxxinvalid') . ' lint --offline --no-cache'},
|
||||||
\ ale#fixers#tombi_lint#Fix(bufnr(''))
|
\ ale#fixers#tombi_lint#Fix(bufnr(''))
|
||||||
|
|||||||
@@ -1,10 +1,16 @@
|
|||||||
Before:
|
Before:
|
||||||
|
Save g:ale_toml_tombi_online
|
||||||
call ale#assert#SetUpLinterTest('toml', 'tombi')
|
call ale#assert#SetUpLinterTest('toml', 'tombi')
|
||||||
|
|
||||||
After:
|
After:
|
||||||
call ale#assert#TearDownLinterTest()
|
call ale#assert#TearDownLinterTest()
|
||||||
|
|
||||||
Execute(The default executable path should be correct):
|
Execute(The default executable path should be correct):
|
||||||
|
AssertLinter 'tombi', ale#Escape('tombi') . ' lsp --offline'
|
||||||
|
|
||||||
|
Execute(The default executable path should obey `toml_tombi_online`):
|
||||||
|
let g:ale_toml_tombi_online = 1
|
||||||
|
|
||||||
AssertLinter 'tombi', ale#Escape('tombi') . ' lsp'
|
AssertLinter 'tombi', ale#Escape('tombi') . ' lsp'
|
||||||
|
|
||||||
Execute(The project root should be detected correctly with a configuration file):
|
Execute(The project root should be detected correctly with a configuration file):
|
||||||
|
|||||||
Reference in New Issue
Block a user