Пример #1
0
    def _get_complete_position(self, context, current_ft, filetype):
        for omnifunc in convert2list(
                self.get_filetype_var(filetype, 'functions')):
            if omnifunc == '' and (filetype == current_ft or
                                   filetype in ['css', 'javascript']):
                omnifunc = context['omni__omnifunc']
            if omnifunc == '':
                continue
            self._omnifunc = omnifunc
            for input_pattern in convert2list(
                    self.get_filetype_var(filetype, 'input_patterns')):

                m = re.search('(' + input_pattern + ')$', context['input'])
                # self.debug(filetype)
                # self.debug(input_pattern)
                if input_pattern == '' or (context['event'] !=
                                           'Manual' and m is None):
                    continue

                if filetype == current_ft and self._omnifunc in [
                        'ccomplete#Complete',
                        'htmlcomplete#CompleteTags',
                        'LanguageClient#complete',
                        'phpcomplete#CompletePHP']:
                    # In the blacklist
                    return -1
                try:
                    complete_pos = self.vim.call(self._omnifunc, 1, '')
                except Exception as e:
                    self.print_error('Error occurred calling omnifunction: ' +
                                     self._omnifunc)
                    return -1
                return complete_pos
        return -1
Пример #2
0
    def get_complete_position(self, context):
        if self.__use_previous_result(context):
            return self.__prev_pos

        current_ft = self.vim.eval('&filetype')
        for filetype in context['filetypes']:
            for omnifunc in convert2list(
                    get_buffer_config(context, filetype,
                                      'deoplete_omni_functions',
                                      'deoplete#omni#functions',
                                      {'_': ''})):
                if omnifunc == '' and filetype == current_ft:
                    omnifunc = context['omni__omnifunc']
                if omnifunc == '' or not self.vim.call(
                            'deoplete#util#exists_omnifunc', omnifunc):
                    continue
                self.__omnifunc = omnifunc
                for input_pattern in convert2list(
                    get_buffer_config(context, filetype,
                                      'deoplete_omni_input_patterns',
                                      'deoplete#omni#input_patterns',
                                      self.__input_patterns)):

                    m = re.search('(' + input_pattern + ')$', context['input'])
                    # self.debug(filetype)
                    # self.debug(input_pattern)
                    if input_pattern == '' or (context['event'] !=
                                               'Manual' and m is None):
                        continue

                    if self.__omnifunc in [
                            'ccomplete#Complete',
                            'htmlcomplete#CompleteTags',
                            'phpcomplete#CompletePHP']:
                        # In the blacklist
                        error(self.vim,
                              'omni source does not support: ' +
                              self.__omnifunc)
                        error(self.vim,
                              'You must use g:deoplete#omni_patterns' +
                              ' instead.')
                        return -1
                    try:
                        complete_pos = self.vim.call(self.__omnifunc, 1, '')
                    except:
                        error_vim(self.vim,
                                  'Error occurred calling omnifunction: ' +
                                  self.__omnifunc)
                        return -1
                    return complete_pos
        return -1
Пример #3
0
    def get_complete_position(self, context):
        if self.__use_previous_result(context):
            return self.__prev_pos

        omnifunc = get_buffer_config(
            self.vim, context, "b:deoplete_omni_functions", "g:deoplete#omni#functions", "g:deoplete#omni#_functions"
        )
        if omnifunc == "":
            omnifunc = self.vim.eval("&l:omnifunc")
        if omnifunc == "" or omnifunc == "ccomplete#Complete":
            return -1
        for input_pattern in convert2list(
            get_buffer_config(
                self.vim,
                context,
                "b:deoplete_omni_input_patterns",
                "g:deoplete#omni#input_patterns",
                "g:deoplete#omni#_input_patterns",
            )
        ):

            m = re.search("(" + input_pattern + ")$", context["input"])
            if input_pattern == "" or (context["event"] != "Manual" and m is None):
                continue

            try:
                complete_pos = self.vim.call(omnifunc, 1, "")
            except:
                error(self.vim, "Error occurred calling omnifunction: " + omnifunc)
                return -1
            return complete_pos
        return -1
Пример #4
0
    def get_complete_position(self, context):
        # Check member prefix pattern.
        if self.vim.eval('&l:omnifunc') == '':
            return -1
        for input_pattern in convert2list(
            get_default_buffer_config(
                self.vim, context,
                'b:deoplete_omni_input_patterns',
                'g:deoplete#omni#input_patterns',
                'g:deoplete#omni#_input_patterns')):

            m = re.search('('+input_pattern+')$', context['input'])
            if m is None or input_pattern == '':
                continue

            pos = self.vim.current.window.cursor
            try:
                complete_pos = self.vim.call(
                    self.vim.eval('&l:omnifunc'), 1, '')
            except:
                error(self.vim, 'Error occurred calling omnifunction: '
                    + self.vim.eval('&l:omnifunc'))

                return -1
            finally:
                if pos != self.vim.current.window.cursor:
                    error(self.vim, 'omnifunction: '
                        + self.vim.eval('&l:omnifunc') + ' moves cursor!')
                    error(self.vim, 'Deoplete cannot support it in omni source.'
                        + ' You should use g:deoplete#omni_patterns.')
            return complete_pos
        return -1
Пример #5
0
    def get_complete_position(self, context):
        # Check member prefix pattern.
        if self.vim.eval('&l:omnifunc') == '':
            return -1
        for input_pattern in convert2list(
            get_default_buffer_config(
                self.vim, context,
                'b:deoplete_omni_input_patterns',
                'g:deoplete#omni#input_patterns',
                'g:deoplete#omni#_input_patterns')):

            m = re.search(input_pattern, context['input'])
            if m is None or input_pattern == '':
                continue

            pos = self.vim.eval('getpos(".")')
            try:
                complete_pos = self.vim.eval('call(&l:omnifunc, [1, ""])')
            except:
                self.vim.command(
                    'call deoplete#util#print_error('
                    + '"Error occurred calling omnifunction: "'
                    + '. &l:omnifunc)')
                self.vim.command(
                    'call deoplete#util#print_error(v:throwpoint)')
                self.vim.command(
                    'call deoplete#util#print_error(v:exception)')

                return -1
            finally:
                if pos != self.vim.eval('getpos(".")'):
                    self.vim.command(
                        'call setpos(".", {0})'.format(str(pos)))
            return complete_pos
        return -1
Пример #6
0
    def get_complete_position(self, context):
        if self.__use_previous_result(context):
            return self.__prev_pos

        omnifunc = get_buffer_config(self.vim, context,
                                     'b:deoplete_omni_functions',
                                     'g:deoplete#omni#functions',
                                     'g:deoplete#omni#_functions')
        if omnifunc == '':
            omnifunc = self.vim.eval('&l:omnifunc')
        if omnifunc == '' or omnifunc == 'ccomplete#Complete':
            return -1
        for input_pattern in convert2list(
            get_buffer_config(self.vim, context,
                              'b:deoplete_omni_input_patterns',
                              'g:deoplete#omni#input_patterns',
                              'g:deoplete#omni#_input_patterns')):

            m = re.search('(' + input_pattern + ')$', context['input'])
            if input_pattern == '' or (context['event'] != 'Manual'
                                       and m is None):
                continue

            try:
                complete_pos = self.vim.call(omnifunc, 1, '')
            except:
                error(self.vim, 'Error occurred calling omnifunction: '
                      + omnifunc)
                return -1
            return complete_pos
        return -1
Пример #7
0
    def get_complete_position(self, context):
        # Check member prefix pattern.
        if self.vim.eval('&l:omnifunc') == '':
            return -1
        for input_pattern in convert2list(
            get_default_buffer_config(
                self.vim, context,
                'b:deoplete_omni_input_patterns',
                'g:deoplete#omni#input_patterns',
                'g:deoplete#omni#_input_patterns')):

            m = re.search('(' + input_pattern + ')$', context['input'])
            if m is None or input_pattern == '':
                continue

            try:
                complete_pos = self.vim.call(
                    self.vim.eval('&l:omnifunc'), 1, '')
            except:
                error(self.vim, 'Error occurred calling omnifunction: '
                      + self.vim.eval('&l:omnifunc'))

                return -1
            return complete_pos
        return -1
Пример #8
0
    def _get_complete_position(self, context, current_ft, filetype):
        for omnifunc in convert2list(
                get_buffer_config(context, filetype,
                                  'deoplete_omni_functions',
                                  'deoplete#omni#functions',
                                  {'_': ''})):
            if omnifunc == '' and (filetype == current_ft or
                                   filetype in ['css', 'javascript']):
                omnifunc = context['omni__omnifunc']
            if omnifunc == '':
                continue
            self.__omnifunc = omnifunc
            for input_pattern in convert2list(
                    get_buffer_config(context, filetype,
                                      'deoplete_omni_input_patterns',
                                      'deoplete#omni#input_patterns',
                                      self._input_patterns)):

                m = re.search('(' + input_pattern + ')$', context['input'])
                # self.debug(filetype)
                # self.debug(input_pattern)
                if input_pattern == '' or (context['event'] !=
                                           'Manual' and m is None):
                    continue

                if filetype == current_ft and self.__omnifunc in [
                        'ccomplete#Complete',
                        'htmlcomplete#CompleteTags',
                        'phpcomplete#CompletePHP']:
                    # In the blacklist
                    error(self.vim,
                          'omni source does not support: ' +
                          self.__omnifunc)
                    error(self.vim,
                          'You must use g:deoplete#omni_patterns' +
                          ' instead.')
                    return -1
                try:
                    complete_pos = self.vim.call(self.__omnifunc, 1, '')
                except:
                    error_vim(self.vim,
                              'Error occurred calling omnifunction: ' +
                              self.__omnifunc)
                    return -1
                return complete_pos
        return -1
Пример #9
0
 def get_complete_position(self, context):
     # Check member prefix pattern.
     for prefix_pattern in convert2list(
             self.get_filetype_var(
                 context['filetype'], 'prefix_patterns')):
         m = re.search(self._object_pattern + prefix_pattern + r'\w*$',
                       context['input'])
         if m is None or prefix_pattern == '':
             continue
         self._prefix = re.sub(r'\w*$', '', m.group(0))
         return re.search(r'\w*$', context['input']).start()
     return -1
Пример #10
0
    def get_complete_position(self, context):
        if self.__use_previous_result(context):
            return self.__prev_pos

        for filetype in context['filetypes']:
            for omnifunc in convert2list(
                    get_buffer_config(context, filetype,
                                      'deoplete_omni_functions',
                                      'deoplete#omni#functions',
                                      {'_': ''})):
                if omnifunc == '':
                    omnifunc = context['omni__omnifunc']
                if omnifunc in ['', 'ccomplete#Complete',
                                'htmlcomplete#CompleteTags']:
                    continue
                self.__omnifunc = omnifunc
                for input_pattern in convert2list(
                    get_buffer_config(context, filetype,
                                      'deoplete_omni_input_patterns',
                                      'deoplete#omni#input_patterns',
                                      self.__input_patterns)):

                    m = re.search('(' + input_pattern + ')$', context['input'])
                    # self.debug(filetype)
                    # self.debug(input_pattern)
                    if input_pattern == '' or (context['event'] !=
                                               'Manual' and m is None):
                        continue

                    try:
                        complete_pos = self.vim.call(self.__omnifunc, 1, '')
                    except:
                        error(self.vim,
                              'Error occurred calling omnifunction: ' +
                              self.__omnifunc)
                        return -1
                    return complete_pos
        return -1
Пример #11
0
    def _get_complete_position(self, context: UserContext, current_ft: str,
                               filetype: str) -> int:
        complete_pos = -1

        for omnifunc in convert2list(
                self.get_filetype_var(filetype, 'functions')):
            if omnifunc == '' and (filetype == current_ft
                                   or filetype in ['css', 'javascript']):
                omnifunc = self.get_buf_option('omnifunc')
            if omnifunc == '':
                continue
            self._omnifunc = omnifunc
            for input_pattern in convert2list(
                    self.get_filetype_var(filetype, 'input_patterns')):

                m = re.search('(' + input_pattern + ')$', context['input'])
                # self.debug(filetype)
                # self.debug(input_pattern)
                if input_pattern == '' or (context['event'] != 'Manual'
                                           and m is None):
                    continue

                if self._omnifunc in [
                        'ccomplete#Complete', 'htmlcomplete#CompleteTags',
                        'LanguageClient#complete', 'rubycomplete#Complete',
                        'phpcomplete#CompletePHP'
                ]:
                    # In the blacklist
                    continue
                try:
                    complete_pos = int(self.vim.call(self._omnifunc, 1, ''))
                except Exception:
                    self.print_error('Error occurred calling omnifunction: ' +
                                     self._omnifunc)
                    return -1
                if complete_pos >= 0:
                    break
        return complete_pos
Пример #12
0
 def get_complete_position(self, context):
     # Check member prefix pattern.
     for prefix_pattern in convert2list(
             get_buffer_config(self.vim, context['filetype'],
                               'b:deoplete_member_prefix_patterns',
                               'g:deoplete#member#prefix_patterns',
                               'g:deoplete#member#_prefix_patterns')):
         m = re.search(self.__object_pattern + prefix_pattern + r'\w*$',
                       context['input'])
         if m is None or prefix_pattern == '':
             continue
         self.__prefix = re.sub(r'\w*$', '', m.group(0))
         return re.search(r'\w*$', context['input']).start()
     return -1
Пример #13
0
 def get_complete_position(self, context):
     # Check member prefix pattern.
     for prefix_pattern in convert2list(
             get_buffer_config(context, context['filetype'],
                               'deoplete_member_prefix_patterns',
                               'deoplete#member#prefix_patterns',
                               self.__prefix_patterns)):
         m = re.search(self.__object_pattern + prefix_pattern + r'\w*$',
                       context['input'])
         if m is None or prefix_pattern == '':
             continue
         self.__prefix = re.sub(r'\w*$', '', m.group(0))
         return re.search(r'\w*$', context['input']).start()
     return -1
Пример #14
0
 def get_complete_position(self, context: UserContext) -> int:
     # Check member prefix pattern.
     for prefix_pattern in convert2list(
             self.get_filetype_var(
                 context['filetype'], 'prefix_patterns')):
         m = re.search(self._object_pattern + prefix_pattern + r'\w*$',
                       context['input'])
         if m is None or prefix_pattern == '':
             continue
         self._prefix = re.sub(r'\w*$', '', m.group(0))
         m = re.search(r'\w*$', context['input'])
         if m:
             return m.start()
     return -1
Пример #15
0
    def _get_complete_position(self, context, current_ft, filetype):
        for omnifunc in convert2list(
                get_buffer_config(context, filetype, 'deoplete_omni_functions',
                                  'deoplete#omni#functions', {'_': ''})):
            if omnifunc == '' and (filetype == current_ft
                                   or filetype in ['css', 'javascript']):
                omnifunc = context['omni__omnifunc']
            if omnifunc == '':
                continue
            self.__omnifunc = omnifunc
            for input_pattern in convert2list(
                    get_buffer_config(context, filetype,
                                      'deoplete_omni_input_patterns',
                                      'deoplete#omni#input_patterns',
                                      self._input_patterns)):

                m = re.search('(' + input_pattern + ')$', context['input'])
                # self.debug(filetype)
                # self.debug(input_pattern)
                if input_pattern == '' or (context['event'] != 'Manual'
                                           and m is None):
                    continue

                if filetype == current_ft and self.__omnifunc in [
                        'ccomplete#Complete', 'htmlcomplete#CompleteTags',
                        'LanguageClient#complete', 'phpcomplete#CompletePHP'
                ]:
                    # In the blacklist
                    return -1
                try:
                    complete_pos = self.vim.call(self.__omnifunc, 1, '')
                except Exception as e:
                    self.print_error('Error occurred calling omnifunction: ' +
                                     self.__omnifunc)
                    return -1
                return complete_pos
        return -1
Пример #16
0
 def get_complete_position(self, context):
     # Check member prefix pattern.
     for prefix_pattern in convert2list(
         get_default_buffer_config(
             self.vim,
             context,
             "b:deoplete_member_prefix_patterns",
             "g:deoplete#member#prefix_patterns",
             "g:deoplete#member#_prefix_patterns",
         )
     ):
         m = re.search(self.object_pattern + prefix_pattern + r"\w*$", context["input"])
         if m is None or prefix_pattern == "":
             continue
         self.prefix = re.sub(r"\w*$", "", m.group(0))
         return re.search(r"\w*$", context["input"]).start()
     return -1
Пример #17
0
    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)")')
Пример #18
0
    def get_complete_position(self, context):
        if self.__use_previous_result(context):
            return self.__prev_pos

        for filetype in context['filetypes']:
            omnifunc = get_buffer_config(context, filetype,
                                         'deoplete_omni_functions',
                                         'deoplete#omni#functions',
                                         'deoplete#omni#_functions')
            if omnifunc == '':
                omnifunc = context['omni__omnifunc']
            if omnifunc == '' or [
                    x for x in
                ['ccomplete#Complete', 'htmlcomplete#CompleteTags']
                    if x == omnifunc
            ]:
                continue
            self.__omnifunc = omnifunc
            for input_pattern in convert2list(
                    get_buffer_config(context, filetype,
                                      'deoplete_omni_input_patterns',
                                      'deoplete#omni#input_patterns',
                                      'deoplete#omni#_input_patterns')):

                m = re.search('(' + input_pattern + ')$', context['input'])
                # self.debug(filetype)
                # self.debug(input_pattern)
                if input_pattern == '' or (context['event'] != 'Manual'
                                           and m is None):
                    continue

                try:
                    complete_pos = self.vim.call(self.__omnifunc, 1, '')
                except:
                    error(
                        self.vim, 'Error occurred calling omnifunction: ' +
                        self.__omnifunc)
                    return -1
                return complete_pos
        return -1
Пример #19
0
    def get_complete_position(self, context):
        # Check member prefix pattern.
        if self.vim.eval('&l:omnifunc') == '':
            return -1
        for input_pattern in convert2list(
            get_default_buffer_config(
                self.vim, context,
                'b:deoplete_omni_input_patterns',
                'g:deoplete#omni#input_patterns',
                'g:deoplete#omni#_input_patterns')):

            m = re.search('('+input_pattern+')$', context['input'])
            if m is None or input_pattern == '':
                continue

            pos = self.vim.eval('getpos(".")')
            try:
                complete_pos = self.vim.eval('call(&l:omnifunc, [1, ""])')
            except:
                self.vim.command(
                    'call deoplete#util#print_error('
                    + '"Error occurred calling omnifunction: "'
                    + '. &l:omnifunc)')

                return -1
            finally:
                if pos != self.vim.eval('getpos(".")'):
                    self.vim.command(
                        'call deoplete#util#print_error('
                        + '"omnifunction: "'
                        + '. &l:omnifunc . " moves cursor!")')
                    self.vim.command(
                        'call deoplete#util#print_error('
                        + '"Deoplete cannot support it in omni source. "'
                        + '. "You should use g:deoplete#omni_patterns.")')
            return complete_pos
        return -1