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
|
|
|
" Author: w0rp <devw0rp@gmail.com>
|
|
|
|
" Description: Primary code path for the plugin
|
|
|
|
" Manages execution of linters when requested by autocommands
|
|
|
|
|
|
|
|
let s:lint_timer = -1
|
2017-04-25 22:52:13 +00:00
|
|
|
let s:queued_buffer_number = -1
|
2017-03-21 14:52:02 +00:00
|
|
|
let s:should_lint_file_for_buffer = {}
|
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-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.
|
|
|
|
function! ale#ShouldDoNothing() abort
|
|
|
|
" Do nothing for blacklisted files
|
|
|
|
" OR if ALE is running in the sandbox
|
|
|
|
return index(g:ale_filetype_blacklist, &filetype) >= 0
|
2017-04-03 18:21:11 +00:00
|
|
|
\ || (exists('*getcmdwintype') && !empty(getcmdwintype()))
|
2017-02-14 21:02:49 +00:00
|
|
|
\ || ale#util#InSandbox()
|
|
|
|
endfunction
|
|
|
|
|
2017-03-21 13:38:27 +00:00
|
|
|
" (delay, [linting_flag])
|
2017-03-14 23:51:57 +00:00
|
|
|
function! ale#Queue(delay, ...) abort
|
|
|
|
if len(a:0) > 1
|
|
|
|
throw 'too many arguments!'
|
|
|
|
endif
|
|
|
|
|
2017-03-21 14:52:02 +00:00
|
|
|
" Default linting_flag to ''
|
|
|
|
let l:linting_flag = get(a:000, 0, '')
|
2017-03-14 23:51:57 +00:00
|
|
|
|
2017-03-21 13:38:27 +00:00
|
|
|
if l:linting_flag !=# '' && l:linting_flag !=# 'lint_file'
|
|
|
|
throw "linting_flag must be either '' or 'lint_file'"
|
2017-03-14 23:51:57 +00:00
|
|
|
endif
|
|
|
|
|
2017-02-14 21:02:49 +00:00
|
|
|
if ale#ShouldDoNothing()
|
2016-10-31 14:47:08 +00:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2017-03-21 14:52:02 +00:00
|
|
|
" Remember that we want to check files for this buffer.
|
|
|
|
" We will remember this until we finally run the linters, via any event.
|
|
|
|
if l:linting_flag ==# 'lint_file'
|
|
|
|
let s:should_lint_file_for_buffer[bufnr('%')] = 1
|
|
|
|
endif
|
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
|
|
|
|
|
2016-10-10 23:00:09 +00:00
|
|
|
let l:linters = ale#linter#Get(&filetype)
|
|
|
|
if len(l:linters) == 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
|
|
|
" There are no linters to lint with, so stop here.
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
if a:delay > 0
|
2017-04-25 22:52:13 +00:00
|
|
|
let s:queued_buffer_number = bufnr('%')
|
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 = timer_start(a:delay, function('ale#Lint'))
|
|
|
|
else
|
|
|
|
call ale#Lint()
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! ale#Lint(...) abort
|
2017-02-14 21:02:49 +00:00
|
|
|
if ale#ShouldDoNothing()
|
2016-10-31 14:47:08 +00:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2017-04-25 22:52:13 +00:00
|
|
|
" Get the buffer number linting was queued for.
|
|
|
|
" or else take the current one.
|
|
|
|
let l:buffer = len(a:0) > 1 && a:1 == s:lint_timer
|
|
|
|
\ ? s:queued_buffer_number
|
|
|
|
\ : bufnr('%')
|
|
|
|
|
|
|
|
" Use the filetype from the buffer
|
|
|
|
let l:linters = ale#linter#Get(getbufvar(l:buffer, '&filetype'))
|
2017-03-21 14:52:02 +00:00
|
|
|
let l:should_lint_file = 0
|
|
|
|
|
|
|
|
" Check if we previously requested checking the file.
|
|
|
|
if has_key(s:should_lint_file_for_buffer, l:buffer)
|
|
|
|
unlet s:should_lint_file_for_buffer[l:buffer]
|
|
|
|
let l:should_lint_file = 1
|
|
|
|
endif
|
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
|
|
|
|
2016-10-23 21:41:00 +00:00
|
|
|
" Initialise the buffer information if needed.
|
|
|
|
call ale#engine#InitBufferInfo(l:buffer)
|
|
|
|
|
2016-10-31 13:45:22 +00:00
|
|
|
" Clear the new loclist again, so we will work with all new items.
|
|
|
|
let g:ale_buffer_info[l:buffer].new_loclist = []
|
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-03-21 14:52:02 +00:00
|
|
|
if l:should_lint_file
|
|
|
|
" Clear loclist items for files if we are checking files again.
|
|
|
|
let g:ale_buffer_info[l:buffer].lint_file_loclist = []
|
|
|
|
else
|
|
|
|
" Otherwise, don't run any `lint_file` linters
|
|
|
|
" We will continue running any linters which are currently checking
|
|
|
|
" the file, and the items will be mixed together with any new items.
|
|
|
|
call filter(l:linters, '!v:val.lint_file')
|
|
|
|
endif
|
|
|
|
|
2016-10-10 23:00:09 +00:00
|
|
|
for l:linter in l:linters
|
|
|
|
call ale#engine#Invoke(l:buffer, l:linter)
|
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
|
|
|
endfor
|
|
|
|
endfunction
|
2017-03-21 14:52:02 +00:00
|
|
|
|
|
|
|
" Reset flags indicating that files should be checked for all buffers.
|
|
|
|
function! ale#ResetLintFileMarkers() abort
|
|
|
|
let s:should_lint_file_for_buffer = {}
|
|
|
|
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
|
|
|
|
|
|
|
|
return getbufvar(a:buffer, l:full_name, g:[l:full_name])
|
|
|
|
endfunction
|