Exemplo n.º 1
0
class DeopleteHandlers(object):
    def __init__(self, vim):
        self.vim = vim

    @neovim.command("DeopleteInitializePython", sync=True, nargs=0)
    def init_python(self):
        self.deoplete = Deoplete(self.vim)
        self.vim.vars["deoplete#_channel_id"] = self.vim.channel_id

    @neovim.rpc_export("completion_begin")
    def completion_begin(self, context):
        pos = self.vim.current.window.cursor
        try:
            complete_position, candidates = self.deoplete.gather_candidates(context)
        except Exception:
            for line in traceback.format_exc().splitlines():
                error(self.vim, line)
            error(self.vim, "An error has occurred. Please execute :messages command.")
            candidates = []

        if not candidates or self.vim.funcs.mode() != "i" or pos != self.vim.current.window.cursor:
            self.vim.vars["deoplete#_context"] = {}
            return

        var_context = {}
        var_context["complete_position"] = complete_position
        var_context["changedtick"] = context["changedtick"]
        var_context["candidates"] = candidates
        self.vim.vars["deoplete#_context"] = var_context

        # Set (and store) current &completeopt setting.  This cannot be done
        # (currently) from the deoplete_start_complete mapping's function.
        self.vim.command("call deoplete#mappings#_set_completeopt()")
        # Note: cannot use vim.feedkeys()
        self.vim.command('call feedkeys("\<Plug>(deoplete_start_complete)")')
Exemplo n.º 2
0
class DeopleteHandlers(object):
    def __init__(self, vim):
        self.vim = vim

    @neovim.command('DeopleteInitializePython', sync=True, nargs=0)
    def init_python(self):
        self.deoplete = Deoplete(self.vim)
        self.vim.vars['deoplete#_channel_id'] = self.vim.channel_id

    @neovim.rpc_export('completion_begin')
    def completion_begin(self, context):
        pos = self.vim.current.window.cursor
        try:
            complete_position, candidates = self.deoplete.gather_candidates(
                context)
        except Exception:
            for line in traceback.format_exc().splitlines():
                error(self.vim, line)
            error(self.vim,
                  'An error has occurred. Please execute :messages command.')
            candidates = []

        if not candidates or self.vim.funcs.mode() != 'i' \
                or pos != self.vim.current.window.cursor:
            self.vim.vars['deoplete#_context'] = {}
            return

        var_context = {}
        var_context['complete_position'] = complete_position
        var_context['changedtick'] = context['changedtick']
        var_context['candidates'] = candidates
        self.vim.vars['deoplete#_context'] = var_context

        # Set (and store) current &completeopt setting.  This cannot be done
        # (currently) from the deoplete_start_complete mapping's function.
        self.vim.call('deoplete#mappings#_set_completeopt')
        # Note: cannot use vim.feedkeys()
        self.vim.command('call feedkeys("\<Plug>(deoplete_start_complete)")')
Exemplo n.º 3
0
class DeopleteHandlers(object):
    def __init__(self, vim):
        self.vim = vim
        self.msgfile = self.vim.eval('tempname()')

    def debug(self, msg):
        self.vim.command('echomsg string("' + str(msg) + '")')

    def error(self, e):
        with open(self.msgfile, 'a') as f:
            traceback.print_exc(None, f)
        self.vim.command('call deoplete#util#print_error('
                         + '"The error is occurred.  Please read ".'
                         + 'string("'+self.msgfile+'").'
                         +'" file or execute :DeopleteMessages command.")')

    @neovim.command('DeopleteInitializePython', sync=True, nargs=0)
    def init_python(self):
        self.deoplete = Deoplete(self.vim)
        self.vim.command('let g:deoplete#_channel_id = '
        + str(self.vim.channel_id))

    @neovim.command('DeopleteMessages', sync=True, nargs=0)
    def print_error(self):
        self.vim.command('edit ' + self.msgfile)

    @neovim.rpc_export('completion_begin')
    def completion_begin(self, context):
        # Skip
        if self.vim.eval('g:deoplete#_skip_next_complete'):
            self.vim.command(
                'let g:deoplete#_skip_next_complete = 0')
            return
        if self.vim.eval('&paste') != 0:
            return

        # Call omni completion
        omni_patterns = deoplete.util.convert2list(
            deoplete.util.get_buffer_config(
                self.vim, context,
                'b:deoplete_omni_patterns',
                'g:deoplete#omni_patterns',
                'g:deoplete#_omni_patterns'))
        # self.debug(omni_pattern)
        for pattern in omni_patterns:
            if self.vim.eval('mode()') == 'i' \
                    and (pattern != '' \
                         and self.vim.eval('&l:omnifunc') != '' \
                         and re.search('('+pattern+')$', context['input'])) \
                         or self.vim.eval(
                             'deoplete#util#is_eskk_convertion()') != 0:
                self.vim.command(
                    'call feedkeys("\<C-x>\<C-o>", "n")')
                return

        try:
            complete_position, candidates = \
                self.deoplete.gather_candidates(context)
        except Exception as e:
            self.error(e)
            candidates = []
        if not candidates or self.vim.eval('mode()') != 'i':
                return
        self.vim.command(
          'let g:deoplete#_context = {}')
        self.vim.command(
          'let g:deoplete#_context.complete_position = '
            + str(complete_position))
        self.vim.command(
          'let g:deoplete#_context.changedtick = '
            + str(context['changedtick']))
        self.vim.command(
          'let g:deoplete#_context.candidates = '
            + str(candidates))
        self.vim.command(
          'call feedkeys("\<Plug>(deoplete_start_complete)")')
Exemplo n.º 4
0
class DeopleteHandlers(object):
    def __init__(self, vim):
        self.vim = vim

    def debug(self, msg):
        self.vim.command('echomsg string("' + str(msg) + '")')

    def error(self, e):
        tmp = self.vim.eval('tempname()')
        with open(tmp, 'w') as f:
            traceback.print_exc(None, f)
        self.vim.command('call deoplete#util#print_error(' \
                         + '"The error is occurred.  Please read ".'
                         + 'string("'+tmp+'")." file.")')

    @neovim.command('DeopleteInitializePython', sync=True, nargs=0)
    def init_python(self):
        self.deoplete = Deoplete(self.vim)
        self.vim.command('let g:deoplete#_channel_id = '
        + str(self.vim.channel_id))

    @neovim.rpc_export('completion_begin')
    def completion_begin(self, context):
        # Encoding conversion
        encoding = self.vim.eval('&encoding')
        context = { k.decode(encoding) :
                    (v.decode(encoding) if isinstance(v, bytes) else v)
                    for k, v in context.items()}

        # Call omni completion
        omni_patterns = convert2list(get_buffer_config(self.vim, context,
                                         'b:deoplete_omni_patterns',
                                         'g:deoplete#omni_patterns',
                                         'g:deoplete#_omni_patterns'))
        # self.debug(omni_pattern)
        for pattern in omni_patterns:
            if pattern != '' \
                    and self.vim.eval('&l:omnifunc') != '' \
                    and re.search('('+pattern+')$', context['input']) \
                    and self.vim.eval('mode()') == 'i':
                self.vim.command(
                    'call feedkeys("\<C-x>\<C-o>", "n")')
                return

        try:
            complete_position, candidates = \
                self.deoplete.gather_candidates(context)
        except Exception as e:
            self.error(e)
            candidates = []
        if not candidates or self.vim.eval('mode()') != 'i':
                return
        self.vim.command(
          'let g:deoplete#_context = {}')
        self.vim.command(
          'let g:deoplete#_context.complete_position = '
            + str(complete_position))
        self.vim.command(
          'let g:deoplete#_context.changedtick = '
            + str(context['changedtick']))
        self.vim.command(
          'let g:deoplete#_context.candidates = '
            + str(candidates))
        self.vim.command(
          'call feedkeys("\<Plug>(deoplete_start_complete)")')