Skip to content

Commit

Permalink
Merge branch 'cazador481-deoplete'
Browse files Browse the repository at this point in the history
Conflicts:
	ftplugin/perl/perlomni.vim
  • Loading branch information
chumakd committed Aug 26, 2015
2 parents d7db2a3 + c8c3352 commit d1d8cde
Show file tree
Hide file tree
Showing 9 changed files with 442 additions and 17 deletions.
35 changes: 18 additions & 17 deletions ftplugin/perl/perlomni.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -1014,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 =================================="{{{
Expand Down Expand Up @@ -1109,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|has\)\s\+' ,
\'backward': '\<\w\+$' ,
Expand Down
120 changes: 120 additions & 0 deletions play.py
Original file line number Diff line number Diff line change
@@ -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


Binary file not shown.
179 changes: 179 additions & 0 deletions rplugin/python3/deoplete/sources/perl_class.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
#!/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 = [
#" 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):
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
##############################

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



# " 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

Loading

0 comments on commit d1d8cde

Please sign in to comment.