mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
refactor(runtime): use vim.version to compare versions #22550
TODO:
Unfortunately, cannot (yet) use vim.version for tmux version comparison,
because `vim.version.parse(…,{strict=false})` does not coerce tmux's
funny "tmux 3.3a" version string.
6969d3d749/runtime/autoload/provider/clipboard.vim (L148)
This commit is contained in:
parent
7a462c10d5
commit
04e8e1f9ea
@ -19,22 +19,6 @@ function! s:cmd_ok(cmd) abort
|
|||||||
return v:shell_error == 0
|
return v:shell_error == 0
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Simple version comparison.
|
|
||||||
function! s:version_cmp(a, b) abort
|
|
||||||
let a = split(a:a, '\.', 0)
|
|
||||||
let b = split(a:b, '\.', 0)
|
|
||||||
|
|
||||||
for i in range(len(a))
|
|
||||||
if str2nr(a[i]) > str2nr(b[i])
|
|
||||||
return 1
|
|
||||||
elseif str2nr(a[i]) < str2nr(b[i])
|
|
||||||
return -1
|
|
||||||
endif
|
|
||||||
endfor
|
|
||||||
|
|
||||||
return 0
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
" Handler for s:system() function.
|
" Handler for s:system() function.
|
||||||
function! s:system_handler(jobid, data, event) dict abort
|
function! s:system_handler(jobid, data, event) dict abort
|
||||||
if a:event ==# 'stderr'
|
if a:event ==# 'stderr'
|
||||||
@ -244,7 +228,7 @@ function! s:version_info(python) abort
|
|||||||
let nvim_path_base = fnamemodify(nvim_path, ':~:h')
|
let nvim_path_base = fnamemodify(nvim_path, ':~:h')
|
||||||
let version_status = 'unknown; '.nvim_path_base
|
let version_status = 'unknown; '.nvim_path_base
|
||||||
if !s:is_bad_response(nvim_version) && !s:is_bad_response(pypi_version)
|
if !s:is_bad_response(nvim_version) && !s:is_bad_response(pypi_version)
|
||||||
if s:version_cmp(nvim_version, pypi_version) == -1
|
if v:lua.vim.version.lt(nvim_version, pypi_version)
|
||||||
let version_status = 'outdated; from '.nvim_path_base
|
let version_status = 'outdated; from '.nvim_path_base
|
||||||
else
|
else
|
||||||
let version_status = 'up to date'
|
let version_status = 'up to date'
|
||||||
@ -598,7 +582,7 @@ function! s:check_ruby() abort
|
|||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if s:version_cmp(current_gem, latest_gem) == -1
|
if v:lua.vim.version.lt(current_gem, latest_gem)
|
||||||
call health#report_warn(
|
call health#report_warn(
|
||||||
\ printf('Gem "neovim" is out-of-date. Installed: %s, latest: %s',
|
\ printf('Gem "neovim" is out-of-date. Installed: %s, latest: %s',
|
||||||
\ current_gem, latest_gem),
|
\ current_gem, latest_gem),
|
||||||
@ -623,8 +607,8 @@ function! s:check_node() abort
|
|||||||
endif
|
endif
|
||||||
let node_v = get(split(s:system(['node', '-v']), "\n"), 0, '')
|
let node_v = get(split(s:system(['node', '-v']), "\n"), 0, '')
|
||||||
call health#report_info('Node.js: '. node_v)
|
call health#report_info('Node.js: '. node_v)
|
||||||
if s:shell_error || s:version_cmp(node_v[1:], '6.0.0') < 0
|
if s:shell_error || v:lua.vim.version.lt(node_v[1:], '6.0.0')
|
||||||
call health#report_warn('Nvim node.js host does not support '.node_v)
|
call health#report_warn('Nvim node.js host does not support Node '.node_v)
|
||||||
" Skip further checks, they are nonsense if nodejs is too old.
|
" Skip further checks, they are nonsense if nodejs is too old.
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
@ -675,7 +659,7 @@ function! s:check_node() abort
|
|||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if s:version_cmp(current_npm, latest_npm) == -1
|
if latest_npm !=# 'unable to parse' && v:lua.vim.version.lt(current_npm, latest_npm)
|
||||||
call health#report_warn(
|
call health#report_warn(
|
||||||
\ printf('Package "neovim" is out-of-date. Installed: %s, latest: %s',
|
\ printf('Package "neovim" is out-of-date. Installed: %s, latest: %s',
|
||||||
\ current_npm, latest_npm),
|
\ current_npm, latest_npm),
|
||||||
@ -751,7 +735,7 @@ function! s:check_perl() abort
|
|||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if s:version_cmp(current_cpan, latest_cpan) == -1
|
if v:lua.vim.version.lt(current_cpan, latest_cpan)
|
||||||
call health#report_warn(
|
call health#report_warn(
|
||||||
\ printf('Module "Neovim::Ext" is out-of-date. Installed: %s, latest: %s',
|
\ printf('Module "Neovim::Ext" is out-of-date. Installed: %s, latest: %s',
|
||||||
\ current_cpan, latest_cpan),
|
\ current_cpan, latest_cpan),
|
||||||
|
@ -3,7 +3,7 @@ if exists('g:loaded_node_provider')
|
|||||||
endif
|
endif
|
||||||
let g:loaded_node_provider = 1
|
let g:loaded_node_provider = 1
|
||||||
|
|
||||||
function! s:is_minimum_version(version, min_major, min_minor) abort
|
function! s:is_minimum_version(version, min_version) abort
|
||||||
if empty(a:version)
|
if empty(a:version)
|
||||||
let nodejs_version = get(split(system(['node', '-v']), "\n"), 0, '')
|
let nodejs_version = get(split(system(['node', '-v']), "\n"), 0, '')
|
||||||
if v:shell_error || nodejs_version[0] !=# 'v'
|
if v:shell_error || nodejs_version[0] !=# 'v'
|
||||||
@ -15,11 +15,7 @@ function! s:is_minimum_version(version, min_major, min_minor) abort
|
|||||||
" Remove surrounding junk. Example: 'v4.12.0' => '4.12.0'
|
" Remove surrounding junk. Example: 'v4.12.0' => '4.12.0'
|
||||||
let nodejs_version = matchstr(nodejs_version, '\(\d\.\?\)\+')
|
let nodejs_version = matchstr(nodejs_version, '\(\d\.\?\)\+')
|
||||||
" [major, minor, patch]
|
" [major, minor, patch]
|
||||||
let v_list = split(nodejs_version, '\.')
|
return !v:lua.vim.version.lt(nodejs_version, a:min_version)
|
||||||
return len(v_list) == 3
|
|
||||||
\ && ((str2nr(v_list[0]) > str2nr(a:min_major))
|
|
||||||
\ || (str2nr(v_list[0]) == str2nr(a:min_major)
|
|
||||||
\ && str2nr(v_list[1]) >= str2nr(a:min_minor)))
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
let s:NodeHandler = {
|
let s:NodeHandler = {
|
||||||
@ -43,20 +39,20 @@ function! provider#node#can_inspect() abort
|
|||||||
if v:shell_error || ver[0] !=# 'v'
|
if v:shell_error || ver[0] !=# 'v'
|
||||||
return 0
|
return 0
|
||||||
endif
|
endif
|
||||||
return (ver[1] ==# '6' && s:is_minimum_version(ver, 6, 12))
|
return (ver[1] ==# '6' && s:is_minimum_version(ver, '6.12.0'))
|
||||||
\ || s:is_minimum_version(ver, 7, 6)
|
\ || s:is_minimum_version(ver, '7.6.0')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! provider#node#Detect() abort
|
function! provider#node#Detect() abort
|
||||||
let minver = [6, 0]
|
let minver = '6.0.0'
|
||||||
if exists('g:node_host_prog')
|
if exists('g:node_host_prog')
|
||||||
return [expand(g:node_host_prog, v:true), '']
|
return [expand(g:node_host_prog, v:true), '']
|
||||||
endif
|
endif
|
||||||
if !executable('node')
|
if !executable('node')
|
||||||
return ['', 'node not found (or not executable)']
|
return ['', 'node not found (or not executable)']
|
||||||
endif
|
endif
|
||||||
if !s:is_minimum_version(v:null, minver[0], minver[1])
|
if !s:is_minimum_version(v:null, minver)
|
||||||
return ['', printf('node version %s.%s not found', minver[0], minver[1])]
|
return ['', printf('node version %s not found', minver)]
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let npm_opts = {}
|
let npm_opts = {}
|
||||||
|
Loading…
Reference in New Issue
Block a user