Skip to content

Commit 3c99c2a

Browse files
authored
Merge pull request #18 from musou1500/17-update-on-write
Add auto update feature
2 parents 29aa9cb + a78b691 commit 3c99c2a

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ options.
5151
| `g:deoplete#sources#padawan#log_file` | `/tmp/padawan-server.log` |
5252
| `g:deoplete#sources#padawan#server_autostart` | `1` |
5353
| `g:deoplete#sources#padawan#add_parentheses` | `0` |
54+
| `g:deoplete#sources#padawan#auto_update` | `0` |
5455

5556
- `g:deoplete#sources#padawan#server_addr`
5657

@@ -77,6 +78,9 @@ Any value but `1` will make this option disabled.
7778
If set to `1` parentheses will be added to function (method) completion. If function
7879
accepts parameters, only opening parenthesis will be added.
7980

81+
- `g:deoplete#sources#padawan#auto_update`
82+
If set to `1` send `update` command to server automatically when `BufWritePost` event is triggered.
83+
8084
## Additional commands
8185

8286
By default, the plugin is not creating any vim commands. However, there are some

autoload/deoplete/sources/padawan.vim

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ let g:deoplete#sources#padawan#server_autostart =
1919
\ get(g:, 'deoplete#sources#padawan#server_autostart', 1)
2020
let g:deoplete#sources#padawan#add_parentheses =
2121
\ get(g:, 'deoplete#sources#padawan#add_parentheses', 0)
22-
22+
let g:deoplete#sources#padawan#auto_update =
23+
\ get(g:, 'deoplete#sources#padawan#auto_update', 0)
2324

2425
python3 << PYTHON
2526
import vim

rplugin/python3/deoplete/sources/deoplete_padawan.py

+11
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,21 @@ def on_init(self, context):
4141
'deoplete#sources#padawan#log_file')
4242
self.add_parentheses = self.vim.eval(
4343
'deoplete#sources#padawan#add_parentheses')
44+
self.auto_update = self.vim.eval(
45+
'deoplete#sources#padawan#auto_update')
4446

4547
self.server = padawan_server.Server(server_addr, server_command,
4648
log_file)
4749

50+
def on_event(self, context):
51+
if (context['event'] == 'BufWritePost' and self.auto_update == 1):
52+
file_path = self.current.buffer.name
53+
current_path = self.get_project_root(file_path)
54+
params = {
55+
'path': current_path
56+
}
57+
self.do_request('update', params)
58+
4859
def get_complete_position(self, context):
4960
patterns = [r'[\'"][^\)]*$', r'[\w\\]*$']
5061
input = context['input']

0 commit comments

Comments
 (0)