2016-10-03 18:41:02 +00:00
|
|
|
" Author: w0rp <devw0rp@gmail.com>
|
|
|
|
" Description: Contains miscellaneous functions
|
|
|
|
|
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
|
|
|
function! s:FindWrapperScript() abort
|
2016-10-10 23:00:09 +00:00
|
|
|
for l:parent in split(&runtimepath, ',')
|
2016-09-18 22:58:04 +00:00
|
|
|
" Expand the path to deal with ~ issues.
|
2016-10-10 23:00:09 +00:00
|
|
|
let l:path = expand(l:parent . '/' . 'stdin-wrapper')
|
2016-09-18 22:58:04 +00:00
|
|
|
|
2016-10-10 23:00:09 +00:00
|
|
|
if filereadable(l:path)
|
2016-10-07 20:33:16 +00:00
|
|
|
if has('win32')
|
2016-12-13 09:50:42 +00:00
|
|
|
return l:path . '.bat'
|
2016-10-07 20:33:16 +00:00
|
|
|
endif
|
|
|
|
|
2016-10-10 23:00:09 +00:00
|
|
|
return l:path
|
2016-09-18 22:58:04 +00:00
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
let g:ale#util#stdin_wrapper = s:FindWrapperScript()
|
2016-10-04 17:17:02 +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
|
|
|
" 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
|
|
|
|
|
2016-10-04 17:17:02 +00:00
|
|
|
" Return the number of lines for a given 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
|
|
|
function! ale#util#GetLineCount(buffer) abort
|
2016-10-04 17:17:02 +00:00
|
|
|
return len(getbufline(a:buffer, 1, '$'))
|
|
|
|
endfunction
|
2016-10-04 17:24:46 +00:00
|
|
|
|
|
|
|
" Given a buffer and a filename, find the nearest file by searching upwards
|
|
|
|
" through the paths relative to the given 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
|
|
|
function! ale#util#FindNearestFile(buffer, filename) abort
|
2016-10-17 20:14:34 +00:00
|
|
|
let l:buffer_filename = fnamemodify(bufname(a:buffer), ':p')
|
|
|
|
|
|
|
|
let l:relative_path = findfile(a:filename, l:buffer_filename . ';')
|
|
|
|
|
|
|
|
if !empty(l:relative_path)
|
|
|
|
return fnamemodify(l:relative_path, ':p')
|
|
|
|
endif
|
|
|
|
|
|
|
|
return ''
|
2016-10-04 17:24:46 +00:00
|
|
|
endfunction
|
2016-10-07 17:33:16 +00:00
|
|
|
|
2017-01-20 17:30:23 +00:00
|
|
|
" Given a buffer and a directory name, find the nearest directory by searching upwards
|
|
|
|
" through the paths relative to the given buffer.
|
|
|
|
function! ale#util#FindNearestDirectory(buffer, directory_name) abort
|
|
|
|
let l:buffer_filename = fnamemodify(bufname(a:buffer), ':p')
|
|
|
|
|
|
|
|
let l:relative_path = finddir(a:directory_name, l:buffer_filename . ';')
|
|
|
|
|
|
|
|
if !empty(l:relative_path)
|
|
|
|
return fnamemodify(l:relative_path, ':p')
|
|
|
|
endif
|
|
|
|
|
|
|
|
return ''
|
|
|
|
endfunction
|
|
|
|
|
2016-10-23 12:04:41 +00:00
|
|
|
" Given a buffer, a string to search for, an a global fallback for when
|
|
|
|
" the search fails, look for a file in parent paths, and if that fails,
|
|
|
|
" use the global fallback path instead.
|
|
|
|
function! ale#util#ResolveLocalPath(buffer, search_string, global_fallback) abort
|
|
|
|
" Search for a locally installed file first.
|
|
|
|
let l:path = ale#util#FindNearestFile(a:buffer, a:search_string)
|
|
|
|
|
|
|
|
" If the serach fails, try the global executable instead.
|
|
|
|
if empty(l:path)
|
|
|
|
let l:path = a:global_fallback
|
|
|
|
endif
|
|
|
|
|
|
|
|
return l:path
|
|
|
|
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 18:51:29 +00:00
|
|
|
function! ale#util#GetFunction(string_or_ref) abort
|
|
|
|
if type(a:string_or_ref) == type('')
|
|
|
|
return function(a:string_or_ref)
|
|
|
|
endif
|
2016-10-07 17:33:16 +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
|
|
|
return a:string_or_ref
|
|
|
|
endfunction
|
2016-10-13 19:56:18 +00:00
|
|
|
|
|
|
|
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
|
2016-10-13 20:24:47 +00:00
|
|
|
|
|
|
|
" This function will perform a binary search to find a message from the
|
|
|
|
" loclist to echo when the cursor moves.
|
|
|
|
function! ale#util#BinarySearch(loclist, line, column) abort
|
|
|
|
let l:min = 0
|
|
|
|
let l:max = len(a:loclist) - 1
|
|
|
|
let l:last_column_match = -1
|
|
|
|
|
|
|
|
while 1
|
|
|
|
if l:max < l:min
|
|
|
|
return l:last_column_match
|
|
|
|
endif
|
|
|
|
|
|
|
|
let l:mid = (l:min + l:max) / 2
|
|
|
|
let l:obj = a:loclist[l:mid]
|
|
|
|
|
|
|
|
" Binary search to get on the same line
|
|
|
|
if a:loclist[l:mid]['lnum'] < a:line
|
|
|
|
let l:min = l:mid + 1
|
|
|
|
elseif a:loclist[l:mid]['lnum'] > a:line
|
|
|
|
let l:max = l:mid - 1
|
|
|
|
else
|
|
|
|
let l:last_column_match = l:mid
|
|
|
|
|
|
|
|
" Binary search to get the same column, or near it
|
|
|
|
if a:loclist[l:mid]['col'] < a:column
|
|
|
|
let l:min = l:mid + 1
|
|
|
|
elseif a:loclist[l:mid]['col'] > a:column
|
|
|
|
let l:max = l:mid - 1
|
|
|
|
else
|
|
|
|
return l:mid
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endwhile
|
|
|
|
endfunction
|