Skip to content
This repository has been archived by the owner on Mar 6, 2023. It is now read-only.

add ncm2 source support #63

Merged
merged 1 commit into from
Jul 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
doc/tags
*.pyc
31 changes: 31 additions & 0 deletions autoload/ncm2_gtags.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
if get(s:, 'loaded', 0)
finish
endif
let s:loaded = 1

let g:ncm2_gtags#proc = yarp#py3('ncm2_gtags')

let g:ncm2_gtags#source = get(g:, 'ncm2_gtags#source', {
\ 'name': 'gtags',
\ 'priority': 6,
\ 'mark': 'gtags',
\ 'word_pattern': '[\w/]+',
\ 'on_complete': 'ncm2_gtags#on_complete',
\ 'on_warmup': 'ncm2_gtags#on_warmup'
\ })

let g:ncm2_gtags#source = extend(g:ncm2_gtags#source,
\ get(g:, 'ncm2_gtags#source_override', {}),
\ 'force')

func! ncm2_gtags#init()
call ncm2#register_source(g:ncm2_gtags#source)
endfunc

func! ncm2_gtags#on_warmup(ctx)
call g:ncm2_gtags#proc.jobstart()
endfunc

func! ncm2_gtags#on_complete(ctx)
call g:ncm2_gtags#proc.try_notify('on_complete', a:ctx)
endfunc
1 change: 1 addition & 0 deletions ncm2-plugin/ncm2_gtags.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
call ncm2_gtags#init()
39 changes: 25 additions & 14 deletions pythonx/cm_sources/gtags.py → pythonx/ncm2_gtags.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,38 @@
# -*- coding: utf-8 -*-

from cm import register_source, Base
import vim
from ncm2 import Ncm2Source, getLogger, Popen
import subprocess
from distutils.spawn import find_executable

register_source(name='gtags',
priority=6,
abbreviation='gtags',
word_pattern=r'\w+')
logger = getLogger(__name__)


class Source(Base):
class Source(Ncm2Source):

GTAGS_DB_NOT_FOUND_ERROR = 3

def __init__(self, nvim):
super().__init__(nvim)
self._checked = False
def check_executable(self):
if not find_executable('global'):
return False
else:
return True

def is_word_valid_for_search(self, word):
FORRBIDDEN_CHARACTERS = [
'^', '$', '{', '}', '(', ')', '.',
'*', '+', '[', ']', '?', '\\'
]
'^', '$', '{', '}', '(', ')', '.',
'*', '+', '[', ']', '?', '\\'
]

for forbbiden_char in FORRBIDDEN_CHARACTERS:
if forbbiden_char in word:
return False
return True

def cm_refresh(self, info, ctx):
def on_complete(self, ctx):
if not self.check_executable():
return []

base = ctx['base']

if not self.is_word_valid_for_search(base):
Expand Down Expand Up @@ -56,4 +60,11 @@ def cm_refresh(self, info, ctx):

matches = output[0].decode('utf8').splitlines()

self.complete(info, ctx, ctx['startcol'], matches)
logger.info('matches %s', matches)

self.complete(ctx, ctx['startccol'], matches)


source = Source(vim)

on_complete = source.on_complete
1 change: 0 additions & 1 deletion rplugin/python3/deoplete/sources/gtags.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def gather_candidates(self, ctx):
command.append('-i')

proc = subprocess.Popen(command,
cwd=ctx['cwd'],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL)
Expand Down