1
1
let s: loaded_plugins = {}
2
2
let s: load_callbacks = {}
3
3
4
- function ! denops#plugin#is_loaded (plugin ) abort
5
- return has_key (s: loaded_plugins , a: plugin )
4
+ function ! denops#plugin#is_loaded (name ) abort
5
+ return has_key (s: loaded_plugins , a: name )
6
6
endfunction
7
7
8
- function ! denops#plugin#wait (plugin , ... ) abort
8
+ function ! denops#plugin#wait (name , ... ) abort
9
9
let l: options = extend ({
10
10
\ ' interval' : g: denops #plugin #wait_interval,
11
11
\ ' timeout' : g: denops #plugin #wait_timeout,
@@ -16,40 +16,40 @@ function! denops#plugin#wait(plugin, ...) abort
16
16
if ! l: options .silent
17
17
call denops#_internal#echo#error (printf (
18
18
\ ' Failed to wait for "%s" to start. Denops server itself is not started.' ,
19
- \ a: plugin ,
19
+ \ a: name ,
20
20
\) )
21
21
endif
22
22
return -2
23
23
endif
24
- if has_key (s: loaded_plugins , a: plugin )
25
- return s: loaded_plugins [a: plugin ]
24
+ if has_key (s: loaded_plugins , a: name )
25
+ return s: loaded_plugins [a: name ]
26
26
endif
27
27
let l: ret = denops#_internal#wait#for (
28
28
\ l: options .timeout ,
29
- \ { - > has_key (s: loaded_plugins , a: plugin ) },
29
+ \ { - > has_key (s: loaded_plugins , a: name ) },
30
30
\ l: options .interval,
31
31
\)
32
32
if l: ret is # -1
33
33
if ! l: options .silent
34
34
call denops#_internal#echo#error (printf (
35
35
\ ' Failed to wait for "%s" to start. It took more than %d milliseconds and timed out.' ,
36
- \ a: plugin ,
36
+ \ a: name ,
37
37
\ l: options .timeout ,
38
38
\) )
39
39
endif
40
40
return -1
41
41
endif
42
42
endfunction
43
43
44
- function ! denops#plugin#wait_async (plugin , callback) abort
45
- if has_key (s: loaded_plugins , a: plugin )
46
- if s: loaded_plugins [a: plugin ] isnot # 0
44
+ function ! denops#plugin#wait_async (name , callback) abort
45
+ if has_key (s: loaded_plugins , a: name )
46
+ if s: loaded_plugins [a: name ] isnot # 0
47
47
return
48
48
endif
49
49
call a: callback ()
50
50
return
51
51
endif
52
- let l: callbacks = get (s: load_callbacks , a: plugin , [])
52
+ let l: callbacks = get (s: load_callbacks , a: name , [])
53
53
call add (l: callbacks , a: callback )
54
54
let s: load_callbacks [a: plugin ] = l: callbacks
55
55
endfunction
@@ -58,47 +58,45 @@ endfunction
58
58
" Some plugins (e.g. dein.vim) use this function with options thus we cannot
59
59
" change the interface of this function.
60
60
" That's why we introduce 'load' function that replaces this function.
61
- function ! denops#plugin#register (plugin , ... ) abort
61
+ function ! denops#plugin#register (name , ... ) abort
62
62
call denops#_internal#echo#deprecate (
63
63
\ ' denops#plugin#register() is deprecated. Use denops#plugin#load() instead.' ,
64
64
\)
65
65
if a: 0 is # 0 || type (a: 1 ) is # v: t_dict
66
- let l: script = s: find_plugin (a: plugin )
66
+ let l: script = denops#_internal#plugin#find (a: name ). script
67
67
else
68
68
let l: script = a: 1
69
69
endif
70
- return denops#plugin#load (a: plugin , l: script )
70
+ return denops#plugin#load (a: name , l: script )
71
71
endfunction
72
72
73
- function ! denops#plugin#load (plugin , script ) abort
73
+ function ! denops#plugin#load (name , script ) abort
74
74
let l: script = denops#_internal#path#norm (a: script )
75
- let l: args = [a: plugin , l: script ]
75
+ let l: args = [a: name , l: script ]
76
76
call denops#_internal#echo#debug (printf (' load plugin: %s' , l: args ))
77
77
call denops#_internal#server#chan#notify (' invoke' , [' load' , l: args ])
78
78
endfunction
79
79
80
- function ! denops#plugin#reload (plugin ) abort
81
- let l: args = [a: plugin ]
80
+ function ! denops#plugin#reload (name ) abort
81
+ let l: args = [a: name ]
82
82
call denops#_internal#echo#debug (printf (' reload plugin: %s' , l: args ))
83
83
call denops#_internal#server#chan#notify (' invoke' , [' reload' , l: args ])
84
84
endfunction
85
85
86
86
function ! denops#plugin#discover () abort
87
- let l: plugins = {}
88
- call s: gather_plugins (l: plugins )
87
+ let l: plugins = denops#_internal#plugin#collect ()
89
88
call denops#_internal#echo#debug (printf (' %d plugins are discovered' , len (l: plugins )))
90
- for [ l: plugin, l: script ] in items ( l: plugins)
91
- call denops#plugin#load (l: plugin , l: script )
89
+ for l: plugin in l: plugins
90
+ call denops#plugin#load (l: plugin.name , l: plugin . script )
92
91
endfor
93
92
endfunction
94
93
95
94
function ! denops#plugin#check_type (... ) abort
96
- if ! a: 0
97
- let l: plugins = {}
98
- call s: gather_plugins (l: plugins )
99
- endif
95
+ let l: plugins = a: 0
96
+ \ ? [denops#_internal#plugin#find (a: 1 )]
97
+ \ : denops#_internal#plugin#collect ()
100
98
let l: args = [g: denops #deno, ' check' ]
101
- let l: args += a: 0 ? [ s: find_plugin ( a: 1 )] : values (l: plugins )
99
+ let l: args = extend ( l: args , map (l: plugins, { _, v - > v . script }) )
102
100
let l: job = denops#_internal#job#start (l: args , {
103
101
\ ' env' : {
104
102
\ ' NO_COLOR' : 1 ,
@@ -112,35 +110,6 @@ function! denops#plugin#check_type(...) abort
112
110
\ })
113
111
endfunction
114
112
115
- function ! s: gather_plugins (plugins) abort
116
- for l: script in globpath (&runtimepath , denops#_internal#path#join ([' denops' , ' *' , ' main.ts' ]), 1 , 1 , 1 )
117
- let l: plugin = fnamemodify (l: script , ' :h:t' )
118
- if l: plugin [:0 ] == # ' @' || has_key (a: plugins , l: plugin )
119
- continue
120
- endif
121
- call extend (a: plugins , { l: plugin : l: script })
122
- endfor
123
- endfunction
124
-
125
- function ! s: options (base, default) abort
126
- let l: options = extend (a: default , a: base )
127
- if l: options .mode !~# ' ^\(reload\|skip\|error\)$'
128
- throw printf (' Unknown mode "%s" is specified' , l: options .mode )
129
- endif
130
- return l: options
131
- endfunction
132
-
133
- function ! s: find_plugin (plugin ) abort
134
- for l: script in globpath (&runtimepath , denops#_internal#path#join ([' denops' , a: plugin , ' main.ts' ]), 1 , 1 , 1 )
135
- let l: plugin = fnamemodify (l: script , ' :h:t' )
136
- if l: plugin [:0 ] == # ' @' || ! filereadable (l: script )
137
- continue
138
- endif
139
- return l: script
140
- endfor
141
- throw printf (' No denops plugin for "%s" exists' , a: plugin )
142
- endfunction
143
-
144
113
function ! s: relay_autocmd (name) abort
145
114
let l: plugin = matchstr (expand (' <amatch>' ), ' ^[^:]\+:\zs.*' )
146
115
execute printf (' doautocmd <nomodeline> User %s:%s' , a: name , l: plugin )
0 commit comments