From 5537c453071742c7f48477cbed226831d8c1711f Mon Sep 17 00:00:00 2001 From: Edward Ash Date: Tue, 18 Aug 2015 13:37:05 -0700 Subject: [PATCH 1/3] Add deoplete compatability --- ftplugin/perl/perlomni.vim | 1 + .../__pycache__/perlomni.cpython-34.pyc | Bin 0 -> 1176 bytes rplugin/python3/deoplete/sources/perlomni.py | 22 ++++++++++++++++++ utils/find_base_classes.pl | 0 utils/moose-type-constraints | 0 utils/parse_moose_accessor.pl | 0 6 files changed, 23 insertions(+) create mode 100644 rplugin/python3/deoplete/sources/__pycache__/perlomni.cpython-34.pyc create mode 100644 rplugin/python3/deoplete/sources/perlomni.py mode change 100644 => 100755 utils/find_base_classes.pl mode change 100644 => 100755 utils/moose-type-constraints mode change 100644 => 100755 utils/parse_moose_accessor.pl diff --git a/ftplugin/perl/perlomni.vim b/ftplugin/perl/perlomni.vim index 8f2170c..d1745eb 100644 --- a/ftplugin/perl/perlomni.vim +++ b/ftplugin/perl/perlomni.vim @@ -767,6 +767,7 @@ endf " util function for building completion hashlist fun! s:toCompHashList(list,menu) + return a:list return map( a:list , '{ "word": v:val , "menu": "'. a:menu .'" }' ) endf diff --git a/rplugin/python3/deoplete/sources/__pycache__/perlomni.cpython-34.pyc b/rplugin/python3/deoplete/sources/__pycache__/perlomni.cpython-34.pyc new file mode 100644 index 0000000000000000000000000000000000000000..09406649f46770e3c05a160b64c9066108cf748c GIT binary patch literal 1176 zcmZ`&Pfrt35TCdETG~<~)mEEhygv3-Jhw zi4sA5K_av$v?;czZ`1owQdptSFsYCdbZt`~8k>4f^+v$i5v6?R=jsMBbpz(}gP^k@ zuOKL5Y=r6q9fHM}2mmOAVA%u$Y+3DPV;!h~{rT|Q2JL|IRj`6+DCm;t5(!yI*yaxp zz?KmJNk~w3%i6xu@m`Wf6Z_-dfg^MU?vB(9S=Kx+N~6N_N}2kJDrMs96UQoLuHvK8 zK8uoXq!(d1-FF9BqFm+Y1GfXcdpJ(RSh*vhXFxYPJ&MQ2QR0&$Q85;BjtZnIg$p!YsQ*Dm^QZJC@%u!wf&f3 zIYyl(YrmU*>=y&2y}(byDD(@Jcedgz@Z)?N!rT#?(|}tk)tMic3jj-CU&>(?rA|fH z`3~B&Q0GM{xhGg7SXRNtD!-Rf`S7oxjGni^$ZCnEkTWh?;)OMN^1n>GPK9@wcNn|e z@Vq1o$1%%I&pRFa@$AOzoPG-IJ9+SWYwnNc1!KyYHAS;xG=P?e_`PR;%+h?PJL4jX Z%i8?YnEng3tZmJb+2+w2=w+)ZegO=j29W>& literal 0 HcmV?d00001 diff --git a/rplugin/python3/deoplete/sources/perlomni.py b/rplugin/python3/deoplete/sources/perlomni.py new file mode 100644 index 0000000..b61706c --- /dev/null +++ b/rplugin/python3/deoplete/sources/perlomni.py @@ -0,0 +1,22 @@ +from .base import Base + +import deoplete.util +class Source(Base): + def __init__(self, vim): + Base.__init__(self,vim) + self.name = 'PerlOmni', + self.mark ='[O]' + + def gather_candidates(self,context): + + type=self.vim.eval("&filetype") + if type != "perl": + return [] + + val=self.vim.eval("PerlComplete(1,'')") + if val < 1: + return [] + values=self.vim.eval("PerlComplete(0,'')") + self.vim.command("echo '"+','.join(values)+"'") + + return [{'word': x } for x in values] diff --git a/utils/find_base_classes.pl b/utils/find_base_classes.pl old mode 100644 new mode 100755 diff --git a/utils/moose-type-constraints b/utils/moose-type-constraints old mode 100644 new mode 100755 diff --git a/utils/parse_moose_accessor.pl b/utils/parse_moose_accessor.pl old mode 100644 new mode 100755 From 88ee24bf628e342cdb11245613df03c2b8240e6a Mon Sep 17 00:00:00 2001 From: Edward Ash Date: Fri, 21 Aug 2015 19:29:06 -0700 Subject: [PATCH 2/3] use lib --- play.py | 120 ++++++++++++++++++ .../python3/deoplete/sources/perl_class.py | 80 ++++++++++++ 2 files changed, 200 insertions(+) create mode 100755 play.py create mode 100644 rplugin/python3/deoplete/sources/perl_class.py diff --git a/play.py b/play.py new file mode 100755 index 0000000..3f483e8 --- /dev/null +++ b/play.py @@ -0,0 +1,120 @@ +#! /home/utils/Python-2.7.8/bin/python +import os, fnmatch, string, re, subprocess +from neovim import attach +def CompClassName(base):#,context): + #cache = GetCacheNS('class',base) + # if type(cache) != type(0) + # return cache + # endif + + # " XXX: prevent waiting too long + if len(base) == 0: + return [ ] + + cache_file='/home/eash/.vim-cpan-module-cache' + +#TODO create cache_file + + result = [] + + #search file for cache + fh=file(cache_file) + for line in fh: + if base in line: + result.append(line.rstrip()) + print line.rstrip() + +# cal extend(classnames, s:scanClass('lib')) + + #look for all modules in lib subdirectory + pattern='*.pm' + for root, dirs, files in os.walk('lib'): + for name in files: + if fnmatch.fnmatch(name, pattern): + name=os.path.join(root, name) + name=name[4:-3] # remove lib/, #.pm + name=string.replace(name,'perl5/','') + name=string.replace(name,'/','::') + # name=string.replace(name,'.pm','') # remove .pm + result.append(name) + print name + + #filter + resultlist=[] + for func in result: + if func.startswith(base) + resultlist.append(func) + + return result + + +# CompClassName('NV::') + +# " perl builtin functions +def CompFunction(base,context) + + #get current functions that are in namespace, due to 'use' + efuncs = scanCurrentExportFunction() + #TODO + # flist = nvim.eval(perlomni#data#p5bfunctions()) + # cal extend(flist,efuncs) + flist=[] + for func in efuncs: + if func.startswith(base) + flist.append(func) + + return flist + + + + + +# " Scan export functions in current buffer +# " Return functions +def scanCurrentExportFunction(): + nvim=attach('socket',path='/tmp/nvim') + bufname=nvim.current.buffer.name + cache = nvim.eval("GetCacheNS('cbexf', "+bufname+")") + # if type(l:cache) != type(0) + # return l:cache + # endif + + funcs=[] + + #find the modules that are used + + for line in nvim.currentbuffer[:] # get all lines from the buffer + match=re.search('^\s*\(use\|require\)\s+(\w+)',line) + if match: + #todo covert to python + funcs.append(scanModuleExportFunctions(match.group(0))) + + return funcs + #return SetCacheNS('cbexf',bufname('%'),funcs) + +def run_perl(mtext, code): + #todo catch error + return subprocess.check_output(['perl', '-M'+mtext , '-e',code ]) + +run_perl('Moo','print @Moo::EXPORT_OK') + +def scanModuleExportFunctions(class): + # let l:cache = GetCacheNS('mef',a:class) + # if type(l:cache) != type(0) + # return l:cache + # endif + + funcs = [] + + # " TODO: TOO SLOW, CACHE TO FILE!!!! + # if exists('g:perlomni_export_functions') + output = run_perl( a:class , printf( 'print join " ",@%s::EXPORT_OK' , a:class )) + funcs.append( string.split(' ', output ) ) + output =run_perl( a:class , printf( 'print join " ",@%s::EXPORT' , a:class )) + funcs.append( string.split( output ) ) + # endif + # return SetCacheNS('mef',a:class,s:toCompHashList(funcs,a:class)) +# " echo s:scanModuleExportFunctions( 'List::MoreUtils' ) +# " sleep 1 + + diff --git a/rplugin/python3/deoplete/sources/perl_class.py b/rplugin/python3/deoplete/sources/perl_class.py new file mode 100644 index 0000000..f536bd5 --- /dev/null +++ b/rplugin/python3/deoplete/sources/perl_class.py @@ -0,0 +1,80 @@ +import deoplete.util, re,os , fnmatch, string, subprocess +from .base import Base + +class Source(Base): + + + # rules={'use_lib':{}} + def __init__(self, vim): + Base.__init__(self,vim) + self.name = 'PerlClass', + self.mark ='[O]' + + + def get_complete_position(self, context): + m = re.search('use lib ', context['input']) + if m : + m = re.search('([\w:]+)$', context['input']) + context['completion_func']=self.CompClassName + return m.start() if m else -1; + else: + return -1 + + + + def gather_candidates(self,context): + deoplete.util.debug(self.vim, context) + return [{'word': x } for x in context['completion_func'](context['complete_str'])] + + + + +############################## +# Completion classes +############################## + + def CompClassName(self,base):#,context): + #cache = GetCacheNS('class',base) + # if type(cache) != type(0) + # return cache + # endif + + # " XXX: prevent waiting too long + if len(base) == 0: + return [ ] + + cache_file='/home/eash/.vim-cpan-module-cache' + + #TODO create cache_file + + result = [] + + #search file for cache + fh=open(cache_file,'r') + for line in fh: + if base in line: + result.append(line.rstrip()) + # print line.rstrip() + + # cal extend(classnames, s:scanClass('lib')) + + #look for all modules in lib subdirectory + pattern='*.pm' + for root, dirs, files in os.walk('lib'): + for name in files: + if fnmatch.fnmatch(name, pattern): + name=os.path.join(root, name) + name=name[4:-3] # remove lib/, #.pm + name=string.replace(name,'perl5/','') + name=string.replace(name,'/','::') + # name=string.replace(name,'.pm','') # remove .pm + result.append(name) + + #filter + # resultlist=[] + # for func in result: + # if func.startswith(base) + # resultlist.append(func) + + return result + From c8c335267b0286aafd95f2c8cb5895356c6eff33 Mon Sep 17 00:00:00 2001 From: Edward Ash Date: Tue, 25 Aug 2015 18:33:21 -0700 Subject: [PATCH 3/3] functions --- ftplugin/perl/perlomni.vim | 42 ++--- .../python3/deoplete/sources/perl_class.py | 173 ++++++++++++++---- .../python3/deoplete/sources/perl_funcion.py | 103 +++++++++++ 3 files changed, 260 insertions(+), 58 deletions(-) create mode 100644 rplugin/python3/deoplete/sources/perl_funcion.py diff --git a/ftplugin/perl/perlomni.vim b/ftplugin/perl/perlomni.vim index d1745eb..b746289 100644 --- a/ftplugin/perl/perlomni.vim +++ b/ftplugin/perl/perlomni.vim @@ -1015,10 +1015,10 @@ cal s:rule({ \'context' : '^$', \'comp' : function('s:CompModuleInstallExport') }) -cal s:rule( { - \'context': '^\(requires\|build_requires\|test_requires\)\s', - \'backward': '[a-zA-Z0-9:]*$', - \'comp': function('s:CompClassName') }) +" cal s:rule( { +" \'context': '^\(requires\|build_requires\|test_requires\)\s', +" \'backward': '[a-zA-Z0-9:]*$', +" \'comp': function('s:CompClassName') }) " }}} " UNDERSCORES =================================="{{{ @@ -1110,19 +1110,19 @@ cal s:rule({ " use base qw(ClassName ... " use base 'ClassName -cal s:rule({ - \'only':1, - \'context': '\<\(new\|use\)\s\+\(\(base\|parent\)\s\+\(qw\)\?[''"(/]\)\?$' , - \'backward': '\<[A-Z][A-Za-z0-9_:]*$', - \'comp': function('s:CompClassName') } ) - - -cal s:rule({ - \'only':1, - \'context': '^extends\s\+[''"]$' , - \'backward': '\<\u[A-Za-z0-9_:]*$', - \'comp': function('s:CompClassName') } ) - +" cal s:rule({ +" \'only':1, +" \'context': '\<\(new\|use\)\s\+\(\(base\|parent\)\s\+\(qw\)\?[''"(/]\)\?$' , +" \'backward': '\<[A-Z][A-Za-z0-9_:]*$', +" \'comp': function('s:CompClassName') } ) +" +" +" cal s:rule({ +" \'only':1, +" \'context': '^extends\s\+[''"]$' , +" \'backward': '\<\u[A-Za-z0-9_:]*$', +" \'comp': function('s:CompClassName') } ) +" cal s:rule({ \'context': '^\s*\(sub\|method\)\s\+' , \'backward': '\<\w\+$' , @@ -1163,10 +1163,10 @@ cal s:rule({ " function completion -cal s:rule({ - \'context': '\(->\|\$\)\@\|\$\)\@$' , \'backward': '\<\w\+$' , diff --git a/rplugin/python3/deoplete/sources/perl_class.py b/rplugin/python3/deoplete/sources/perl_class.py index f536bd5..f18e626 100644 --- a/rplugin/python3/deoplete/sources/perl_class.py +++ b/rplugin/python3/deoplete/sources/perl_class.py @@ -1,76 +1,118 @@ -import deoplete.util, re,os , fnmatch, string, subprocess +#!/usr/bin/python +# -*- coding: utf-8 -*- +import deoplete.util +import re +import os +import fnmatch +import string +import subprocess from .base import Base -class Source(Base): +class Source(Base): - # rules={'use_lib':{}} def __init__(self, vim): - Base.__init__(self,vim) - self.name = 'PerlClass', - self.mark ='[O]' - + Base.__init__(self, vim) + self.name = ('PerlClass', ) + self.mark = '[O]' + self.rules = [ +#" class name completion +# " matches: +# " new [ClassName] +# " use [ClassName] +# " use base qw(ClassName ... +# " use base 'ClassName + {'context': re.compile('^use lib [\w:]*$'), + 'backward': re.compile('([\w:]+)$'), + 'comp': self.CompClassName}, + {'context': re.compile('^\s*(?:requires|build_requires|test_requires)\s'), + 'backward': re.compile('([\w:]*)$'), + 'comp': self.CompClassName}, + {'context': re.compile('(?:new|use)\s+[\w:]*$'), + 'backward': re.compile('([\w:]*)$'), + 'comp': self.CompClassName}, + {'context': re.compile('(?:new|use)\sbase\sqw\([\w:]*$'), + 'backward': re.compile('([\w:]*)$'), + 'comp': self.CompClassName}, + {'context': re.compile('(?:new|use)\sbase\s[\'"][\w:]$'), + 'backward': re.compile('([\w:]*)$'), + 'comp': self.CompClassName}, + + #generic class:: match + {'context': re.compile('[\w\d]+::[\w\d]*$'), + 'backward': re.compile('([\w:]*)$'), + 'comp': self.CompClassName}, + + #function completion + {'context': re.compile('[\s^]\w+'), + 'backward': re.compile('([\w:]+)$'), + 'comp': self.CompFunction}, + + ] def get_complete_position(self, context): - m = re.search('use lib ', context['input']) - if m : - m = re.search('([\w:]+)$', context['input']) - context['completion_func']=self.CompClassName - return m.start() if m else -1; - else: - return -1 - - - - def gather_candidates(self,context): + for rule in self.rules: + if rule['context'].match(context['input']): + deoplete.util.debug(self.vim, 'Hi') + m = rule['backward'].search(context['input']) + context['completion_func'] = rule['comp'] + return (m.start() if m else -1) + return -1 + + def gather_candidates(self, context): deoplete.util.debug(self.vim, context) - return [{'word': x } for x in context['completion_func'](context['complete_str'])] - - - + return [{'word': x} for x in context['completion_func' + ](context['complete_str'])] ############################## # Completion classes ############################## - def CompClassName(self,base):#,context): - #cache = GetCacheNS('class',base) + def CompClassName(self, base): # ,context): + + # cache = GetCacheNS('class',base) # if type(cache) != type(0) # return cache # endif # " XXX: prevent waiting too long + if len(base) == 0: - return [ ] + return [] - cache_file='/home/eash/.vim-cpan-module-cache' + cache_file = '/home/eash/.vim-cpan-module-cache' - #TODO create cache_file + # TODO create cache_file result = [] - #search file for cache - fh=open(cache_file,'r') + # search file for cache + + fh = open(cache_file, 'r') for line in fh: if base in line: result.append(line.rstrip()) + # print line.rstrip() # cal extend(classnames, s:scanClass('lib')) - #look for all modules in lib subdirectory - pattern='*.pm' - for root, dirs, files in os.walk('lib'): + # look for all modules in lib subdirectory + + pattern = '*.pm' + for (root, dirs, files) in os.walk('lib'): for name in files: if fnmatch.fnmatch(name, pattern): - name=os.path.join(root, name) - name=name[4:-3] # remove lib/, #.pm - name=string.replace(name,'perl5/','') - name=string.replace(name,'/','::') + name = os.path.join(root, name) + name = name[4:-3] # remove lib/, #.pm + name = string.replace(name, 'perl5/', '') + name = string.replace(name, '/', '::') + # name=string.replace(name,'.pm','') # remove .pm + result.append(name) - #filter + # filter # resultlist=[] # for func in result: # if func.startswith(base) @@ -78,3 +120,60 @@ def CompClassName(self,base):#,context): return result + + + # " perl builtin functions + def CompFunction(base,context): + + #get current functions that are in namespace, due to 'use' + efuncs = scanCurrentExportFunction() + #TODO + # flist = nvim.eval(perlomni#data#p5bfunctions()) + # cal extend(flist,efuncs) + + return efuncs + + # " Scan export functions in current buffer + # " Return functions + def scanCurrentExportFunction(self): + # cache = nvim.eval("GetCacheNS('cbexf', "+bufname+")") + # if type(l:cache) != type(0) + # return l:cache + # endif + + funcs=[] + + #find the modules that are used + + for line in self.vim.currentbuffer[:]: # get all lines from the buffer + match=re.search('^\s*\(use\|require\)\s+(\w+)',line) + if match: + #todo covert to python + funcs.append(self.scanModuleExportFunctions(match.group(0))) + + return funcs + #return SetCacheNS('cbexf',bufname('%'),funcs) + + def run_perl(mtext, code): + #todo catch error + return subprocess.check_output(['perl', '-M'+mtext , '-e',code ]) + + def scanModuleExportFunctions(self, class_name): + # let l:cache = GetCacheNS('mef',a:class) + # if type(l:cache) != type(0) + # return l:cache + # endif + + funcs = [] + + # " TODO: TOO SLOW, CACHE TO FILE!!!! + # if exists('g:perlomni_export_functions') + output = run_perl( class_name, printf( 'print join " ",@%s::EXPORT_OK' , class_name )) + funcs.append( string.split(' ', output ) ) + output =run_perl( class_name , printf( 'print join " ",@%s::EXPORT' , class_name )) + funcs.append( string.split( output ) ) + # endif + # return SetCacheNS('mef',a:class,s:toCompHashList(funcs,a:class)) + # " echo s:scanModuleExportFunctions( 'List::MoreUtils' ) + # " sleep 1 + diff --git a/rplugin/python3/deoplete/sources/perl_funcion.py b/rplugin/python3/deoplete/sources/perl_funcion.py new file mode 100644 index 0000000..de0c092 --- /dev/null +++ b/rplugin/python3/deoplete/sources/perl_funcion.py @@ -0,0 +1,103 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +import deoplete.util +import re +import os +import fnmatch +import string +import subprocess +from .base import Base + + +class Source(Base): + + def __init__(self, vim): + Base.__init__(self, vim) + self.name = ('PerlClass', ) + self.mark = '[O]' + self.rules = [ + #function completion + {'context': re.compile('^\s(?:sub|method)\s+\w*'), + 'backward': re.compile('\w*'), + 'comp':self.CompCurrentBaseFunction,} + {'context': re.compile('[\s^]\w+'), + 'backward': re.compile('([\w:]+)$'), + 'comp': self.CompFunction}, + + ] + + def get_complete_position(self, context): + for rule in self.rules: + if rule['context'].match(context['input']): + deoplete.util.debug(self.vim, 'Hi') + m = rule['backward'].search(context['input']) + context['completion_func'] = rule['comp'] + return (m.start() if m else -1) + return -1 + + def gather_candidates(self, context): + deoplete.util.debug(self.vim, context) + return [{'word': x} for x in context['completion_func' + ](context['complete_str'])] + +############################## +# Completion classes +############################## + + + + # " perl builtin functions + def CompFunction(base,context): + + #get current functions that are in namespace, due to 'use' + efuncs = scanCurrentExportFunction() + #TODO + # flist = nvim.eval(perlomni#data#p5bfunctions()) + # cal extend(flist,efuncs) + + return efuncs + + # " Scan export functions in current buffer + # " Return functions + def scanCurrentExportFunction(self): + # cache = nvim.eval("GetCacheNS('cbexf', "+bufname+")") + # if type(l:cache) != type(0) + # return l:cache + # endif + + funcs=[] + + #find the modules that are used + + for line in self.vim.currentbuffer[:]: # get all lines from the buffer + match=re.search('^\s*\(use\|require\)\s+(\w+)',line) + if match: + #todo covert to python + funcs.append(self.scanModuleExportFunctions(match.group(0))) + + return funcs + #return SetCacheNS('cbexf',bufname('%'),funcs) + + def run_perl(mtext, code): + #todo catch error + return subprocess.check_output(['perl', '-M'+mtext , '-e',code ]) + + def scanModuleExportFunctions(self, class_name): + # let l:cache = GetCacheNS('mef',a:class) + # if type(l:cache) != type(0) + # return l:cache + # endif + + funcs = [] + + # " TODO: TOO SLOW, CACHE TO FILE!!!! + # if exists('g:perlomni_export_functions') + output = run_perl( class_name, printf( 'print join " ",@%s::EXPORT_OK' , class_name )) + funcs.append( string.split(' ', output ) ) + output =run_perl( class_name , printf( 'print join " ",@%s::EXPORT' , class_name )) + funcs.append( string.split( output ) ) + # endif + # return SetCacheNS('mef',a:class,s:toCompHashList(funcs,a:class)) + # " echo s:scanModuleExportFunctions( 'List::MoreUtils' ) + # " sleep 1 +