Example #1
0
 def cm_refresh(self, info, ctx):
     getLogger(__name__).debug('Running a refresh…')
     matches = self._acid_manager.gather_candidates(ctx['base'])
     self._nvim.call('cm#complete',
                     info['name'],
                     ctx,
                     ctx['startcol'],
                     matches,
                     async=True)
Example #2
0
def start_channel(source_name, modulename, serveraddr, start_type='channel'):

    # setup logging
    setup_logging(modulename)
    # setup logger for module
    logger = getLogger(modulename)

    logger = getLogger(__name__)

    logger.info("start_channel for %s", modulename)

    # change proccess title
    try:
        import setproctitle
        setproctitle.setproctitle('%s nvim-completion-manager' % modulename)
    except:
        pass

    try:

        # connect neovim and setup python environment
        nvim = setup_neovim(serveraddr)

        if start_type == 'core':

            import cm_core
            nvim.vars['_cm_channel_id'] = nvim.channel_id
            handler = cm_core.CoreHandler(nvim)
            logger.info('starting core, enter event loop')
            run_event_loop('core', logger, nvim, handler)

        elif start_type == 'channel':

            nvim.call('cm#_channel_started', source_name, nvim.channel_id)

            if sys.version_info.major == 2:
                # python2 doesn't support namespace package
                # use load_source as a workaround
                import imp
                file = modulename.replace('.', '/')
                exp = 'globpath(&rtp,"pythonx/%s.py",1)' % file
                path = nvim.eval(exp).strip()
                logger.info('python2 file path: %s, exp: %s', path, exp)
                m = imp.load_source(modulename, path)
            else:
                m = importlib.import_module(modulename)

            handler = m.Source(nvim)
            logger.info('handler created, entering event loop')
            run_event_loop('channel', logger, nvim, handler)

    except Exception as ex:
        logger.exception('Exception when running %s: %s', modulename, ex)
        exit(1)
    finally:
        # terminate here
        exit(0)
Example #3
0
 def __init__(self, nvim):
     super(Source, self).__init__(nvim)
     # TODO Why is this necessary when it isn't in deoplete sources?
     sys.path.append(
         os.path.join(
             nvim.eval('globpath(&rtp,"rplugin/python3/acid",1)').split(
                 "\n")[0], ".."))
     from async_clj_omni import acid
     self._nvim = nvim
     self._acid_manager = acid.AcidManager(getLogger(__name__), nvim)
     self._acid_manager.on_init()
Example #4
0
# For debugging
# NVIM_PYTHON_LOG_FILE=nvim.log NVIM_PYTHON_LOG_LEVEL=INFO nvim

import sys
import os
import re
import copy
import importlib
import cm
import subprocess
import time
import cm_default
import threading
import json

logger = cm.getLogger(__name__)


# use a trick to only register the source withou loading the entire
# module
class CmSkipLoading(Exception):
    pass


class CoreHandler(cm.Base):
    def __init__(self, nvim):

        super().__init__(nvim)

        # process control information on channels
        self._channel_processes = {}
Example #5
0
register_source(name='cm-jedi',
                priority=9,
                abbreviation='Py',
                scoping=True,
                scopes=['python'],
                multi_thread=0,
                # disable early cache to minimize the issue of #116
                # early_cache=1,
                # The last two patterns is for displaying function signatures r'\(\s?', r',\s?'
                cm_refresh_patterns=[r'^(import|from).*\s', r'\.', r'\(\s?', r',\s?'],
                python=py,)

import re
import jedi

logger = getLogger(__name__)

class Source(Base):

    def __init__(self,nvim):
        Base.__init__(self, nvim)
        self._snippet_engine = nvim.vars['cm_completed_snippet_engine']

        # workaround for #62
        try:
            import resource
            import psutil
            mem = psutil.virtual_memory()
            resource.setrlimit(resource.RLIMIT_DATA, (mem.total/3, resource.RLIM_INFINITY))
        except Exception as ex:
            logger.exception("set RLIMIT_DATA failed. %s", ex)
Example #6
0
from cm import getLogger
from os.path import dirname, join, isfile, samefile
from pathlib import Path
import shlex
import json

logger = getLogger(__name__)


def _extract_args_from_cmake(cmd):
    args = None
    if 'command' in cmd:
        # the last arg is filename
        args = shlex.split(cmd['command'])[:-1]
    elif 'arguments' in cmd:
        # the last arg is filename
        args = cmd['arguments'][:-1]

    # filter for ccache
    while args and not args[0].startswith("-"):
        args = args[1:]
    return args


def args_from_cmake(filepath, cwd, database_paths):
    filedir = dirname(filepath)

    cfg_path = find_config([filedir, cwd], database_paths)

    if not cfg_path:
        return None, None
Example #7
0
# For debugging
# NVIM_PYTHON_LOG_FILE=nvim.log NVIM_PYTHON_LOG_LEVEL=INFO nvim

import sys
import os
import re
import copy
import importlib
import cm
import subprocess
import time
import cm_default
import threading
import json

logger = cm.getLogger(__name__)

# use a trick to only register the source withou loading the entire
# module
class CmSkipLoading(Exception):
    pass

class CoreHandler(cm.Base):

    def __init__(self,nvim):

        super().__init__(nvim)

        # process control information on channels
        self._channel_processes = {}
        self._channel_threads = {}
Example #8
0
""" An ncm source for vim-minisnip """
from os import listdir, path
from cm import register_source, Base, getLogger

register_source(name='vim-minisnip', abbreviation='minisnip', priority=9)

LOGGER = getLogger(__name__)


class Source(Base):
    """ The primary class: fetches, processes and returns snippets """
    def __init__(self, nvim):
        self.nvim = nvim
        self.minisnip_dir = nvim.eval('get(g:, "minisnip_dir")')
        self.snippets = listdir(path.expanduser(self.minisnip_dir))
        LOGGER.info('minisnip snippets: %s', self.snippets)

    def process_matches(self, filetypes):
        """ Process and return snippet names"""
        matches = []
        for filetype in filetypes:
            for snippet in self.snippets:
                if filetype in snippet:
                    matches.append(snippet.split(filetype)[1])
        LOGGER.info('minisnip matches: %s', matches)
        return matches

    def cm_refresh(self, info, ctx):
        """ Refresh NCM with matches """
        split_filetypes = ctx['filetype'].split('.')
        filetypes = ['_' + filetype + '_' for filetype in split_filetypes]
Example #9
0
 def cm_refresh(self,info,ctx):
     getLogger(__name__).debug('Running a refresh…')
     matches = self._cider_completion_manager.gather_candidates(ctx['base'])
     self._nvim.call('cm#complete', info['name'], ctx, ctx['startcol'], matches, False, async=True)
Example #10
0
 def __init__(self,nvim):
     super(Source,self).__init__(nvim)
     self._nvim = nvim
     self._cider_completion_manager = fireplace.CiderCompletionManager(getLogger(__name__), nvim)
Example #11
0
 def __init__(self,nvim):
     super(Source,self).__init__(nvim)
     self._nvim = nvim
     self._cider_completion_manager = fireplace.CiderCompletionManager(getLogger(__name__), nvim)