#1278 Allow linters to be defined pretty much anywhere

This commit is contained in:
w0rp
2018-04-24 21:48:33 +01:00
parent ebbf7d0353
commit 41c0b837ae
4 changed files with 37 additions and 8 deletions

View File

@@ -3,6 +3,7 @@ call ale#Set('wrap_command_as_one_argument', 0)
" Description: Linter registration and lazy-loading
" Retrieves linters as requested by the engine, loading them if needed.
let s:runtime_loaded_map = {}
let s:linters = {}
" Default filetype aliases.
@@ -38,6 +39,7 @@ let s:default_ale_linters = {
" Testing/debugging helper to unload all linters.
function! ale#linter#Reset() abort
let s:runtime_loaded_map = {}
let s:linters = {}
endfunction
@@ -250,20 +252,20 @@ function! ale#linter#Define(filetype, linter) abort
call add(s:linters[a:filetype], l:new_linter)
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
let l:combined_linters = []
for l:filetype in a:filetypes
" Load linter defintions from files if we haven't loaded them yet.
if !has_key(s:linters, l:filetype)
" Load linters from runtimepath if we haven't done that yet.
if !has_key(s:runtime_loaded_map, l:filetype)
execute 'silent! runtime! ale_linters/' . l:filetype . '/*.vim'
" Always set an empty List for the loaded linters if we don't find
" 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
let s:runtime_loaded_map[l:filetype] = 1
endif
call extend(l:combined_linters, get(s:linters, l:filetype, []))