@@ -4,16 +4,28 @@ if (get(g:, 'deoplete#sources#padawan#loaded', 0))
4
4
finish
5
5
endif
6
6
7
+ let s: plugin_directory = expand (' <sfile>:p:h:h:h:h' )
8
+ let s: server_command = s: plugin_directory . ' /vendor/bin/padawan-server'
9
+ let s: padawan_command = s: plugin_directory . ' /vendor/bin/padawan'
10
+ if ! executable (s: server_command ) || ! executable (s: padawan_command )
11
+ let s: server_command = ' padawan-server'
12
+ let s: padawan_command = ' padawan'
13
+ endif
14
+
7
15
let g: deoplete #sources#padawan#loaded = 1
8
16
9
17
let lib_path = expand (' <sfile>:p:h:h:h:h' ) . ' /rplugin/python3/deoplete/sources/deoplete_padawan'
10
18
11
19
let g: deoplete #sources#padawan#server_addr =
12
20
\ get (g: , ' deoplete#sources#padawan#server_addr' , ' http://127.0.0.1:15155' )
13
21
let g: deoplete #sources#padawan#server_command =
14
- \ get (g: , ' deoplete#sources#padawan#server_command' , ' padawan-server' )
22
+ \ get (g: , ' deoplete#sources#padawan#server_command' , s: server_command )
23
+ let g: deoplete #sources#padawan#padawan_command =
24
+ \ get (g: , ' deoplete#sources#padawan#padawan_command' , s: padawan_command )
15
25
let g: deoplete #sources#padawan#log_file =
16
26
\ get (g: , ' deoplete#sources#padawan#log_file' , ' /tmp/padawan-server.log' )
27
+ let g: deoplete #sources#padawan#composer_command =
28
+ \ get (g: , ' deoplete#sources#padawan#composer_command' , ' composer' )
17
29
18
30
let g: deoplete #sources#padawan#server_autostart =
19
31
\ get (g: , ' deoplete#sources#padawan#server_autostart' , 1 )
@@ -22,6 +34,7 @@ let g:deoplete#sources#padawan#add_parentheses =
22
34
let g: deoplete #sources#padawan#auto_update =
23
35
\ get (g: , ' deoplete#sources#padawan#auto_update' , 0 )
24
36
37
+
25
38
python3 << PYTHON
26
39
import vim
27
40
import sys
@@ -31,14 +44,26 @@ lib_path = vim.eval('lib_path')
31
44
sys.path .insert (0 , os.path .join (lib_path))
32
45
33
46
import padawan_server
47
+ import padawan_helper
34
48
35
49
server_addr = vim .eval (' g:deoplete#sources#padawan#server_addr' )
36
50
server_command = vim .eval (' g:deoplete#sources#padawan#server_command' )
37
51
log_file = vim .eval (' g:deoplete#sources#padawan#log_file' )
38
52
39
53
_padawan_server = padawan_server.Server (server_addr, server_command, log_file)
54
+ _padawan_helper = padawan_helper.Helper ()
40
55
PYTHON
41
56
57
+ function ! deoplete#sources#padawan#InstallServer ()
58
+ let l: composer = g: deoplete #sources#padawan#composer_command
59
+ exec " !cd " . s: plugin_directory . " && " . l: composer . " install"
60
+ endfunction
61
+
62
+ function ! deoplete#sources#padawan#UpdateServer ()
63
+ let l: composer = g: deoplete #sources#padawan#composer_command
64
+ exec " !cd " . s: plugin_directory . " && " . l: composer . " update"
65
+ endfunction
66
+
42
67
function ! deoplete#sources#padawan#StartServer ()
43
68
" @todo - add some feedback with information if started
44
69
python3 _padawan_server.start ()
@@ -53,3 +78,38 @@ function! deoplete#sources#padawan#RestartServer()
53
78
" @todo - add some feedback with information if restarted
54
79
python3 _padawan_server.restart ()
55
80
endfunction
81
+
82
+ function ! deoplete#sources#padawan#Generate (... )
83
+ if empty (get (b: , ' padawan_project_root' , 0 ))
84
+ python3 << PYTHON
85
+ file_name = vim .eval (' expand("%:p")' )
86
+ vim .command (" let b:padawan_project_root = '{}'" .format (
87
+ _padawan_helper.get_project_root (file_name))
88
+ )
89
+ PYTHON
90
+ endif
91
+ if confirm (" Are you sure you want to generate index in "
92
+ \. b: padawan_project_root . " ?" , " &Yes\n &No" , 2 ) == 1
93
+ let cmd = " cd " . b: padawan_project_root . " && "
94
+ \. g: deoplete #sources#padawan#padawan_command . " generate"
95
+ if get (a: , 1 , 0 )
96
+ exec " !" . l: cmd
97
+ else
98
+ call jobstart (l: cmd , {
99
+ \' on_exit' : function(' s: generate_exit '),
100
+ \' on_stdout' : function(' s: generate_stdout ')})
101
+ endif
102
+ endif
103
+ endfunction
104
+
105
+ function ! s: generate_stdout (id, out, ... )
106
+ for l: line in a: out
107
+ if l: line = ~ ' Progress:'
108
+ echo l: line
109
+ endif
110
+ endfor
111
+ endfunction
112
+
113
+ function ! s: generate_exit (... )
114
+ echo " Padawan.php: Index generating has finished!"
115
+ endfunction
0 commit comments