Skip to content

Commit b62543b

Browse files
committed
👍 Add supported_versions.json and use it in health check
1 parent 0608102 commit b62543b

File tree

2 files changed

+43
-31
lines changed

2 files changed

+43
-31
lines changed

autoload/health/denops.vim

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
const s:DENO_VERSION = '1.45.0'
2-
const s:VIM_VERSION = '9.1.0448'
3-
const s:NEOVIM_VERSION = '0.10.0'
1+
const s:root = resolve(expand('<sfile>:p:h:h:h'))
42

53
function! s:compare_version(v1, v2) abort
6-
let l:v1 = map(split(a:v1, '\.'), { _, v -> v + 0 })
7-
let l:v2 = map(split(a:v2, '\.'), { _, v -> v + 0 })
4+
const l:v1 = map(split(a:v1, '\.'), { _, v -> v + 0 })
5+
const l:v2 = map(split(a:v2, '\.'), { _, v -> v + 0 })
86
for l:i in range(max([len(l:v1), len(l:v2)]))
97
let l:t1 = get(l:v1, l:i, 0)
108
let l:t2 = get(l:v2, l:i, 0)
@@ -15,8 +13,16 @@ function! s:compare_version(v1, v2) abort
1513
return 0
1614
endfunction
1715

16+
function! s:load_supported_versions() abort
17+
const l:jsonfile = denops#_internal#path#join([s:root, 'denops', 'supported_versions.json'])
18+
if !filereadable(l:jsonfile)
19+
throw 'Failed to read <runtimepath>/denops/supported_versions.json'
20+
endif
21+
return json_decode(join(readfile(l:jsonfile), "\n"))
22+
endfunction
23+
1824
function! s:get_deno_version(deno) abort
19-
let l:output = system(printf('%s --version', a:deno))
25+
const l:output = system(printf('%s --version', a:deno))
2026
return matchstr(l:output, 'deno \zs[0-9.]\+')
2127
endfunction
2228

@@ -42,61 +48,49 @@ function! s:check_deno_executable() abort
4248
call s:report_ok('Deno executable check: passed')
4349
endfunction
4450

45-
function! s:check_deno_version() abort
46-
let l:deno_version = s:get_deno_version(g:denops#deno)
47-
call s:report_info(printf(
48-
\ 'Supported Deno version: `%s`',
49-
\ s:DENO_VERSION,
50-
\))
51+
function! s:check_deno_version(supported_version) abort
52+
const l:deno_version = s:get_deno_version(g:denops#deno)
5153
call s:report_info(printf(
5254
\ 'Detected Deno version: `%s`',
5355
\ l:deno_version,
5456
\))
5557
if empty(l:deno_version)
5658
call s:report_error('Unable to detect version of deno, make sure your deno runtime is correct.')
5759
return
58-
elseif s:compare_version(l:deno_version, s:DENO_VERSION) < 0
60+
elseif s:compare_version(l:deno_version, a:supported_version) < 0
5961
call s:report_error(printf(
6062
\ 'Unsupported Deno version is detected. You need to upgrade it to `%s` or later.',
61-
\ s:DENO_VERSION,
63+
\ a:supported_version,
6264
\))
6365
return
6466
endif
6567
call s:report_ok('Deno version check: passed')
6668
endfunction
6769

68-
function! s:check_vim_version() abort
69-
call s:report_info(printf(
70-
\ 'Supported Vim version: `%s`',
71-
\ s:VIM_VERSION,
72-
\))
70+
function! s:check_vim_version(supported_version) abort
7371
call s:report_info(printf(
7472
\ 'Detected Vim version: `%s`',
7573
\ denops#_internal#meta#get().version,
7674
\))
77-
if !has(printf('patch-%s', s:VIM_VERSION))
75+
if !has(printf('patch-%s', a:supported_version))
7876
call s:report_error(printf(
7977
\ 'Unsupported Vim version is detected. You need to upgrade it to `%s` or later.',
80-
\ s:VIM_VERSION,
78+
\ a:supported_version,
8179
\))
8280
return
8381
endif
8482
call s:report_ok('Vim version check: passed')
8583
endfunction
8684

87-
function! s:check_neovim_version() abort
88-
call s:report_info(printf(
89-
\ 'Supported Neovim version: `%s`',
90-
\ s:NEOVIM_VERSION,
91-
\))
85+
function! s:check_neovim_version(supported_version) abort
9286
call s:report_info(printf(
9387
\ 'Detected Neovim version: `%s`',
9488
\ denops#_internal#meta#get().version,
9589
\))
96-
if !has(printf('nvim-%s', s:NEOVIM_VERSION))
90+
if !has(printf('nvim-%s', a:supported_version))
9791
call s:report_error(printf(
9892
\ 'Unsupported Neovim version is detected. You need to upgrade it to `%s` or later.',
99-
\ s:NEOVIM_VERSION,
93+
\ a:supported_version,
10094
\))
10195
return
10296
endif
@@ -157,11 +151,24 @@ else
157151
endif
158152

159153
function! health#denops#check() abort
160-
call s:check_deno_version()
154+
const l:supported_versions = s:load_supported_versions()
155+
call s:report_info(printf(
156+
\ 'Supported Deno version: `%s`',
157+
\ l:supported_versions.deno,
158+
\))
159+
call s:report_info(printf(
160+
\ 'Supported Vim version: `%s`',
161+
\ l:supported_versions.vim,
162+
\))
163+
call s:report_info(printf(
164+
\ 'Supported Neovim version: `%s`',
165+
\ l:supported_versions.neovim,
166+
\))
167+
call s:check_deno_version(l:supported_versions.deno)
161168
if !has('nvim')
162-
call s:check_vim_version()
169+
call s:check_vim_version(l:supported_versions.vim)
163170
else
164-
call s:check_neovim_version()
171+
call s:check_neovim_version(l:supported_versions.neovim)
165172
endif
166173
call s:check_denops()
167174
call s:check_denops_status()

denops/supported_versions.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"deno": "1.45.0",
3+
"vim": "9.1.0448",
4+
"neovim": "0.10.0"
5+
}

0 commit comments

Comments
 (0)