#1278 Allow linters to be defined pretty much anywhere
This commit is contained in:
parent
ebbf7d0353
commit
41c0b837ae
@ -3,6 +3,7 @@ call ale#Set('wrap_command_as_one_argument', 0)
|
|||||||
" Description: Linter registration and lazy-loading
|
" Description: Linter registration and lazy-loading
|
||||||
" Retrieves linters as requested by the engine, loading them if needed.
|
" Retrieves linters as requested by the engine, loading them if needed.
|
||||||
|
|
||||||
|
let s:runtime_loaded_map = {}
|
||||||
let s:linters = {}
|
let s:linters = {}
|
||||||
|
|
||||||
" Default filetype aliases.
|
" Default filetype aliases.
|
||||||
@ -38,6 +39,7 @@ let s:default_ale_linters = {
|
|||||||
|
|
||||||
" Testing/debugging helper to unload all linters.
|
" Testing/debugging helper to unload all linters.
|
||||||
function! ale#linter#Reset() abort
|
function! ale#linter#Reset() abort
|
||||||
|
let s:runtime_loaded_map = {}
|
||||||
let s:linters = {}
|
let s:linters = {}
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@ -250,20 +252,20 @@ function! ale#linter#Define(filetype, linter) abort
|
|||||||
call add(s:linters[a:filetype], l:new_linter)
|
call add(s:linters[a:filetype], l:new_linter)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
" Prevent any linters from being loaded for a given filetype.
|
||||||
|
function! ale#linter#PreventLoading(filetype) abort
|
||||||
|
let s:runtime_loaded_map[a:filetype] = 1
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! ale#linter#GetAll(filetypes) abort
|
function! ale#linter#GetAll(filetypes) abort
|
||||||
let l:combined_linters = []
|
let l:combined_linters = []
|
||||||
|
|
||||||
for l:filetype in a:filetypes
|
for l:filetype in a:filetypes
|
||||||
" Load linter defintions from files if we haven't loaded them yet.
|
" Load linters from runtimepath if we haven't done that yet.
|
||||||
if !has_key(s:linters, l:filetype)
|
if !has_key(s:runtime_loaded_map, l:filetype)
|
||||||
execute 'silent! runtime! ale_linters/' . l:filetype . '/*.vim'
|
execute 'silent! runtime! ale_linters/' . l:filetype . '/*.vim'
|
||||||
|
|
||||||
" Always set an empty List for the loaded linters if we don't find
|
let s:runtime_loaded_map[l:filetype] = 1
|
||||||
" any. This will prevent us from executing the runtime command
|
|
||||||
" many times, redundantly.
|
|
||||||
if !has_key(s:linters, l:filetype)
|
|
||||||
let s:linters[l:filetype] = []
|
|
||||||
endif
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
call extend(l:combined_linters, get(s:linters, l:filetype, []))
|
call extend(l:combined_linters, get(s:linters, l:filetype, []))
|
||||||
|
22
doc/ale.txt
22
doc/ale.txt
@ -2359,6 +2359,21 @@ ale#linter#Define(filetype, linter) *ale#linter#Define()*
|
|||||||
containing `.` characters will be split into individual parts, and files
|
containing `.` characters will be split into individual parts, and files
|
||||||
will be loaded for each filetype between the `.` characters.
|
will be loaded for each filetype between the `.` characters.
|
||||||
|
|
||||||
|
Linters can be defined from vimrc and other files as long as this function
|
||||||
|
is loaded first. For example, the following code will define a Hello World
|
||||||
|
linter in vimrc in Vim 8: >
|
||||||
|
|
||||||
|
" Plugins have to be loaded first.
|
||||||
|
" If you are using a plugin manager, run that first.
|
||||||
|
packloadall
|
||||||
|
|
||||||
|
call ale#linter#Define('vim', {
|
||||||
|
\ 'name': 'echo-test',
|
||||||
|
\ 'executable': 'echo',
|
||||||
|
\ 'command': 'echo hello world',
|
||||||
|
\ 'callback': {buffer, lines -> map(lines, '{"text": v:val, "lnum": 1}')},
|
||||||
|
\})
|
||||||
|
<
|
||||||
|
|
||||||
ale#linter#Get(filetype) *ale#linter#Get()*
|
ale#linter#Get(filetype) *ale#linter#Get()*
|
||||||
|
|
||||||
@ -2374,6 +2389,13 @@ ale#linter#Get(filetype) *ale#linter#Get()*
|
|||||||
components.
|
components.
|
||||||
|
|
||||||
|
|
||||||
|
ale#linter#PreventLoading(filetype) *ale#linter#PreventLoading()*
|
||||||
|
|
||||||
|
Given a `filetype`, prevent any more linters from being loaded from
|
||||||
|
|runtimepath| for that filetype. This function can be called from vimrc or
|
||||||
|
similar to prevent ALE from loading linters.
|
||||||
|
|
||||||
|
|
||||||
ale#statusline#Count(buffer) *ale#statusline#Count()*
|
ale#statusline#Count(buffer) *ale#statusline#Count()*
|
||||||
|
|
||||||
Given the number of a buffer which may have problems, return a |Dictionary|
|
Given the number of a buffer which may have problems, return a |Dictionary|
|
||||||
|
@ -32,6 +32,7 @@ Before:
|
|||||||
|
|
||||||
call ale#engine#ResetExecutableCache()
|
call ale#engine#ResetExecutableCache()
|
||||||
call ale#linter#Reset()
|
call ale#linter#Reset()
|
||||||
|
call ale#linter#PreventLoading('testft')
|
||||||
let g:ale_linters = {}
|
let g:ale_linters = {}
|
||||||
let g:ale_fixers = {}
|
let g:ale_fixers = {}
|
||||||
let g:ale_linter_aliases = {}
|
let g:ale_linter_aliases = {}
|
||||||
|
@ -5,6 +5,9 @@ Before:
|
|||||||
let g:testlinter1 = {'name': 'testlinter1', 'executable': 'testlinter1', 'command': 'testlinter1', 'callback': 'testCB1', 'output_stream': 'stdout', 'read_buffer': 1, 'lint_file': 0, 'aliases': [], 'lsp': '', 'add_newline': 0}
|
let g:testlinter1 = {'name': 'testlinter1', 'executable': 'testlinter1', 'command': 'testlinter1', 'callback': 'testCB1', 'output_stream': 'stdout', 'read_buffer': 1, 'lint_file': 0, 'aliases': [], 'lsp': '', 'add_newline': 0}
|
||||||
let g:testlinter2 = {'name': 'testlinter2', 'executable': 'testlinter2', 'command': 'testlinter2', 'callback': 'testCB2', 'output_stream': 'stdout', 'read_buffer': 0, 'lint_file': 1, 'aliases': [], 'lsp': '', 'add_newline': 0}
|
let g:testlinter2 = {'name': 'testlinter2', 'executable': 'testlinter2', 'command': 'testlinter2', 'callback': 'testCB2', 'output_stream': 'stdout', 'read_buffer': 0, 'lint_file': 1, 'aliases': [], 'lsp': '', 'add_newline': 0}
|
||||||
call ale#linter#Reset()
|
call ale#linter#Reset()
|
||||||
|
call ale#linter#PreventLoading('testft')
|
||||||
|
call ale#linter#PreventLoading('javascript')
|
||||||
|
call ale#linter#PreventLoading('typescript')
|
||||||
|
|
||||||
After:
|
After:
|
||||||
Restore
|
Restore
|
||||||
@ -145,6 +148,7 @@ Execute (Buffer-local overrides for aliases should be used):
|
|||||||
AssertEqual [g:testlinter1, g:testlinter2], ale#linter#Get('testft1')
|
AssertEqual [g:testlinter1, g:testlinter2], ale#linter#Get('testft1')
|
||||||
|
|
||||||
Execute (Linters should be loaded from disk appropriately):
|
Execute (Linters should be loaded from disk appropriately):
|
||||||
|
call ale#linter#Reset()
|
||||||
AssertEqual [{'name': 'testlinter', 'output_stream': 'stdout', 'executable': 'testlinter', 'command': 'testlinter', 'callback': 'testCB', 'read_buffer': 1, 'lint_file': 0, 'aliases': [], 'lsp': '', 'add_newline': 0}], ale#linter#Get('testft')
|
AssertEqual [{'name': 'testlinter', 'output_stream': 'stdout', 'executable': 'testlinter', 'command': 'testlinter', 'callback': 'testCB', 'read_buffer': 1, 'lint_file': 0, 'aliases': [], 'lsp': '', 'add_newline': 0}], ale#linter#Get('testft')
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user