1
- let s: loaded_plugins = {}
2
- let s: load_callbacks = {}
3
-
4
1
function ! denops#plugin#is_loaded (name) abort
5
- return has_key ( s: loaded_plugins , a: name )
2
+ return denops#_internal#plugin#get ( a: name ). state = ~# ' ^\%(loaded\|failed\)$ '
6
3
endfunction
7
4
8
5
function ! denops#plugin#wait (name, ... ) abort
@@ -21,66 +18,43 @@ function! denops#plugin#wait(name, ...) abort
21
18
endif
22
19
return -2
23
20
endif
24
- if has_key ( s: loaded_plugins , a: name )
25
- return s: loaded_plugins [ a: name ]
26
- endif
27
- let l: ret = denops#_internal#wait#for (
28
- \ l: options .timeout ,
29
- \ { - > has_key ( s: loaded_plugins , a: name ) },
30
- \ l: options .interval,
31
- \)
32
- if l: ret is # -1
33
- if ! l: options . silent
34
- call denops#_internal#echo#error ( printf (
35
- \ ' Failed to wait for "%s" to start. It took more than %d milliseconds and timed out. ' ,
36
- \ a: name ,
37
- \ l: options . timeout ,
38
- \) )
21
+ if ! denops#plugin#is_loaded ( a: name )
22
+ let l: ret = denops#_internal#wait#for (
23
+ \ l: options . timeout ,
24
+ \ { - > denops#plugin#is_loaded ( a: name ) },
25
+ \ l: options .interval ,
26
+ \)
27
+ if l: ret is # -1
28
+ if ! l: options . silent
29
+ call denops#_internal#echo#error ( printf (
30
+ \ ' Failed to wait for "%s" to start. It took more than %d milliseconds and timed out. ' ,
31
+ \ a: name ,
32
+ \ l: options . timeout ,
33
+ \) )
34
+ endif
35
+ return -1
39
36
endif
40
- return -1
41
37
endif
38
+ return denops#_internal#plugin#get (a: name ).state == # ' loaded' ? 0 : -3
42
39
endfunction
43
40
44
41
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
- return
48
- endif
42
+ let l: plugin = denops#_internal#plugin#get (a: name )
43
+ if l: plugin .state == # ' loaded'
49
44
call a: callback ()
50
45
return
46
+ elseif l: plugin .state == # ' failed'
47
+ return
51
48
endif
52
- let l: callbacks = get (s: load_callbacks , a: name , [])
53
- call add (l: callbacks , a: callback )
54
- let s: load_callbacks [a: name ] = l: callbacks
55
- endfunction
56
-
57
- " DEPRECATED
58
- " Some plugins (e.g. dein.vim) use this function with options thus we cannot
59
- " change the interface of this function.
60
- " That's why we introduce 'load' function that replaces this function.
61
- function ! denops#plugin#register (name, ... ) abort
62
- call denops#_internal#echo#deprecate (
63
- \ ' denops#plugin#register() is deprecated. Use denops#plugin#load() instead.' ,
64
- \)
65
- if a: 0 is # 0 || type (a: 1 ) is # v: t_dict
66
- let l: script = denops#_internal#plugin#find (a: name ).script
67
- else
68
- let l: script = a: 1
69
- endif
70
- return denops#plugin#load (a: name , l: script )
49
+ call add (l: plugin .callbacks, a: callback )
71
50
endfunction
72
51
73
52
function ! denops#plugin#load (name, script ) abort
74
- let l: script = denops#_internal#path#norm (a: script )
75
- let l: args = [a: name , l: script ]
76
- call denops#_internal#echo#debug (printf (' load plugin: %s' , l: args ))
77
- call denops#_internal#server#chan#notify (' invoke' , [' load' , l: args ])
53
+ call denops#_internal#plugin#load (a: name , a: script )
78
54
endfunction
79
55
80
56
function ! denops#plugin#reload (name) abort
81
- let l: args = [a: name ]
82
- call denops#_internal#echo#debug (printf (' reload plugin: %s' , l: args ))
83
- call denops#_internal#server#chan#notify (' invoke' , [' reload' , l: args ])
57
+ call denops#_internal#plugin#reload (a: name )
84
58
endfunction
85
59
86
60
function ! denops#plugin#discover () abort
@@ -110,38 +84,21 @@ function! denops#plugin#check_type(...) abort
110
84
\ })
111
85
endfunction
112
86
113
- function ! s: relay_autocmd (name) abort
114
- let l: plugin = matchstr (expand (' <amatch>' ), ' ^[^:]\+:\zs.*' )
115
- execute printf (' doautocmd <nomodeline> User %s:%s' , a: name , l: plugin )
116
- endfunction
117
-
118
- function ! s: DenopsSystemPluginPost () abort
119
- let l: plugin = matchstr (expand (' <amatch>' ), ' DenopsSystemPluginPost:\zs.*' )
120
- let s: loaded_plugins [l: plugin ] = 0
121
- if has_key (s: load_callbacks , l: plugin )
122
- for l: Callback in remove (s: load_callbacks , l: plugin )
123
- call l: Callback ()
124
- endfor
125
- endif
126
- execute printf (' doautocmd <nomodeline> User DenopsPluginPost:%s' , l: plugin )
127
- endfunction
128
-
129
- function ! s: DenopsSystemPluginFail () abort
130
- let l: plugin = matchstr (expand (' <amatch>' ), ' DenopsSystemPluginFail:\zs.*' )
131
- let s: loaded_plugins [l: plugin ] = -3
132
- if has_key (s: load_callbacks , l: plugin )
133
- call remove (s: load_callbacks , l: plugin )
87
+ " DEPRECATED
88
+ " Some plugins (e.g. dein.vim) use this function with options thus we cannot
89
+ " change the interface of this function.
90
+ " That's why we introduce 'load' function that replaces this function.
91
+ function ! denops#plugin#register (name, ... ) abort
92
+ call denops#_internal#echo#deprecate (
93
+ \ ' denops#plugin#register() is deprecated. Use denops#plugin#load() instead.' ,
94
+ \)
95
+ if a: 0 is # 0 || type (a: 1 ) is # v: t_dict
96
+ let l: script = denops#_internal#plugin#find (a: name ).script
97
+ else
98
+ let l: script = a: 1
134
99
endif
135
- execute printf ( ' doautocmd <nomodeline> User DenopsPluginFail:%s ' , l: plugin )
100
+ return denops#plugin#load ( a: name , l: script )
136
101
endfunction
137
102
138
- augroup denops_autoload_plugin_internal
139
- autocmd !
140
- autocmd User DenopsSystemPluginPre:* call s: relay_autocmd (' DenopsPluginPre' )
141
- autocmd User DenopsSystemPluginPost:* ++nested call s: DenopsSystemPluginPost ()
142
- autocmd User DenopsSystemPluginFail:* call s: DenopsSystemPluginFail ()
143
- autocmd User DenopsClosed let s: loaded_plugins = {}
144
- augroup END
145
-
146
103
call denops#_internal#conf#define (' denops#plugin#wait_interval' , 200 )
147
104
call denops#_internal#conf#define (' denops#plugin#wait_timeout' , 30000 )
0 commit comments