2016-10-03 14:41:02 -04:00
|
|
|
" Author: w0rp <devw0rp@gmail.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 14:51:29 -04:00
|
|
|
" Description: Backend execution and job management
|
|
|
|
" Executes linters in the background, using NeoVim or Vim 8 jobs
|
2016-09-17 07:06:53 -04:00
|
|
|
|
2016-09-14 06:47:52 -04:00
|
|
|
" Stores information for each job including:
|
|
|
|
"
|
|
|
|
" linter: The linter dictionary for the job.
|
|
|
|
" buffer: The buffer number for the job.
|
2016-10-08 12:27:59 -04:00
|
|
|
" output: The array of lines for the output of the job.
|
2016-09-14 06:47:52 -04:00
|
|
|
let s:job_info_map = {}
|
|
|
|
|
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 14:51:29 -04:00
|
|
|
function! s:GetJobID(job) abort
|
|
|
|
if has('nvim')
|
|
|
|
"In NeoVim, job values are just IDs.
|
|
|
|
return a:job
|
2016-09-11 11:49:55 -04:00
|
|
|
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 14:51:29 -04:00
|
|
|
" In Vim 8, the job is a special variable, and we open a channel for each
|
|
|
|
" job. We'll use the ID of the channel instead as the job ID.
|
|
|
|
return ch_info(job_getchannel(a:job)).id
|
2016-09-11 11:49:55 -04:00
|
|
|
endfunction
|
|
|
|
|
2016-10-23 17:41:00 -04:00
|
|
|
function! ale#engine#InitBufferInfo(buffer) abort
|
|
|
|
if !has_key(g:ale_buffer_info, a:buffer)
|
2016-10-31 09:45:22 -04:00
|
|
|
" job_list will hold the list of jobs
|
|
|
|
" loclist holds the loclist items after all jobs have completed.
|
|
|
|
" new_loclist holds loclist items while jobs are being run.
|
2016-10-23 17:41:00 -04:00
|
|
|
let g:ale_buffer_info[a:buffer] = {
|
|
|
|
\ 'job_list': [],
|
2016-10-24 15:21:32 -04:00
|
|
|
\ 'loclist': [],
|
2016-10-31 09:45:22 -04:00
|
|
|
\ 'new_loclist': [],
|
2016-10-23 17:41:00 -04:00
|
|
|
\}
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! ale#engine#ClearJob(job) abort
|
2016-10-10 19:00:09 -04:00
|
|
|
let l:job_id = s:GetJobID(a:job)
|
|
|
|
let l:linter = s:job_info_map[l:job_id].linter
|
2016-09-08 19:23:26 -04:00
|
|
|
|
2016-09-09 20:37:40 -04:00
|
|
|
if has('nvim')
|
2016-09-08 19:23:26 -04:00
|
|
|
call jobstop(a:job)
|
2016-09-09 20:37:40 -04:00
|
|
|
else
|
2016-09-27 10:06:26 -04:00
|
|
|
" We must close the channel for reading the buffer if it is open
|
|
|
|
" when stopping a job. Otherwise, we will get errors in the status line.
|
|
|
|
if ch_status(job_getchannel(a:job)) ==# 'open'
|
|
|
|
call ch_close_in(job_getchannel(a:job))
|
|
|
|
endif
|
|
|
|
|
2016-09-09 20:37:40 -04:00
|
|
|
call job_stop(a:job)
|
2016-09-08 19:23:26 -04:00
|
|
|
endif
|
2016-09-09 20:37:40 -04:00
|
|
|
|
2016-10-10 19:00:09 -04:00
|
|
|
call remove(s:job_info_map, l:job_id)
|
2016-10-23 17:41:00 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:StopPreviousJobs(buffer, linter) abort
|
|
|
|
let l:new_job_list = []
|
|
|
|
|
|
|
|
for l:job in g:ale_buffer_info[a:buffer].job_list
|
|
|
|
let l:job_id = s:GetJobID(l:job)
|
|
|
|
|
|
|
|
if has_key(s:job_info_map, l:job_id)
|
|
|
|
\&& s:job_info_map[l:job_id].linter.name ==# a:linter.name
|
|
|
|
" Stop jobs which match the buffer and linter.
|
|
|
|
call ale#engine#ClearJob(l:job)
|
|
|
|
else
|
|
|
|
" Keep other jobs in the list.
|
|
|
|
call add(l:new_job_list, l:job)
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
|
|
|
|
" Update the list, removing the previously run job.
|
|
|
|
let g:ale_buffer_info[a:buffer].job_list = l:new_job_list
|
2016-09-08 19:23:26 -04:00
|
|
|
endfunction
|
|
|
|
|
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 14:51:29 -04:00
|
|
|
function! s:GatherOutput(job, data) abort
|
2016-10-10 19:00:09 -04:00
|
|
|
let l:job_id = s:GetJobID(a:job)
|
2016-10-08 12:27:59 -04:00
|
|
|
|
2016-10-10 19:00:09 -04:00
|
|
|
if !has_key(s:job_info_map, l:job_id)
|
2016-09-08 19:23:26 -04:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2016-10-10 19:00:09 -04:00
|
|
|
call extend(s:job_info_map[l:job_id].output, a:data)
|
2016-09-08 19:23:26 -04:00
|
|
|
endfunction
|
|
|
|
|
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 14:51:29 -04:00
|
|
|
function! s:GatherOutputVim(channel, data) abort
|
2016-09-09 20:37:40 -04:00
|
|
|
call s:GatherOutput(ch_getjob(a:channel), [a:data])
|
|
|
|
endfunction
|
|
|
|
|
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 14:51:29 -04:00
|
|
|
function! s:GatherOutputNeoVim(job, data, event) abort
|
|
|
|
call s:GatherOutput(a:job, a:data)
|
2016-10-04 13:17:02 -04:00
|
|
|
endfunction
|
|
|
|
|
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 14:51:29 -04:00
|
|
|
function! s:HandleExit(job) abort
|
2016-10-08 18:55:58 -04:00
|
|
|
if a:job ==# 'no process'
|
2016-10-08 16:04:42 -04:00
|
|
|
" Stop right away when the job is not valid in Vim 8.
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2016-10-10 19:00:09 -04:00
|
|
|
let l:job_id = s:GetJobID(a:job)
|
2016-10-08 12:27:59 -04:00
|
|
|
|
2016-10-10 19:00:09 -04:00
|
|
|
if !has_key(s:job_info_map, l:job_id)
|
2016-09-08 19:23:26 -04:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2016-10-10 19:00:09 -04:00
|
|
|
let l:job_info = s:job_info_map[l:job_id]
|
|
|
|
let l:linter = l:job_info.linter
|
|
|
|
let l:output = l:job_info.output
|
|
|
|
let l:buffer = l:job_info.buffer
|
2016-09-08 19:23:26 -04:00
|
|
|
|
2016-10-24 04:58:45 -04:00
|
|
|
" Call the same function for stopping jobs again to clean up the job
|
|
|
|
" which just closed.
|
2016-10-23 17:41:00 -04:00
|
|
|
call s:StopPreviousJobs(l:buffer, l:linter)
|
2016-10-13 10:13:11 -04:00
|
|
|
|
2016-10-10 19:00:09 -04:00
|
|
|
let l:linter_loclist = ale#util#GetFunction(l:linter.callback)(l:buffer, l:output)
|
2016-09-14 06:47:52 -04:00
|
|
|
|
2016-10-04 13:17:02 -04:00
|
|
|
" Make some adjustments to the loclists to fix common problems.
|
2016-10-10 19:00:09 -04:00
|
|
|
call s:FixLocList(l:buffer, l:linter_loclist)
|
2016-10-09 16:44:50 -04:00
|
|
|
|
2016-10-10 19:00:09 -04:00
|
|
|
for l:item in l:linter_loclist
|
|
|
|
let l:item.linter_name = l:linter.name
|
2016-10-10 14:56:05 -04:00
|
|
|
endfor
|
|
|
|
|
2016-09-08 19:23:26 -04:00
|
|
|
" Add the loclist items from the linter.
|
2016-10-31 09:45:22 -04:00
|
|
|
call extend(g:ale_buffer_info[l:buffer].new_loclist, l:linter_loclist)
|
|
|
|
|
|
|
|
if !empty(g:ale_buffer_info[l:buffer].job_list)
|
|
|
|
" Wait for all jobs to complete before doing anything else.
|
|
|
|
return
|
|
|
|
endif
|
2016-09-08 19:23:26 -04:00
|
|
|
|
|
|
|
" Sort the loclist again.
|
|
|
|
" We need a sorted list so we can run a binary search against it
|
|
|
|
" for efficient lookup of the messages in the cursor handler.
|
2016-10-31 09:45:22 -04:00
|
|
|
call sort(g:ale_buffer_info[l:buffer].new_loclist, 'ale#util#LocItemCompare')
|
|
|
|
|
|
|
|
" Now swap the old and new loclists, after we have collected everything
|
|
|
|
" and sorted the list again.
|
|
|
|
let g:ale_buffer_info[l:buffer].loclist = g:ale_buffer_info[l:buffer].new_loclist
|
|
|
|
let g:ale_buffer_info[l:buffer].new_loclist = []
|
2016-09-08 19:23:26 -04:00
|
|
|
|
|
|
|
if g:ale_set_loclist
|
2016-10-24 15:21:32 -04:00
|
|
|
call setloclist(0, g:ale_buffer_info[l:buffer].loclist)
|
2016-09-08 19:23:26 -04:00
|
|
|
endif
|
|
|
|
|
|
|
|
if g:ale_set_signs
|
2016-10-24 15:21:32 -04:00
|
|
|
call ale#sign#SetSigns(l:buffer, g:ale_buffer_info[l:buffer].loclist)
|
2016-09-08 19:23:26 -04:00
|
|
|
endif
|
|
|
|
|
Implement a more efficient statusbar
The statusbar now keeps its state in a separate variable, in order to
avoid excess iterations. The engine now updates said variable on run,
and a new function is made available for external statusbars to call (to
avoid dependencies on internal implementation details of ale).
To keep things light, the status bar code is not loaded unless invoked
by the user or an external plugin. On the first load it will update
itself from the global loclist, after that, the engine will handle all
updates.
The external integration function, `ale#statusline#Count()`, will return
a tuple in the format [E, W] (where E is errors, W is warnings), unless
no data exists (ie, the plugin doesn't have a linter for a file or has
not run yet), in which case it returns 0/false.
2016-10-11 17:51:01 -04:00
|
|
|
if exists('*ale#statusline#Update')
|
|
|
|
" Don't load/run if not already loaded.
|
2016-10-24 15:21:32 -04:00
|
|
|
call ale#statusline#Update(l:buffer, g:ale_buffer_info[l:buffer].loclist)
|
Implement a more efficient statusbar
The statusbar now keeps its state in a separate variable, in order to
avoid excess iterations. The engine now updates said variable on run,
and a new function is made available for external statusbars to call (to
avoid dependencies on internal implementation details of ale).
To keep things light, the status bar code is not loaded unless invoked
by the user or an external plugin. On the first load it will update
itself from the global loclist, after that, the engine will handle all
updates.
The external integration function, `ale#statusline#Count()`, will return
a tuple in the format [E, W] (where E is errors, W is warnings), unless
no data exists (ie, the plugin doesn't have a linter for a file or has
not run yet), in which case it returns 0/false.
2016-10-11 17:51:01 -04:00
|
|
|
endif
|
|
|
|
|
2016-10-12 16:13:22 -04:00
|
|
|
" Call user autocommands. This allows users to hook into ALE's lint cycle.
|
2016-10-14 14:17:12 -04:00
|
|
|
silent doautocmd User ALELint
|
2016-10-12 16:13:22 -04:00
|
|
|
|
2016-09-08 19:23:26 -04:00
|
|
|
" Mark line 200, column 17 with a squiggly line or something
|
|
|
|
" matchadd('ALEError', '\%200l\%17v')
|
|
|
|
endfunction
|
|
|
|
|
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 14:51:29 -04:00
|
|
|
function! s:HandleExitNeoVim(job, data, event) abort
|
2016-09-09 20:37:40 -04:00
|
|
|
call s:HandleExit(a:job)
|
|
|
|
endfunction
|
|
|
|
|
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 14:51:29 -04:00
|
|
|
function! s:HandleExitVim(channel) abort
|
2016-09-09 20:37:40 -04:00
|
|
|
call s:HandleExit(ch_getjob(a:channel))
|
|
|
|
endfunction
|
|
|
|
|
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 14:51:29 -04:00
|
|
|
function! s:FixLocList(buffer, loclist) abort
|
|
|
|
" Some errors have line numbers beyond the end of the file,
|
|
|
|
" so we need to adjust them so they set the error at the last line
|
|
|
|
" of the file instead.
|
2016-10-10 19:00:09 -04:00
|
|
|
let l:last_line_number = ale#util#GetLineCount(a: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 14:51:29 -04:00
|
|
|
|
2016-10-10 19:00:09 -04:00
|
|
|
for l:item in a:loclist
|
|
|
|
if l:item.lnum == 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 14:51:29 -04:00
|
|
|
" When errors appear at line 0, put them at line 1 instead.
|
2016-10-10 19:00:09 -04:00
|
|
|
let l:item.lnum = 1
|
|
|
|
elseif l:item.lnum > l:last_line_number
|
|
|
|
let l:item.lnum = l:last_line_number
|
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 14:51:29 -04:00
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! ale#engine#Invoke(buffer, linter) abort
|
2016-10-23 17:41:00 -04:00
|
|
|
" Stop previous jobs for the same linter.
|
|
|
|
call s:StopPreviousJobs(a:buffer, a:linter)
|
2016-09-08 19:23:26 -04:00
|
|
|
|
2016-09-11 11:49:55 -04:00
|
|
|
if has_key(a:linter, 'command_callback')
|
|
|
|
" If there is a callback for generating a command, call that instead.
|
2016-10-10 19:00:09 -04:00
|
|
|
let l:command = ale#util#GetFunction(a:linter.command_callback)(a:buffer)
|
2016-09-11 11:49:55 -04:00
|
|
|
else
|
2016-10-10 19:00:09 -04:00
|
|
|
let l:command = a:linter.command
|
2016-09-11 11:49:55 -04:00
|
|
|
endif
|
|
|
|
|
2016-10-10 19:00:09 -04:00
|
|
|
if l:command =~# '%s'
|
2016-10-04 08:50:44 -04:00
|
|
|
" If there is a '%s' in the command string, replace it with the name
|
|
|
|
" of the file.
|
2016-10-10 19:00:09 -04:00
|
|
|
let l:command = printf(l:command, shellescape(fnamemodify(bufname(a:buffer), ':p')))
|
2016-10-04 08:50:44 -04:00
|
|
|
endif
|
|
|
|
|
2016-09-09 20:37:40 -04:00
|
|
|
if has('nvim')
|
2016-09-15 15:20:41 -04:00
|
|
|
if a:linter.output_stream ==# 'stderr'
|
|
|
|
" Read from stderr instead of stdout.
|
2016-10-10 19:00:09 -04:00
|
|
|
let l:job = jobstart(l:command, {
|
2016-09-15 15:20:41 -04:00
|
|
|
\ 'on_stderr': 's:GatherOutputNeoVim',
|
|
|
|
\ 'on_exit': 's:HandleExitNeoVim',
|
|
|
|
\})
|
2016-10-07 12:08:11 -04:00
|
|
|
elseif a:linter.output_stream ==# 'both'
|
2016-10-10 19:00:09 -04:00
|
|
|
let l:job = jobstart(l:command, {
|
2016-10-07 12:08:11 -04:00
|
|
|
\ 'on_stdout': 's:GatherOutputNeoVim',
|
|
|
|
\ 'on_stderr': 's:GatherOutputNeoVim',
|
|
|
|
\ 'on_exit': 's:HandleExitNeoVim',
|
|
|
|
\})
|
2016-09-15 15:20:41 -04:00
|
|
|
else
|
2016-10-10 19:00:09 -04:00
|
|
|
let l:job = jobstart(l:command, {
|
2016-09-15 15:20:41 -04:00
|
|
|
\ 'on_stdout': 's:GatherOutputNeoVim',
|
|
|
|
\ 'on_exit': 's:HandleExitNeoVim',
|
|
|
|
\})
|
|
|
|
endif
|
2016-09-09 20:37:40 -04:00
|
|
|
else
|
2016-10-10 19:00:09 -04:00
|
|
|
let l:job_options = {
|
2016-10-08 16:52:41 -04:00
|
|
|
\ 'in_mode': 'nl',
|
2016-09-09 20:37:40 -04:00
|
|
|
\ 'out_mode': 'nl',
|
|
|
|
\ 'err_mode': 'nl',
|
|
|
|
\ 'close_cb': function('s:HandleExitVim'),
|
2016-09-15 15:20:41 -04:00
|
|
|
\}
|
|
|
|
|
|
|
|
if a:linter.output_stream ==# 'stderr'
|
|
|
|
" Read from stderr instead of stdout.
|
2016-10-10 19:00:09 -04:00
|
|
|
let l:job_options.err_cb = function('s:GatherOutputVim')
|
2016-10-07 12:08:11 -04:00
|
|
|
elseif a:linter.output_stream ==# 'both'
|
|
|
|
" Read from both streams.
|
2016-10-10 19:00:09 -04:00
|
|
|
let l:job_options.out_cb = function('s:GatherOutputVim')
|
|
|
|
let l:job_options.err_cb = function('s:GatherOutputVim')
|
2016-09-15 15:20:41 -04:00
|
|
|
else
|
2016-10-10 19:00:09 -04:00
|
|
|
let l:job_options.out_cb = function('s:GatherOutputVim')
|
2016-09-15 15:20:41 -04:00
|
|
|
endif
|
|
|
|
|
2016-10-08 11:01:17 -04:00
|
|
|
if has('win32')
|
|
|
|
" job_start commands on Windows have to be run with cmd /c,
|
|
|
|
" othwerwise %PATHTEXT% will not be used to programs ending int
|
|
|
|
" .cmd, .bat, .exe, etc.
|
|
|
|
let l:command = 'cmd /c ' . l:command
|
2016-10-10 13:56:39 -04:00
|
|
|
else
|
2016-10-10 17:56:12 -04:00
|
|
|
" Execute the command with the shell, to fix escaping issues.
|
|
|
|
let l:command = split(&shell) + split(&shellcmdflag) + [l:command]
|
|
|
|
|
2016-10-10 13:56:39 -04:00
|
|
|
" On Unix machines, we can send the Vim buffer directly.
|
2016-10-08 16:52:41 -04:00
|
|
|
" This is faster than reading the lines ourselves.
|
2016-10-10 19:00:09 -04:00
|
|
|
let l:job_options.in_io = 'buffer'
|
|
|
|
let l:job_options.in_buf = a:buffer
|
2016-10-08 11:01:17 -04:00
|
|
|
endif
|
|
|
|
|
2016-09-15 15:20:41 -04:00
|
|
|
" Vim 8 will read the stdin from the file's buffer.
|
2016-10-10 19:00:09 -04:00
|
|
|
let l:job = job_start(l:command, l:job_options)
|
2016-09-09 20:37:40 -04:00
|
|
|
endif
|
2016-09-08 19:23:26 -04:00
|
|
|
|
2016-10-08 16:52:41 -04:00
|
|
|
" Only proceed if the job is being run.
|
2016-10-10 19:00:09 -04:00
|
|
|
if has('nvim') || (l:job !=# 'no process' && job_status(l:job) ==# 'run')
|
2016-10-23 17:41:00 -04:00
|
|
|
" Add the job to the list of jobs, so we can track them.
|
|
|
|
call add(g:ale_buffer_info[a:buffer].job_list, l:job)
|
2016-09-08 19:23:26 -04:00
|
|
|
|
2016-10-08 16:04:42 -04:00
|
|
|
" Store the ID for the job in the map to read back again.
|
2016-10-10 19:00:09 -04:00
|
|
|
let s:job_info_map[s:GetJobID(l:job)] = {
|
2016-10-08 16:04:42 -04:00
|
|
|
\ 'linter': a:linter,
|
|
|
|
\ 'buffer': a:buffer,
|
|
|
|
\ 'output': [],
|
|
|
|
\}
|
|
|
|
|
|
|
|
if has('nvim')
|
2016-10-08 16:52:41 -04:00
|
|
|
" In NeoVim, we have to send the buffer lines ourselves.
|
2016-10-10 19:00:09 -04:00
|
|
|
let l:input = join(getbufline(a:buffer, 1, '$'), "\n") . "\n"
|
2016-10-08 16:52:41 -04:00
|
|
|
|
2016-10-10 19:00:09 -04:00
|
|
|
call jobsend(l:job, l:input)
|
|
|
|
call jobclose(l:job, 'stdin')
|
2016-10-10 13:56:39 -04:00
|
|
|
elseif has('win32')
|
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 14:51:29 -04:00
|
|
|
" On some Vim versions, we have to send the buffer data ourselves.
|
2016-10-10 19:00:09 -04:00
|
|
|
let l:input = join(getbufline(a:buffer, 1, '$'), "\n") . "\n"
|
|
|
|
let l:channel = job_getchannel(l:job)
|
2016-10-08 16:52:41 -04:00
|
|
|
|
2016-10-10 19:00:09 -04:00
|
|
|
if ch_status(l:channel) ==# 'open'
|
|
|
|
call ch_sendraw(l:channel, l:input)
|
|
|
|
call ch_close_in(l:channel)
|
2016-10-08 16:52:41 -04:00
|
|
|
endif
|
2016-10-08 16:04:42 -04:00
|
|
|
endif
|
2016-09-09 20:37:40 -04:00
|
|
|
endif
|
2016-09-08 19:23:26 -04:00
|
|
|
endfunction
|
2016-10-17 18:26:19 -04:00
|
|
|
|
2016-10-24 15:21:32 -04:00
|
|
|
" Given a buffer number, return the warnings and errors for a given buffer.
|
|
|
|
function! ale#engine#GetLoclist(buffer) abort
|
|
|
|
if !has_key(g:ale_buffer_info, a:buffer)
|
|
|
|
return []
|
|
|
|
endif
|
|
|
|
|
|
|
|
return g:ale_buffer_info[a:buffer].loclist
|
|
|
|
endfunction
|
|
|
|
|
2016-10-17 18:26:19 -04:00
|
|
|
" This function can be called with a timeout to wait for all jobs to finish.
|
|
|
|
" If the jobs to not finish in the given number of milliseconds,
|
|
|
|
" an exception will be thrown.
|
|
|
|
"
|
|
|
|
" The time taken will be a very rough approximation, and more time may be
|
|
|
|
" permitted than is specified.
|
|
|
|
function! ale#engine#WaitForJobs(deadline) abort
|
2016-10-17 18:43:31 -04:00
|
|
|
let l:start_time = system('date +%s%3N') + 0
|
|
|
|
|
|
|
|
if l:start_time == 0
|
|
|
|
throw 'Failed to read milliseconds from the clock!'
|
|
|
|
endif
|
|
|
|
|
2016-10-17 18:26:19 -04:00
|
|
|
let l:job_list = []
|
|
|
|
|
2016-10-24 04:58:45 -04:00
|
|
|
" Gather all of the jobs from every buffer.
|
2016-10-23 17:41:00 -04:00
|
|
|
for l:info in values(g:ale_buffer_info)
|
|
|
|
call extend(l:job_list, l:info.job_list)
|
2016-10-17 18:26:19 -04:00
|
|
|
endfor
|
|
|
|
|
|
|
|
let l:should_wait_more = 1
|
|
|
|
|
|
|
|
while l:should_wait_more
|
|
|
|
let l:should_wait_more = 0
|
|
|
|
|
|
|
|
for l:job in l:job_list
|
|
|
|
if job_status(l:job) ==# 'run'
|
2016-10-17 18:43:31 -04:00
|
|
|
let l:now = system('date +%s%3N') + 0
|
|
|
|
|
|
|
|
if l:now - l:start_time > a:deadline
|
2016-10-17 18:26:19 -04:00
|
|
|
" Stop waiting after a timeout, so we don't wait forever.
|
|
|
|
throw 'Jobs did not complete on time!'
|
|
|
|
endif
|
|
|
|
|
|
|
|
" Wait another 10 milliseconds
|
|
|
|
let l:should_wait_more = 1
|
|
|
|
sleep 10ms
|
|
|
|
break
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
endwhile
|
2016-10-17 18:43:31 -04:00
|
|
|
|
|
|
|
" Sleep for a small amount of time after all jobs finish.
|
|
|
|
" This seems to be enough to let handlers after jobs end run, and
|
|
|
|
" prevents the occasional failure where this function exits after jobs
|
|
|
|
" end, but before handlers are run.
|
|
|
|
sleep 10ms
|
2016-10-17 18:26:19 -04:00
|
|
|
endfunction
|