All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
1 let s:version_cache = {}
3 " Reset the version cache used for parsing the version.
4 function! ale#semver#ResetVersionCache() abort
5 let s:version_cache = {}
8 function! ale#semver#ParseVersion(version_lines) abort
9 for l:line in a:version_lines
10 let l:match = matchlist(l:line, '\v(\d+)\.(\d+)(\.(\d+))?')
13 return [l:match[1] + 0, l:match[2] + 0, l:match[4] + 0]
20 " Given an executable name and some lines of output, which can be empty,
21 " parse the version from the lines of output, or return the cached version
22 " triple [major, minor, patch]
24 " If the version cannot be found, an empty List will be returned instead.
25 function! s:GetVersion(executable, version_lines) abort
26 let l:version = get(s:version_cache, a:executable, [])
27 let l:parsed_version = ale#semver#ParseVersion(a:version_lines)
29 if !empty(l:parsed_version)
30 let l:version = l:parsed_version
31 let s:version_cache[a:executable] = l:version
37 function! ale#semver#RunWithVersionCheck(buffer, executable, command, Callback) abort
38 if empty(a:executable)
42 let l:cache = s:version_cache
44 if has_key(s:version_cache, a:executable)
45 return a:Callback(a:buffer, s:version_cache[a:executable])
48 return ale#command#Run(
51 \ {_, output -> a:Callback(a:buffer, s:GetVersion(a:executable, output))},
52 \ {'output_stream': 'both', 'executable': a:executable}
56 " Given two triples of integers [major, minor, patch], compare the triples
57 " and return 1 if the LHS is greater than or equal to the RHS.
59 " Pairs of [major, minor] can also be used for either argument.
61 " 0 will be returned if the LHS is an empty List.
62 function! ale#semver#GTE(lhs, rhs) abort
67 if a:lhs[0] > a:rhs[0]
69 elseif a:lhs[0] == a:rhs[0]
70 if a:lhs[1] > a:rhs[1]
72 elseif a:lhs[1] == a:rhs[1]
73 return get(a:lhs, 2) >= get(a:rhs, 2)