integration with nvim-completion-manager, use callback style.
@@ -13,6 +13,7 @@ from . logger import logger
from . RPC import RPC
from . TextDocumentItem import TextDocumentItem
from . DiagnosticsDisplay import DiagnosticsDisplay
+import re
@neovim.plugin
@@ -162,6 +163,16 @@ class LanguageClient:
return
command = self.serverCommands[languageId]
+ try:
+ self.nvim.call('cm#register_source',dict(name='LanguageClient_%s' % languageId,
+ priority=9,
+ scopes=[ languageId ],
+ abbreviation='',
+ cm_refresh='LanguageClient_completionManager_refresh'))
+ except Exception as ex:
+ # fails if completion manager has not been installed yet
+ logger.exception("register completion manager source failed.")
+
self.server = subprocess.Popen(
# ["/bin/bash", "/tmp/wrapper.sh"],
command,
@@ -599,6 +610,63 @@ call fzf#run(fzf#wrap({{
logger.info("End textDocument/completion")
return items
+ # this method is called by nvim-completion-manager framework
+ @neovim.function("LanguageClient_completionManager_refresh")
+ def completionManager_refresh(self, args) -> None:
+ if not self.alive():
+ return
+
+ logger.info("completionManager_refresh: %s", args)
+ info = args[0]
+ ctx = args[1]
+
+ typed = ctx["typed"]
+ col = ctx["col"]
+ kwtyped = re.search(r'[0-9a-zA-Z_]*?$', typed).group(0)
+ startcol = col-len(kwtyped)
+
+ args = {}
+ args["line"] = ctx["lnum"] - 1
+ args["character"] = ctx["col"] - 1
+ if typed=='':
+ return
+
+ uri, line, character = self.getArgs([args], ["uri", "line", "character"])
+
+ logger.info("uri[%s] line[%s] character[%s]", uri, line, character)
+
+ def cb(result):
+
+ logger.info("result: %s",result)
+ items = result
+ isIncomplete = False
+ if type(result)==type({}):
+ items = result["items"]
+ isIncomplete = result.get('isIncomplete',False)
+
+ # convert to vim style completion-items
+ matches = []
+ for item in items:
+ e = {}
+ e['icase'] = 1
+ e['word'] = item['label']
+ e['abbr'] = item.get('insertText',None) or ''
+ e['dup'] = 1
+ e['info'] = item.get('documentation',None) or ''
+ matches.append(e)
+
+ self.nvim.call('cm#complete', info['name'], ctx, startcol, matches, isIncomplete, async=True)
+
+ items = self.rpc.call('textDocument/completion', {
+ "textDocument": {
+ "uri": uri
+ },
+ "position": {
+ "line": line,
+ "character": character
+ }
+ },cb)
+
# FIXME: python infinite loop after this call.
@neovim.function("LanguageClient_exit")
def exit(self, args: List) -> None:
