Closed sphynx79 closed 7 years ago
Doesn't support rcodetools's completefunc
complete_add
function. If you are using NCM, popup menu should always be managed by NCM. Simply return all the matches as array.complete_check
s:RCT_completion
should be defined as global function. It's hard to get the real script function name outside the script.omnifunc
if it's possible.Just looked into rcodetools's completefunc, it's not hard to convert it into ncm source
Here's the demo code, simply place it into ncm's installation directory as pythonx/cm_sources/rcodetools.py
.
# -*- coding: utf-8 -*-
from cm import register_source, getLogger, Base
register_source(name='rcodetools',
priority=9,
abbreviation='rb',
scoping=True,
scopes=['ruby'],
sort=0,
cm_refresh_patterns=[r'\.$'],)
import subprocess
logger = getLogger(__name__)
class Source(Base):
def __init__(self,nvim):
super(Source,self).__init__(nvim)
def cm_refresh(self,info,ctx,*args):
src = self.get_src(ctx)
# use stdin for rct-complete
proc = subprocess.Popen(args=['rct-complete',
'--completion-class-info',
'--dev',
'--fork',
'--line=%s' % ctx['lnum'],
'--column=%s' % (ctx['col']-1),
'--filename=%s' % ctx['filepath']
],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL)
result, errs = proc.communicate(src.encode('utf-8'),timeout=30)
logger.debug("result %s", result)
result = result.decode('utf-8')
logger.info("result %s", result)
results = result.split("\n")
if not results:
return
matches = []
for line in results:
# sayHi\tHelloWorld#sayHi
fields = line.split("\t")
if not fields:
continue
word = fields[0]
menu = ''
if len(fields)>1:
menu = fields[1]
if not word.strip():
continue
item = dict(word=word,
icase=1,
dup=1,
menu=menu,
)
matches.append(item)
logger.info('matches %s', matches)
self.complete(info, ctx, ctx['startcol'], matches)
You could use this as a start, and maintain a git repo for this purpose.
I didn't put it into NCM's repo or create another repo because I just learned how to write ruby's hello-world, I'm not capable of maintaining this.
Here's the screencast:
I'm sorry but this not work for me, i put your script in nvim\plugged\nvim-completion-manager\pythonx\cm_sources\cm_rcodetools.py and restart nvim. But not work, maybe beacause i use windows, and a i saw in your script that you use fork in subprocess.Popen, but windows not support fork.
I resolve this problem with https://github.com/osyo-manga/vim-monster, i install this plugin and put in my init.vim
au User CmSetup call cm#register_source({'name' : 'monster', \ 'priority': 9, \ 'scoping': 1, \ 'scopes': ['ruby'], \ 'abbreviation': 'rb', \ 'cm_refreshpatterns':['[^. \t].\w', '[a-zA-Z]\w*::'], \ 'cm_refresh': {'omnifunc': 'monster#omnifunc'}, \ })
Make sure rct-complete
command is availabe on your system.
You need to install rcodetools then setup PATH environment variable.
Popen is available on windows, if you are on windows, you need to change
proc = subprocess.Popen(args=['rct-complete',
into
proc = subprocess.Popen(args=['ruby', 'path/to/rct-complete'
If it is still not working, follow the instructions from the README#trouble-shooting section for debugging.
Please can you help me to use your plugin with rcodetools.
In this moment i use https://github.com/lifepillar/vim-mucomplete and work.
set completefunc give me this21_RCT_completion
can i use this completefunc??