Skip to content

Commit

Permalink
test omnifunc implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
bfredl committed Feb 13, 2016
1 parent 0fe0efe commit 48969e2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,5 @@ Most useful is `IPyRun("string of code"[, silent])` which can be called to progr
nnoremap <Leader>c :call IPyRun('close("all")',1)<cr>

`IPyConnect(args...)` can likewise be used to connect with vimscript generated arguments.

`IPyOmniFunc` can be used as `&completefunc`/`&omnifunc` for use with a completer framework. Note that unlike `<Plug><IPy-Complete)` this is synchronous and waits for the kernel, so if the kernel hangs this might hang nvim! For use with async completion like Deoplete it would be better to create a dedicated source.
19 changes: 18 additions & 1 deletion rplugin/python/nvim_ipy.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def ipy_run(self, args):
@neovim.function("IPyComplete")
def ipy_complete(self,args):
line = self.vim.current.line
#FIXME: (upstream) this sometimes get wrong if
#FIXME: (upstream) this sometimes get wrong if
#completing just after entering insert mode:
#pos = self.vim.current.buffer.mark(".")[1]+1
pos = self.vim.funcs.col('.')-1
Expand All @@ -266,6 +266,23 @@ def ipy_complete(self,args):
start = content["cursor_start"]+1
self.vim.funcs.complete(start, content['matches'])

@neovim.function("IPyOmniFunc", sync=True)
def ipy_omnifunc(self,args):
findstart, base = args
if findstart:
if not self.has_connection:
return False
line = self.vim.current.line
pos = self.vim.funcs.col('.')-1

reply = self.waitfor(self.kc.complete(line, pos))
content = reply["content"]
start = content["cursor_start"]
self._matches = content['matches']
return start
else:
return self._matches

@neovim.function("IPyObjInfo")
def ipy_objinfo(self, args):
word, level = args
Expand Down

0 comments on commit 48969e2

Please sign in to comment.