Skip to content

Commit 1245bb3

Browse files
committed
👍 Add denops#cache#update() function
1 parent fe902c8 commit 1245bb3

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

autoload/denops/cache.vim

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
let s:root = expand('<sfile>:p:h:h:h')
2+
let s:job = v:null
3+
4+
function! denops#cache#update(...) abort
5+
let l:options = extend(#{ reload: v:false }, a:0 ? a:1 : {})
6+
let l:entryfiles = extend([
7+
\ denops#_internal#path#join([s:root, 'denops', '@denops-private', 'mod.ts']),
8+
\], map(denops#_internal#plugin#collect(), { _, v -> v.script }))
9+
10+
let l:args = [g:denops#deno, 'cache']
11+
12+
if l:options.reload
13+
let l:args = add(l:args, '--reload')
14+
echomsg '[denops] Forcibly update cache of the following files.'
15+
else
16+
echomsg '[denops] Update cache of the following files. Call `denops#cache#update(#{reload: v:true})` to forcibly update.'
17+
endif
18+
19+
for l:entryfile in l:entryfiles
20+
echomsg printf('[denops] %s', l:entryfile)
21+
endfor
22+
let l:args = extend(l:args, l:entryfiles)
23+
24+
let s:job = denops#_internal#job#start(l:args, #{
25+
\ on_stderr: funcref('s:on_stderr'),
26+
\ on_exit: funcref('s:on_exit'),
27+
\ env: #{
28+
\ NO_COLOR: 1,
29+
\ DENO_NO_PROMPT: 1,
30+
\ },
31+
\})
32+
call denops#_internal#wait#for(60 * 1000, { -> s:job is# v:null }, 100)
33+
echomsg '[denops] Deno cache is updated.'
34+
endfunction
35+
36+
function! s:on_stderr(job, data, event) abort
37+
echohl Comment
38+
for l:line in split(a:data, '\n')
39+
echomsg printf('[denops] %s', substitute(l:line, '\t', ' ', 'g'))
40+
endfor
41+
echohl None
42+
endfunction
43+
44+
function! s:on_exit(job, status, event) abort
45+
let s:job = v:null
46+
endfunction

doc/denops.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,16 @@ denops#request_async({name}, {method}, {params}, {success}, {failure})
200200
\ { e -> s:failure(e) },
201201
\)
202202
<
203+
*denops#cache#update()*
204+
denops#cache#update([{options}])
205+
Update Deno module cache of denops itself and denops plugins in
206+
|runtimepath|.
207+
208+
The following {options} is available
209+
210+
"reload" |v:true| to force update ("--reload" flag of "deno
211+
cache") command.
212+
203213
*denops#server#start()*
204214
denops#server#start()
205215
Starts a denops server process and connects to the channel. It does

0 commit comments

Comments
 (0)