2017-06-15 08:30:34 +00:00
|
|
|
" Author: w0rp <devw0rp@gmail.com>, David Alexander <opensource@thelonelyghost.com>
|
First pass at optimizing ale to autoload (#80)
* First pass at optimizing ale to autoload
First off, the structure/function names should be revised a bit,
but I will wait for @w0rp's input before unifying the naming style.
Second off, the docs probably need some more work, I just did some
simple find-and-replace work.
With that said, this pull brings major performance gains for ale. On my
slowest system, fully loading ale and all its code takes around 150ms.
I have moved all of ale's autoload-able code to autoload/, and in
addition, implemented lazy-loading of linters. This brings load time on
that same system down to 5ms.
The only downside of lazy loading is that `g:ale_linters` cannot be
changed at runtime; however, it also speeds up performance at runtime by
simplfying the logic greatly.
Please let me know what you think!
Closes #59
* Address Travis/Vint errors
For some reason, ale isn't running vint for me...
* Incorporate feedback, make fixes
Lazy-loading logic is much improved.
* Add header comments; remove incorrect workaround
* Remove unneeded plugin guards
* Fix lazy-loading linter logic
Set the wrong variable....
* Fix capitialization
2016-10-10 18:51:29 +00:00
|
|
|
" Description: Primary code path for the plugin
|
|
|
|
" Manages execution of linters when requested by autocommands
|
|
|
|
|
2018-05-28 18:19:20 +00:00
|
|
|
" Strings used for severity in the echoed message
|
|
|
|
let g:ale_echo_msg_error_str = get(g:, 'ale_echo_msg_error_str', 'Error')
|
|
|
|
let g:ale_echo_msg_info_str = get(g:, 'ale_echo_msg_info_str', 'Info')
|
|
|
|
let g:ale_echo_msg_warning_str = get(g:, 'ale_echo_msg_warning_str', 'Warning')
|
2018-06-24 20:16:45 +00:00
|
|
|
" Ignoring linters, for disabling some, or ignoring LSP diagnostics.
|
|
|
|
let g:ale_linters_ignore = get(g:, 'ale_linters_ignore', {})
|
2018-05-28 18:19:20 +00:00
|
|
|
|
First pass at optimizing ale to autoload (#80)
* First pass at optimizing ale to autoload
First off, the structure/function names should be revised a bit,
but I will wait for @w0rp's input before unifying the naming style.
Second off, the docs probably need some more work, I just did some
simple find-and-replace work.
With that said, this pull brings major performance gains for ale. On my
slowest system, fully loading ale and all its code takes around 150ms.
I have moved all of ale's autoload-able code to autoload/, and in
addition, implemented lazy-loading of linters. This brings load time on
that same system down to 5ms.
The only downside of lazy loading is that `g:ale_linters` cannot be
changed at runtime; however, it also speeds up performance at runtime by
simplfying the logic greatly.
Please let me know what you think!
Closes #59
* Address Travis/Vint errors
For some reason, ale isn't running vint for me...
* Incorporate feedback, make fixes
Lazy-loading logic is much improved.
* Add header comments; remove incorrect workaround
* Remove unneeded plugin guards
* Fix lazy-loading linter logic
Set the wrong variable....
* Fix capitialization
2016-10-10 18:51:29 +00:00
|
|
|
let s:lint_timer = -1
|
2018-10-29 11:29:12 +00:00
|
|
|
let s:getcmdwintype_exists = exists('*getcmdwintype')
|
First pass at optimizing ale to autoload (#80)
* First pass at optimizing ale to autoload
First off, the structure/function names should be revised a bit,
but I will wait for @w0rp's input before unifying the naming style.
Second off, the docs probably need some more work, I just did some
simple find-and-replace work.
With that said, this pull brings major performance gains for ale. On my
slowest system, fully loading ale and all its code takes around 150ms.
I have moved all of ale's autoload-able code to autoload/, and in
addition, implemented lazy-loading of linters. This brings load time on
that same system down to 5ms.
The only downside of lazy loading is that `g:ale_linters` cannot be
changed at runtime; however, it also speeds up performance at runtime by
simplfying the logic greatly.
Please let me know what you think!
Closes #59
* Address Travis/Vint errors
For some reason, ale isn't running vint for me...
* Incorporate feedback, make fixes
Lazy-loading logic is much improved.
* Add header comments; remove incorrect workaround
* Remove unneeded plugin guards
* Fix lazy-loading linter logic
Set the wrong variable....
* Fix capitialization
2016-10-10 18:51:29 +00:00
|
|
|
|
2017-05-26 20:21:15 +00:00
|
|
|
" Return 1 if a file is too large for ALE to handle.
|
2018-05-28 18:19:20 +00:00
|
|
|
function! ale#FileTooLarge(buffer) abort
|
|
|
|
let l:max = getbufvar(a:buffer, 'ale_maximum_file_size', get(g:, 'ale_maximum_file_size', 0))
|
2017-05-26 20:21:15 +00:00
|
|
|
|
|
|
|
return l:max > 0 ? (line2byte(line('$') + 1) > l:max) : 0
|
|
|
|
endfunction
|
|
|
|
|
2017-02-14 21:02:49 +00:00
|
|
|
" A function for checking various conditions whereby ALE just shouldn't
|
|
|
|
" attempt to do anything, say if particular buffer types are open in Vim.
|
2017-07-31 23:03:24 +00:00
|
|
|
function! ale#ShouldDoNothing(buffer) abort
|
2017-10-14 15:51:12 +00:00
|
|
|
" The checks are split into separate if statements to make it possible to
|
|
|
|
" profile each check individually with Vim's profiling tools.
|
2018-09-04 15:51:18 +00:00
|
|
|
"
|
2018-04-12 19:31:33 +00:00
|
|
|
" Do nothing if ALE is disabled.
|
|
|
|
if !getbufvar(a:buffer, 'ale_enabled', get(g:, 'ale_enabled', 0))
|
|
|
|
return 1
|
|
|
|
endif
|
|
|
|
|
2017-10-14 18:22:19 +00:00
|
|
|
" Don't perform any checks when newer NeoVim versions are exiting.
|
|
|
|
if get(v:, 'exiting', v:null) isnot v:null
|
|
|
|
return 1
|
|
|
|
endif
|
|
|
|
|
2018-05-28 16:38:14 +00:00
|
|
|
let l:filetype = getbufvar(a:buffer, '&filetype')
|
|
|
|
|
|
|
|
" Do nothing when there's no filetype.
|
|
|
|
if l:filetype is# ''
|
|
|
|
return 1
|
|
|
|
endif
|
|
|
|
|
|
|
|
" Do nothing for blacklisted files.
|
|
|
|
if index(get(g:, 'ale_filetype_blacklist', []), l:filetype) >= 0
|
2017-10-14 15:51:12 +00:00
|
|
|
return 1
|
|
|
|
endif
|
|
|
|
|
2018-05-28 16:38:14 +00:00
|
|
|
" Do nothing if running from command mode.
|
2017-10-14 16:31:58 +00:00
|
|
|
if s:getcmdwintype_exists && !empty(getcmdwintype())
|
2017-10-14 15:51:12 +00:00
|
|
|
return 1
|
|
|
|
endif
|
|
|
|
|
2017-10-26 19:29:23 +00:00
|
|
|
let l:filename = fnamemodify(bufname(a:buffer), ':t')
|
|
|
|
|
2018-05-28 16:38:14 +00:00
|
|
|
" Do nothing for directories.
|
2017-10-26 19:29:23 +00:00
|
|
|
if l:filename is# '.'
|
|
|
|
return 1
|
|
|
|
endif
|
|
|
|
|
2018-09-03 12:59:56 +00:00
|
|
|
" Don't start linting and so on when an operator is pending.
|
|
|
|
if ale#util#Mode(1) is# 'no'
|
|
|
|
return 1
|
|
|
|
endif
|
|
|
|
|
2018-05-28 16:38:14 +00:00
|
|
|
" Do nothing if running in the sandbox.
|
2017-10-14 15:51:12 +00:00
|
|
|
if ale#util#InSandbox()
|
|
|
|
return 1
|
|
|
|
endif
|
|
|
|
|
|
|
|
" Do nothing if the file is too large.
|
2018-05-28 18:19:20 +00:00
|
|
|
if ale#FileTooLarge(a:buffer)
|
2017-10-14 15:51:12 +00:00
|
|
|
return 1
|
|
|
|
endif
|
|
|
|
|
|
|
|
" Do nothing from CtrlP buffers with CtrlP-funky.
|
2017-10-14 16:11:30 +00:00
|
|
|
if exists(':CtrlPFunky') is 2
|
|
|
|
\&& getbufvar(a:buffer, '&l:statusline') =~# 'CtrlPMode.*funky'
|
2017-10-14 15:51:12 +00:00
|
|
|
return 1
|
|
|
|
endif
|
|
|
|
|
|
|
|
return 0
|
2017-02-14 21:02:49 +00:00
|
|
|
endfunction
|
|
|
|
|
2018-10-29 11:29:12 +00:00
|
|
|
function! s:Lint(buffer, should_lint_file, timer_id) abort
|
|
|
|
" Use the filetype from the buffer
|
|
|
|
let l:filetype = getbufvar(a:buffer, '&filetype')
|
|
|
|
let l:linters = ale#linter#Get(l:filetype)
|
|
|
|
|
|
|
|
" Apply ignore lists for linters only if needed.
|
|
|
|
let l:ignore_config = ale#Var(a:buffer, 'linters_ignore')
|
|
|
|
let l:linters = !empty(l:ignore_config)
|
|
|
|
\ ? ale#engine#ignore#Exclude(l:filetype, l:linters, l:ignore_config)
|
|
|
|
\ : l:linters
|
|
|
|
|
2018-10-29 18:28:28 +00:00
|
|
|
" Tell other sources that they can start checking the buffer now.
|
|
|
|
let g:ale_want_results_buffer = a:buffer
|
|
|
|
silent doautocmd <nomodeline> User ALEWantResults
|
|
|
|
unlet! g:ale_want_results_buffer
|
|
|
|
|
2018-10-29 11:29:12 +00:00
|
|
|
" Don't set up buffer data and so on if there are no linters to run.
|
|
|
|
if !has_key(g:ale_buffer_info, a:buffer) && empty(l:linters)
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
" Clear lint_file linters, or only run them if the file exists.
|
|
|
|
let l:lint_file = empty(l:linters)
|
|
|
|
\ || (a:should_lint_file && filereadable(expand('#' . a:buffer . ':p')))
|
|
|
|
|
|
|
|
call ale#engine#RunLinters(a:buffer, l:linters, l:lint_file)
|
|
|
|
endfunction
|
|
|
|
|
2017-07-31 23:03:24 +00:00
|
|
|
" (delay, [linting_flag, buffer_number])
|
2017-03-14 23:51:57 +00:00
|
|
|
function! ale#Queue(delay, ...) abort
|
2017-07-31 23:03:24 +00:00
|
|
|
if a:0 > 2
|
2017-03-14 23:51:57 +00:00
|
|
|
throw 'too many arguments!'
|
|
|
|
endif
|
|
|
|
|
2018-10-29 11:29:12 +00:00
|
|
|
let l:buffer = get(a:000, 1, v:null)
|
2017-08-08 23:05:55 +00:00
|
|
|
|
2018-10-29 11:29:12 +00:00
|
|
|
if l:buffer is v:null
|
|
|
|
let l:buffer = bufnr('')
|
2017-03-14 23:51:57 +00:00
|
|
|
endif
|
|
|
|
|
2018-07-25 00:27:28 +00:00
|
|
|
if type(l:buffer) isnot v:t_number
|
2017-07-31 23:03:24 +00:00
|
|
|
throw 'buffer_number must be a Number'
|
|
|
|
endif
|
|
|
|
|
2018-06-20 07:34:42 +00:00
|
|
|
if ale#ShouldDoNothing(l:buffer)
|
2016-10-31 14:47:08 +00:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2018-10-29 11:29:12 +00:00
|
|
|
" Default linting_flag to ''
|
|
|
|
let l:should_lint_file = get(a:000, 0) is# 'lint_file'
|
2017-03-14 23:51:57 +00:00
|
|
|
|
First pass at optimizing ale to autoload (#80)
* First pass at optimizing ale to autoload
First off, the structure/function names should be revised a bit,
but I will wait for @w0rp's input before unifying the naming style.
Second off, the docs probably need some more work, I just did some
simple find-and-replace work.
With that said, this pull brings major performance gains for ale. On my
slowest system, fully loading ale and all its code takes around 150ms.
I have moved all of ale's autoload-able code to autoload/, and in
addition, implemented lazy-loading of linters. This brings load time on
that same system down to 5ms.
The only downside of lazy loading is that `g:ale_linters` cannot be
changed at runtime; however, it also speeds up performance at runtime by
simplfying the logic greatly.
Please let me know what you think!
Closes #59
* Address Travis/Vint errors
For some reason, ale isn't running vint for me...
* Incorporate feedback, make fixes
Lazy-loading logic is much improved.
* Add header comments; remove incorrect workaround
* Remove unneeded plugin guards
* Fix lazy-loading linter logic
Set the wrong variable....
* Fix capitialization
2016-10-10 18:51:29 +00:00
|
|
|
if s:lint_timer != -1
|
|
|
|
call timer_stop(s:lint_timer)
|
|
|
|
let s:lint_timer = -1
|
|
|
|
endif
|
|
|
|
|
|
|
|
if a:delay > 0
|
2018-10-29 11:29:12 +00:00
|
|
|
let s:lint_timer = timer_start(
|
|
|
|
\ a:delay,
|
|
|
|
\ function('s:Lint', [l:buffer, l:should_lint_file])
|
|
|
|
\)
|
First pass at optimizing ale to autoload (#80)
* First pass at optimizing ale to autoload
First off, the structure/function names should be revised a bit,
but I will wait for @w0rp's input before unifying the naming style.
Second off, the docs probably need some more work, I just did some
simple find-and-replace work.
With that said, this pull brings major performance gains for ale. On my
slowest system, fully loading ale and all its code takes around 150ms.
I have moved all of ale's autoload-able code to autoload/, and in
addition, implemented lazy-loading of linters. This brings load time on
that same system down to 5ms.
The only downside of lazy loading is that `g:ale_linters` cannot be
changed at runtime; however, it also speeds up performance at runtime by
simplfying the logic greatly.
Please let me know what you think!
Closes #59
* Address Travis/Vint errors
For some reason, ale isn't running vint for me...
* Incorporate feedback, make fixes
Lazy-loading logic is much improved.
* Add header comments; remove incorrect workaround
* Remove unneeded plugin guards
* Fix lazy-loading linter logic
Set the wrong variable....
* Fix capitialization
2016-10-10 18:51:29 +00:00
|
|
|
else
|
2018-10-29 11:29:12 +00:00
|
|
|
call s:Lint(l:buffer, l:should_lint_file, 0)
|
First pass at optimizing ale to autoload (#80)
* First pass at optimizing ale to autoload
First off, the structure/function names should be revised a bit,
but I will wait for @w0rp's input before unifying the naming style.
Second off, the docs probably need some more work, I just did some
simple find-and-replace work.
With that said, this pull brings major performance gains for ale. On my
slowest system, fully loading ale and all its code takes around 150ms.
I have moved all of ale's autoload-able code to autoload/, and in
addition, implemented lazy-loading of linters. This brings load time on
that same system down to 5ms.
The only downside of lazy loading is that `g:ale_linters` cannot be
changed at runtime; however, it also speeds up performance at runtime by
simplfying the logic greatly.
Please let me know what you think!
Closes #59
* Address Travis/Vint errors
For some reason, ale isn't running vint for me...
* Incorporate feedback, make fixes
Lazy-loading logic is much improved.
* Add header comments; remove incorrect workaround
* Remove unneeded plugin guards
* Fix lazy-loading linter logic
Set the wrong variable....
* Fix capitialization
2016-10-10 18:51:29 +00:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2017-05-05 22:03:19 +00:00
|
|
|
let g:ale_has_override = get(g:, 'ale_has_override', {})
|
|
|
|
|
|
|
|
" Call has(), but check a global Dictionary so we can force flags on or off
|
|
|
|
" for testing purposes.
|
|
|
|
function! ale#Has(feature) abort
|
|
|
|
return get(g:ale_has_override, a:feature, has(a:feature))
|
|
|
|
endfunction
|
|
|
|
|
2017-04-15 23:16:48 +00:00
|
|
|
" Given a buffer number and a variable name, look for that variable in the
|
|
|
|
" buffer scope, then in global scope. If the name does not exist in the global
|
|
|
|
" scope, an exception will be thrown.
|
|
|
|
"
|
|
|
|
" Every variable name will be prefixed with 'ale_'.
|
|
|
|
function! ale#Var(buffer, variable_name) abort
|
|
|
|
let l:full_name = 'ale_' . a:variable_name
|
2018-07-22 21:31:46 +00:00
|
|
|
let l:vars = getbufvar(str2nr(a:buffer), '', {})
|
2017-05-30 21:15:24 +00:00
|
|
|
|
|
|
|
return get(l:vars, l:full_name, g:[l:full_name])
|
2017-04-15 23:16:48 +00:00
|
|
|
endfunction
|
2017-05-12 08:20:16 +00:00
|
|
|
|
2017-05-20 22:32:41 +00:00
|
|
|
" Initialize a variable with a default value, if it isn't already set.
|
|
|
|
"
|
|
|
|
" Every variable name will be prefixed with 'ale_'.
|
|
|
|
function! ale#Set(variable_name, default) abort
|
|
|
|
let l:full_name = 'ale_' . a:variable_name
|
|
|
|
|
2018-07-04 23:40:15 +00:00
|
|
|
if !has_key(g:, l:full_name)
|
|
|
|
let g:[l:full_name] = a:default
|
|
|
|
endif
|
2017-05-20 22:32:41 +00:00
|
|
|
endfunction
|
|
|
|
|
2018-07-15 17:24:53 +00:00
|
|
|
" Given a string for adding to a command, return the string padded with a
|
|
|
|
" space on the left if it is not empty. Otherwise return an empty string.
|
|
|
|
"
|
|
|
|
" This can be used for making command strings cleaner and easier to test.
|
|
|
|
function! ale#Pad(string) abort
|
|
|
|
return !empty(a:string) ? ' ' . a:string : ''
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Given a environment variable name and a value, produce part of a command for
|
|
|
|
" setting an environment variable before running a command. The syntax will be
|
|
|
|
" valid for cmd on Windows, or most shells on Unix.
|
|
|
|
function! ale#Env(variable_name, value) abort
|
|
|
|
if has('win32')
|
|
|
|
return 'set ' . a:variable_name . '=' . ale#Escape(a:value) . ' && '
|
|
|
|
endif
|
|
|
|
|
|
|
|
return a:variable_name . '=' . ale#Escape(a:value) . ' '
|
|
|
|
endfunction
|
|
|
|
|
2017-05-12 08:20:16 +00:00
|
|
|
" Escape a string suitably for each platform.
|
2017-05-15 19:21:18 +00:00
|
|
|
" shellescape does not work on Windows.
|
2017-05-12 08:20:16 +00:00
|
|
|
function! ale#Escape(str) abort
|
2017-08-08 07:39:13 +00:00
|
|
|
if fnamemodify(&shell, ':t') is? 'cmd.exe'
|
2017-06-14 10:05:49 +00:00
|
|
|
" If the string contains spaces, it will be surrounded by quotes.
|
|
|
|
" Otherwise, special characters will be escaped with carets (^).
|
|
|
|
return substitute(
|
|
|
|
\ a:str =~# ' '
|
|
|
|
\ ? '"' . substitute(a:str, '"', '""', 'g') . '"'
|
|
|
|
\ : substitute(a:str, '\v([&|<>^])', '^\1', 'g'),
|
|
|
|
\ '%',
|
|
|
|
\ '%%',
|
|
|
|
\ 'g',
|
|
|
|
\)
|
2017-05-12 08:20:16 +00:00
|
|
|
endif
|
2017-05-25 23:06:16 +00:00
|
|
|
|
|
|
|
return shellescape (a:str)
|
2017-05-12 08:20:16 +00:00
|
|
|
endfunction
|
2017-11-14 10:28:36 +00:00
|
|
|
|
|
|
|
" Get the loclist item message according to a given format string.
|
|
|
|
"
|
|
|
|
" See `:help g:ale_loclist_msg_format` and `:help g:ale_echo_msg_format`
|
|
|
|
function! ale#GetLocItemMessage(item, format_string) abort
|
|
|
|
let l:msg = a:format_string
|
|
|
|
let l:severity = g:ale_echo_msg_warning_str
|
|
|
|
let l:code = get(a:item, 'code', '')
|
|
|
|
let l:type = get(a:item, 'type', 'E')
|
|
|
|
let l:linter_name = get(a:item, 'linter_name', '')
|
|
|
|
let l:code_repl = !empty(l:code) ? '\=submatch(1) . l:code . submatch(2)' : ''
|
|
|
|
|
|
|
|
if l:type is# 'E'
|
|
|
|
let l:severity = g:ale_echo_msg_error_str
|
|
|
|
elseif l:type is# 'I'
|
|
|
|
let l:severity = g:ale_echo_msg_info_str
|
|
|
|
endif
|
|
|
|
|
|
|
|
" Replace special markers with certain information.
|
|
|
|
" \=l:variable is used to avoid escaping issues.
|
|
|
|
let l:msg = substitute(l:msg, '\V%severity%', '\=l:severity', 'g')
|
|
|
|
let l:msg = substitute(l:msg, '\V%linter%', '\=l:linter_name', 'g')
|
|
|
|
let l:msg = substitute(l:msg, '\v\%([^\%]*)code([^\%]*)\%', l:code_repl, 'g')
|
|
|
|
" Replace %s with the text.
|
|
|
|
let l:msg = substitute(l:msg, '\V%s', '\=a:item.text', 'g')
|
|
|
|
|
|
|
|
return l:msg
|
|
|
|
endfunction
|