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,80 +18,63 @@ 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
87
- let l: plugins = denops#_internal#plugin#collect ()
88
- call denops#_internal#echo#debug (printf (' %d plugins are discovered' , len (l: plugins )))
89
- for l: plugin in l: plugins
90
- call denops#plugin#load (l: plugin .name, l: plugin .script )
61
+ const l: pattern = denops#_internal#path#join ([' denops' , ' *' , ' main.ts' ])
62
+ let l: counter = 0
63
+ for l: script in globpath (&runtimepath , l: pattern , 1 , 1 , 1 )
64
+ let l: name = fnamemodify (l: script , ' :h:t' )
65
+ if l: name [:0 ] == # ' @' || ! filereadable (l: script )
66
+ continue
67
+ endif
68
+ call denops#plugin#load (l: name , l: script )
69
+ let l: counter += 1
91
70
endfor
71
+ call denops#_internal#echo#debug (printf (' %d plugins are discovered' , l: counter ))
92
72
endfunction
93
73
94
74
function ! denops#plugin#check_type (... ) abort
95
75
let l: plugins = a: 0
96
- \ ? [denops#_internal#plugin#find (a: 1 )]
97
- \ : denops#_internal#plugin#collect ()
76
+ \ ? [denops#_internal#plugin#get (a: 1 )]
77
+ \ : denops#_internal#plugin#list ()
98
78
let l: args = [g: denops #deno, ' check' ]
99
79
let l: args = extend (l: args , map (l: plugins , { _, v - > v .script }))
100
80
let l: job = denops#_internal#job#start (l: args , {
@@ -110,38 +90,33 @@ function! denops#plugin#check_type(...) abort
110
90
\ })
111
91
endfunction
112
92
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
93
+ " DEPRECATED
94
+ " Some plugins (e.g. dein.vim) use this function with options thus we cannot
95
+ " change the interface of this function.
96
+ " That's why we introduce 'load' function that replaces this function.
97
+ function ! denops#plugin#register (name, ... ) abort
98
+ call denops#_internal#echo#deprecate (
99
+ \ ' denops# plugin#register() is deprecated. Use denops#plugin#load() instead. ' ,
100
+ \)
101
+ if a: 0 is # 0 || type ( a: 1 ) is # v: t_dict
102
+ let l: script = s: find_script ( a: name )
103
+ else
104
+ let l: script = a: 1
125
105
endif
126
- execute printf ( ' doautocmd <nomodeline> User DenopsPluginPost:%s ' , l: plugin )
106
+ return denops#plugin#load ( a: name , l: script )
127
107
endfunction
128
108
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 )
134
- endif
135
- execute printf (' doautocmd <nomodeline> User DenopsPluginFail:%s' , l: plugin )
109
+ function ! s: find_script (name) abort
110
+ const l: pattern = denops#_internal#path#join ([' denops' , a: name , ' main.ts' ])
111
+ for l: script in globpath (&runtimepath , l: pattern , 1 , 1 , 1 )
112
+ let l: name = fnamemodify (l: script , ' :h:t' )
113
+ if l: name [:0 ] == # ' @' || ! filereadable (l: script )
114
+ continue
115
+ endif
116
+ return l: script
117
+ endfor
118
+ throw printf (' Denops plugin "%s" does not exist in the runtimepath' , a: name )
136
119
endfunction
137
120
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
121
call denops#_internal#conf#define (' denops#plugin#wait_interval' , 200 )
147
122
call denops#_internal#conf#define (' denops#plugin#wait_timeout' , 30000 )
0 commit comments