diff options
Diffstat (limited to 'autoload')
-rw-r--r-- | autoload/ale/handlers/gcc.vim | 12 | ||||
-rw-r--r-- | autoload/ale/semver.vim | 52 |
2 files changed, 40 insertions, 24 deletions
diff --git a/autoload/ale/handlers/gcc.vim b/autoload/ale/handlers/gcc.vim index 256cd01d..9ec7b110 100644 --- a/autoload/ale/handlers/gcc.vim +++ b/autoload/ale/handlers/gcc.vim @@ -18,18 +18,6 @@ function! s:RemoveUnicodeQuotes(text) abort return l:text endfunction -function! ale#handlers#gcc#ParseGCCVersion(lines) abort - for l:line in a:lines - let l:match = matchstr(l:line, '\d\.\d\.\d') - - if !empty(l:match) - return ale#semver#Parse(l:match) - endif - endfor - - return [] -endfunction - function! ale#handlers#gcc#HandleGCCFormat(buffer, lines) abort " Look for lines like the following. " diff --git a/autoload/ale/semver.vim b/autoload/ale/semver.vim index b153dd1d..6b0fd34a 100644 --- a/autoload/ale/semver.vim +++ b/autoload/ale/semver.vim @@ -1,27 +1,55 @@ -" Given some text, parse a semantic versioning string from the text -" into a triple of integeers [major, minor, patch]. +let s:version_cache = {} + +" Reset the version cache used for parsing the version. +function! ale#semver#ResetVersionCache() abort + let s:version_cache = {} +endfunction + +" Given an executable name and some lines of output, which can be empty, +" parse the version from the lines of output, or return the cached version +" triple [major, minor, patch] " -" If no match can be performed, then an empty List will be returned instead. -function! ale#semver#Parse(text) abort - let l:match = matchlist(a:text, '^ *\(\d\+\)\.\(\d\+\)\.\(\d\+\)') +" If the version cannot be found, an empty List will be returned instead. +function! ale#semver#GetVersion(executable, version_lines) abort + let l:version = get(s:version_cache, a:executable, []) - if empty(l:match) - return [] - endif + for l:line in a:version_lines + let l:match = matchlist(l:line, '\v(\d+)\.(\d+)\.(\d+)') + + if !empty(l:match) + let l:version = [l:match[1] + 0, l:match[2] + 0, l:match[3] + 0] + let s:version_cache[a:executable] = l:version + + break + endif + endfor - return [l:match[1] + 0, l:match[2] + 0, l:match[3] + 0] + return l:version +endfunction + +" Return 1 if the semver version has been cached for a given executable. +function! ale#semver#HasVersion(executable) abort + return has_key(s:version_cache, a:executable) endfunction " Given two triples of integers [major, minor, patch], compare the triples -" and return 1 if the lhs is greater than or equal to the rhs. -function! ale#semver#GreaterOrEqual(lhs, rhs) abort +" and return 1 if the LHS is greater than or equal to the RHS. +" +" Pairs of [major, minor] can also be used for either argument. +" +" 0 will be returned if the LHS is an empty List. +function! ale#semver#GTE(lhs, rhs) abort + if empty(a:lhs) + return 0 + endif + if a:lhs[0] > a:rhs[0] return 1 elseif a:lhs[0] == a:rhs[0] if a:lhs[1] > a:rhs[1] return 1 elseif a:lhs[1] == a:rhs[1] - return a:lhs[2] >= a:rhs[2] + return get(a:lhs, 2) >= get(a:rhs, 2) endif endif |