Files
ale/autoload/ale/util.vim
Bjorn Neergaard 7f0ce89d2b 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 19:51:29 +01:00

66 lines
1.6 KiB
VimL

" Author: w0rp <devw0rp@gmail.com>
" Description: Contains miscellaneous functions
function! s:FindWrapperScript() abort
for parent in split(&runtimepath, ',')
" Expand the path to deal with ~ issues.
let path = expand(parent . '/' . 'stdin-wrapper')
if filereadable(path)
if has('win32')
return path . '.exe'
endif
return path
endif
endfor
endfunction
let g:ale#util#stdin_wrapper = s:FindWrapperScript()
" A null file for sending output to nothing.
let g:ale#util#nul_file = '/dev/null'
if has('win32')
let g:ale#util#nul_file = 'nul'
endif
" Return the number of lines for a given buffer.
function! ale#util#GetLineCount(buffer) abort
return len(getbufline(a:buffer, 1, '$'))
endfunction
" Given a buffer and a filename, find the nearest file by searching upwards
" through the paths relative to the given buffer.
function! ale#util#FindNearestFile(buffer, filename) abort
return findfile(a:filename, fnamemodify(bufname(a:buffer), ':p') . ';')
endfunction
function! ale#util#GetFunction(string_or_ref) abort
if type(a:string_or_ref) == type('')
return function(a:string_or_ref)
endif
return a:string_or_ref
endfunction
function! ale#util#LocItemCompare(left, right) abort
if a:left['lnum'] < a:right['lnum']
return -1
endif
if a:left['lnum'] > a:right['lnum']
return 1
endif
if a:left['col'] < a:right['col']
return -1
endif
if a:left['col'] > a:right['col']
return 1
endif
return 0
endfunction