Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions autoload/denops.vim
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
function! denops#notify(plugin, method, params) abort
function! denops#notify(name, method, params) abort
call denops#_internal#server#chan#notify(
\ 'invoke',
\ ['dispatch', [a:plugin, a:method, a:params]],
\ ['dispatch', [a:name, a:method, a:params]],
\)
endfunction

function! denops#request(plugin, method, params) abort
function! denops#request(name, method, params) abort
return denops#_internal#server#chan#request(
\ 'invoke',
\ ['dispatch', [a:plugin, a:method, a:params]],
\ ['dispatch', [a:name, a:method, a:params]],
\)
endfunction

function! denops#request_async(plugin, method, params, success, failure) abort
function! denops#request_async(name, method, params, success, failure) abort
let l:success = denops#callback#register(a:success, {
\ 'once': v:true,
\})
Expand All @@ -21,7 +21,7 @@ function! denops#request_async(plugin, method, params, success, failure) abort
\})
return denops#_internal#server#chan#notify(
\ 'invoke',
\ ['dispatchAsync', [a:plugin, a:method, a:params, l:success, l:failure]],
\ ['dispatchAsync', [a:name, a:method, a:params, l:success, l:failure]],
\)
endfunction

Expand Down
24 changes: 24 additions & 0 deletions autoload/denops/_internal/plugin.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function! denops#_internal#plugin#collect() abort
let l:pattern = denops#_internal#path#join(['denops', '*', 'main.ts'])
let l:plugins = []
for l:script in globpath(&runtimepath, l:pattern, 1, 1, 1)
let l:name = fnamemodify(l:script, ':h:t')
if l:name[:0] ==# '@' || !filereadable(l:script)
continue
endif
call add(l:plugins, #{ name: l:name, script: l:script })
endfor
return l:plugins
endfunction

function! denops#_internal#plugin#find(name) abort
let l:pattern = denops#_internal#path#join(['denops', a:name, 'main.ts'])
for l:script in globpath(&runtimepath, l:pattern, 1, 1, 1)
let l:name = fnamemodify(l:script, ':h:t')
if l:name[:0] ==# '@' || !filereadable(l:script)
continue
endif
return #{ name: l:name, script: l:script }
endfor
throw printf('No denops plugin for "%s" exists', a:name)
endfunction
46 changes: 46 additions & 0 deletions autoload/denops/cache.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
let s:root = expand('<sfile>:p:h:h:h')
let s:job = v:null

function! denops#cache#update(...) abort
let l:options = extend(#{ reload: v:false }, a:0 ? a:1 : {})
let l:entryfiles = extend([
\ denops#_internal#path#join([s:root, 'denops', '@denops-private', 'mod.ts']),
\], map(denops#_internal#plugin#collect(), { _, v -> v.script }))

let l:args = [g:denops#deno, 'cache']

if l:options.reload
let l:args = add(l:args, '--reload')
echomsg '[denops] Forcibly update cache of the following files.'
else
echomsg '[denops] Update cache of the following files. Call `denops#cache#update(#{reload: v:true})` to forcibly update.'
endif

for l:entryfile in l:entryfiles
echomsg printf('[denops] %s', l:entryfile)
endfor
let l:args = extend(l:args, l:entryfiles)

let s:job = denops#_internal#job#start(l:args, #{
\ on_stderr: funcref('s:on_stderr'),
\ on_exit: funcref('s:on_exit'),
\ env: #{
\ NO_COLOR: 1,
\ DENO_NO_PROMPT: 1,
\ },
\})
call denops#_internal#wait#for(60 * 1000, { -> s:job is# v:null }, 100)
echomsg '[denops] Deno cache is updated.'
endfunction

function! s:on_stderr(job, data, event) abort
echohl Comment
for l:line in split(a:data, '\n')
echomsg printf('[denops] %s', substitute(l:line, '\t', ' ', 'g'))
endfor
echohl None
endfunction

function! s:on_exit(job, status, event) abort
let s:job = v:null
endfunction
83 changes: 26 additions & 57 deletions autoload/denops/plugin.vim
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
let s:loaded_plugins = {}
let s:load_callbacks = {}

function! denops#plugin#is_loaded(plugin) abort
return has_key(s:loaded_plugins, a:plugin)
function! denops#plugin#is_loaded(name) abort
return has_key(s:loaded_plugins, a:name)
endfunction

function! denops#plugin#wait(plugin, ...) abort
function! denops#plugin#wait(name, ...) abort
let l:options = extend({
\ 'interval': g:denops#plugin#wait_interval,
\ 'timeout': g:denops#plugin#wait_timeout,
Expand All @@ -16,40 +16,40 @@ function! denops#plugin#wait(plugin, ...) abort
if !l:options.silent
call denops#_internal#echo#error(printf(
\ 'Failed to wait for "%s" to start. Denops server itself is not started.',
\ a:plugin,
\ a:name,
\))
endif
return -2
endif
if has_key(s:loaded_plugins, a:plugin)
return s:loaded_plugins[a:plugin]
if has_key(s:loaded_plugins, a:name)
return s:loaded_plugins[a:name]
endif
let l:ret = denops#_internal#wait#for(
\ l:options.timeout,
\ { -> has_key(s:loaded_plugins, a:plugin) },
\ { -> has_key(s:loaded_plugins, a:name) },
\ l:options.interval,
\)
if l:ret is# -1
if !l:options.silent
call denops#_internal#echo#error(printf(
\ 'Failed to wait for "%s" to start. It took more than %d milliseconds and timed out.',
\ a:plugin,
\ a:name,
\ l:options.timeout,
\))
endif
return -1
endif
endfunction

function! denops#plugin#wait_async(plugin, callback) abort
if has_key(s:loaded_plugins, a:plugin)
if s:loaded_plugins[a:plugin] isnot# 0
function! denops#plugin#wait_async(name, callback) abort
if has_key(s:loaded_plugins, a:name)
if s:loaded_plugins[a:name] isnot# 0
return
endif
call a:callback()
return
endif
let l:callbacks = get(s:load_callbacks, a:plugin, [])
let l:callbacks = get(s:load_callbacks, a:name, [])
call add(l:callbacks, a:callback)
let s:load_callbacks[a:plugin] = l:callbacks
endfunction
Expand All @@ -58,47 +58,45 @@ endfunction
" Some plugins (e.g. dein.vim) use this function with options thus we cannot
" change the interface of this function.
" That's why we introduce 'load' function that replaces this function.
function! denops#plugin#register(plugin, ...) abort
function! denops#plugin#register(name, ...) abort
call denops#_internal#echo#deprecate(
\ 'denops#plugin#register() is deprecated. Use denops#plugin#load() instead.',
\)
if a:0 is# 0 || type(a:1) is# v:t_dict
let l:script = s:find_plugin(a:plugin)
let l:script = denops#_internal#plugin#find(a:name).script
else
let l:script = a:1
endif
return denops#plugin#load(a:plugin, l:script)
return denops#plugin#load(a:name, l:script)
endfunction

function! denops#plugin#load(plugin, script) abort
function! denops#plugin#load(name, script) abort
let l:script = denops#_internal#path#norm(a:script)
let l:args = [a:plugin, l:script]
let l:args = [a:name, l:script]
call denops#_internal#echo#debug(printf('load plugin: %s', l:args))
call denops#_internal#server#chan#notify('invoke', ['load', l:args])
endfunction

function! denops#plugin#reload(plugin) abort
let l:args = [a:plugin]
function! denops#plugin#reload(name) abort
let l:args = [a:name]
call denops#_internal#echo#debug(printf('reload plugin: %s', l:args))
call denops#_internal#server#chan#notify('invoke', ['reload', l:args])
endfunction

function! denops#plugin#discover() abort
let l:plugins = {}
call s:gather_plugins(l:plugins)
let l:plugins = denops#_internal#plugin#collect()
call denops#_internal#echo#debug(printf('%d plugins are discovered', len(l:plugins)))
for [l:plugin, l:script] in items(l:plugins)
call denops#plugin#load(l:plugin, l:script)
for l:plugin in l:plugins
call denops#plugin#load(l:plugin.name, l:plugin.script)
endfor
endfunction

function! denops#plugin#check_type(...) abort
if !a:0
let l:plugins = {}
call s:gather_plugins(l:plugins)
endif
let l:plugins = a:0
\ ? [denops#_internal#plugin#find(a:1)]
\ : denops#_internal#plugin#collect()
let l:args = [g:denops#deno, 'check']
let l:args += a:0 ? [s:find_plugin(a:1)] : values(l:plugins)
let l:args = extend(l:args, map(l:plugins, { _, v -> v.script }))
let l:job = denops#_internal#job#start(l:args, {
\ 'env': {
\ 'NO_COLOR': 1,
Expand All @@ -112,35 +110,6 @@ function! denops#plugin#check_type(...) abort
\ })
endfunction

function! s:gather_plugins(plugins) abort
for l:script in globpath(&runtimepath, denops#_internal#path#join(['denops', '*', 'main.ts']), 1, 1, 1)
let l:plugin = fnamemodify(l:script, ':h:t')
if l:plugin[:0] ==# '@' || has_key(a:plugins, l:plugin)
continue
endif
call extend(a:plugins, { l:plugin : l:script })
endfor
endfunction

function! s:options(base, default) abort
let l:options = extend(a:default, a:base)
if l:options.mode !~# '^\(reload\|skip\|error\)$'
throw printf('Unknown mode "%s" is specified', l:options.mode)
endif
return l:options
endfunction

function! s:find_plugin(plugin) abort
for l:script in globpath(&runtimepath, denops#_internal#path#join(['denops', a:plugin, 'main.ts']), 1, 1, 1)
let l:plugin = fnamemodify(l:script, ':h:t')
if l:plugin[:0] ==# '@' || !filereadable(l:script)
continue
endif
return l:script
endfor
throw printf('No denops plugin for "%s" exists', a:plugin)
endfunction

function! s:relay_autocmd(name) abort
let l:plugin = matchstr(expand('<amatch>'), '^[^:]\+:\zs.*')
execute printf('doautocmd <nomodeline> User %s:%s', a:name, l:plugin)
Expand Down
58 changes: 34 additions & 24 deletions doc/denops.txt
Original file line number Diff line number Diff line change
Expand Up @@ -158,26 +158,26 @@ VARIABLE *denops-variable*
FUNCTION *denops-function*

*denops#notify()*
denops#notify({plugin}, {method}, {params})
Calls API {method} of {plugin} with {params} and returns immediately
without waiting for a result.
denops#notify({name}, {method}, {params})
Calls API {method} of {name} plugin with {params} and returns
immediately without waiting for a result.
Use |denops#request()| instead if you need a result.
Note: It does not redraw in the Vim environment. Manually execute
|:redraw| if needed.

*denops#request()*
denops#request({plugin}, {method}, {params})
Calls API {method} of {plugin} with {params} and waits for a result,
then returns it.
denops#request({name}, {method}, {params})
Calls API {method} of {name} plugin with {params} and waits for a
result, then returns it.
Use |denops#notify()| instead if you don't need a result.
Use |denops#request_async()| instead if you need a result
asynchronously.

*denops#request_async()*
denops#request_async({plugin}, {method}, {params}, {success}, {failure})
Calls API {method} of {plugin} with {params} and returns immediately.
Once the call succeeds, the {success} callback is called with a
result.
denops#request_async({name}, {method}, {params}, {success}, {failure})
Calls API {method} of {name} plugin with {params} and returns
immediately. Once the call succeeds, the {success} callback is called
with a result.
Otherwise, the {failure} callback is called with an error.
Use |denops#notify()| instead if you don't need a result.
Use |denops#request()| instead if you need a result synchronously.
Expand All @@ -200,6 +200,16 @@ denops#request_async({plugin}, {method}, {params}, {success}, {failure})
\ { e -> s:failure(e) },
\)
<
*denops#cache#update()*
denops#cache#update([{options}])
Update Deno module cache of denops itself and denops plugins in
|runtimepath|.

The following {options} is available

"reload" |v:true| to force update ("--reload" flag of "deno
cache") command.

*denops#server#start()*
denops#server#start()
Starts a denops server process and connects to the channel. It does
Expand Down Expand Up @@ -282,14 +292,14 @@ denops#server#wait_async({callback})
callbacks registered are called in order of registration.

*denops#plugin#is_loaded()*
denops#plugin#is_loaded({plugin})
Returns 1 if a {plugin} plugin is already loaded. Otherwise, returns
denops#plugin#is_loaded({name})
Returns 1 if a {name} plugin is already loaded. Otherwise, returns
0.

*denops#plugin#wait()*
denops#plugin#wait({plugin}[, {options}])
Waits synchronously until a {plugin} plugin is loaded. It returns
immediately when the {plugin} plugin is already loaded.
denops#plugin#wait({name}[, {options}])
Waits synchronously until a {name} plugin is loaded. It returns
immediately when the {name} plugin is already loaded.
It returns -1 if it times out, -2 if the server is not yet ready or
interrupted, or -3 if the plugin initialization failed.
Developers need to consider this return value to decide whether to
Expand All @@ -305,15 +315,15 @@ denops#plugin#wait({plugin}[, {options}])
Default: 0

*denops#plugin#wait_async()*
denops#plugin#wait_async({plugin}, {callback})
Waits asynchronously until a {plugin} plugin is loaded and invokes a
{callback}. It invokes the {callback} immediately when the {plugin}
denops#plugin#wait_async({name}, {callback})
Waits asynchronously until a {name} plugin is loaded and invokes a
{callback}. It invokes the {callback} immediately when the {name}
plugin is already loaded. If this function is called multiple times
for the same {plugin} plugin, callbacks registered for the plugin are
for the same {name} plugin, callbacks registered for the plugin are
called in order of registration.

*denops#plugin#register()*
denops#plugin#register({plugin}[, {script}[, {options}]])
denops#plugin#register({name}[, {script}[, {options}]])
DEPRECATED: Use |denops#plugin#load()| instead.

Developers who would like to support previous denops versions should
Expand Down Expand Up @@ -344,7 +354,7 @@ denops#plugin#discover()
by |denops#server#start()|.

*denops#plugin#load()*
denops#plugin#load({plugin}, {script})
denops#plugin#load({name}, {script})
Loads a denops plugin. Use this function to load denops plugins that
are not discovered by |denops#plugin#discover()|.
It invokes |User| |DenopsPluginPre|:{plugin} just before denops
Expand All @@ -353,12 +363,12 @@ denops#plugin#load({plugin}, {script})
function of the plugin.

*denops#plugin#reload()*
denops#plugin#reload({plugin})
denops#plugin#reload({name})
Reloads a denops plugin.

*denops#plugin#check_type()*
denops#plugin#check_type([{plugin}])
Runs Deno's type check feature for {plugin} or all registered plugins.
denops#plugin#check_type([{name}])
Runs Deno's type check feature for {name} or all registered plugins.
The result of the check will be displayed in |message-history|.

*denops#callback#register()*
Expand Down