예제 #1
0
파일: omni.py 프로젝트: tony/deoplete.nvim
    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
예제 #2
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
예제 #3
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
예제 #4
0
    def itersource(self, context):
        sources = sorted(self.__sources.items(),
                         key=lambda x: get_custom(
                             context['custom'],
                             x[1].name, 'rank', x[1].rank),
                         reverse=True)
        filetypes = context['filetypes']
        ignore_sources = set()
        for ft in filetypes:
            ignore_sources.update(
                get_buffer_config(context, ft,
                                  'deoplete_ignore_sources',
                                  'deoplete#ignore_sources',
                                  {}))

        for source_name, source in sources:
            if (source_name in ignore_sources):
                continue
            if context['sources'] and source_name not in context['sources']:
                continue
            if source.filetypes and not any(x in filetypes
                                            for x in source.filetypes):
                continue
            if not source.is_initialized and hasattr(source, 'on_init'):
                self.debug('on_init Source: %s', source.name)
                source.on_init(context)
                source.is_initialized = True

            yield source_name, source
예제 #5
0
    def itersource(self, context):
        sources = sorted(self.__sources.items(),
                         key=lambda x: get_custom(
                             context['custom'],
                             x[1].name, 'rank', x[1].rank),
                         reverse=True)
        filetypes = context['filetypes']
        ignore_sources = set()
        for ft in filetypes:
            ignore_sources.update(
                get_buffer_config(context, ft,
                                  'deoplete_ignore_sources',
                                  'deoplete#ignore_sources',
                                  'deoplete#_ignore_sources'))

        for source_name, source in sources:
            if (source_name in ignore_sources):
                continue
            if context['sources'] and source_name not in context['sources']:
                continue
            if source.filetypes and not any(x in filetypes
                                            for x in source.filetypes):
                continue

            yield source_name, source
예제 #6
0
파일: omni.py 프로젝트: holwech/nvim
    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
예제 #7
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(self.vim, filetype,
                                         'b:deoplete_omni_functions',
                                         'g:deoplete#omni#functions',
                                         'g:deoplete#omni#_functions')
            if omnifunc == '':
                omnifunc = self.vim.eval('&l: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(self.vim, filetype,
                                  'b:deoplete_omni_input_patterns',
                                  'g:deoplete#omni#input_patterns',
                                  'g: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
예제 #8
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
예제 #9
0
    def itersource(self, context):
        sources = sorted(self._sources.items(),
                         key=lambda x: get_custom(
                             context['custom'],
                             x[1].name, 'rank', x[1].rank),
                         reverse=True)
        filetypes = context['filetypes']
        ignore_sources = set()
        for ft in filetypes:
            ignore_sources.update(
                get_buffer_config(context, ft,
                                  'deoplete_ignore_sources',
                                  'deoplete#ignore_sources',
                                  {}))

        for source_name, source in sources:
            if source.limit > 0 and context['bufsize'] > source.limit:
                continue
            if source.filetypes is None or source_name in ignore_sources:
                continue
            if context['sources'] and source_name not in context['sources']:
                continue
            if source.filetypes and not any(x in filetypes
                                            for x in source.filetypes):
                continue
            if not source.is_initialized and hasattr(source, 'on_init'):
                self.debug('on_init Source: %s', source.name)
                try:
                    source.on_init(context)
                except Exception as exc:
                    if isinstance(exc, SourceInitError):
                        error(self._vim,
                              'Error when loading source {}: {}. '
                              'Ignoring.'.format(source_name, exc))
                    else:
                        error_tb(self._vim,
                                 'Error when loading source {}: {}. '
                                 'Ignoring.'.format(source_name, exc))
                    self._ignored_sources.add(source.path)
                    self._sources.pop(source_name)
                    continue
                else:
                    source.is_initialized = True
            yield source_name, source
예제 #10
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)")')
예제 #11
0
    def itersource(self, context, sources):
        filetypes = context['filetypes']
        ignore_sources = set()
        for ft in filetypes:
            ignore_sources.update(
                get_buffer_config(self.__vim, ft,
                                  'b:deoplete_ignore_sources',
                                  'g:deoplete#ignore_sources',
                                  '{}'))

        for source_name, source in sources:
            if (source_name in ignore_sources):
                continue
            if context['sources'] and source_name not in context['souces']:
                continue
            if source.filetypes and not any(x in filetypes
                                            for x in source.filetypes):
                continue

            yield source_name, source
예제 #12
0
    def gather_candidates(self, context):
        if self.__use_previous_result(context):
            return self.__prev_candidates

        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")
        try:
            self.debug(omnifunc)
            candidates = self.vim.call(omnifunc, 0, context["complete_str"])
        except:
            error(self.vim, "Error occurred calling omnifunction: " + omnifunc)
            candidates = []
        self.__prev_pos = context["complete_position"]
        self.__prev_input = context["input"]
        self.__prev_candidates = candidates

        return candidates
예제 #13
0
    def itersource(self, context):
        sources = sorted(self._sources.items(),
                         key=lambda x: get_custom(context['custom'], x[1].name,
                                                  'rank', x[1].rank),
                         reverse=True)
        filetypes = context['filetypes']
        ignore_sources = set()
        for ft in filetypes:
            ignore_sources.update(
                get_buffer_config(context, ft, 'deoplete_ignore_sources',
                                  'deoplete#ignore_sources', {}))

        for source_name, source in sources:
            if source.limit > 0 and context['bufsize'] > source.limit:
                continue
            if source.filetypes is None or source_name in ignore_sources:
                continue
            if context['sources'] and source_name not in context['sources']:
                continue
            if source.filetypes and not any(x in filetypes
                                            for x in source.filetypes):
                continue
            if not source.is_initialized and hasattr(source, 'on_init'):
                self.debug('on_init Source: %s', source.name)
                try:
                    source.on_init(context)
                except Exception as exc:
                    if isinstance(exc, SourceInitError):
                        error(
                            self._vim, 'Error when loading source {}: {}. '
                            'Ignoring.'.format(source_name, exc))
                    else:
                        error_tb(
                            self._vim, 'Error when loading source {}: {}. '
                            'Ignoring.'.format(source_name, exc))
                    self._sources.pop(source_name)
                    continue
                else:
                    source.is_initialized = True
            yield source_name, source
예제 #14
0
    def itersource(self, context):
        sources = sorted(self.__sources.items(),
                         key=lambda x: get_custom(context['custom'], x[1].name,
                                                  'rank', x[1].rank),
                         reverse=True)
        filetypes = context['filetypes']
        ignore_sources = set()
        for ft in filetypes:
            ignore_sources.update(
                get_buffer_config(context, ft, 'deoplete_ignore_sources',
                                  'deoplete#ignore_sources', {}))

        for source_name, source in sources:
            if (source_name in ignore_sources):
                continue
            if context['sources'] and source_name not in context['sources']:
                continue
            if source.filetypes and not any(x in filetypes
                                            for x in source.filetypes):
                continue

            yield source_name, source
예제 #15
0
    def gather_candidates(self, context):
        if self.__use_previous_result(context):
            return self.__prev_candidates

        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')
        try:
            self.debug(omnifunc)
            candidates = self.vim.call(
                omnifunc, 0, context['complete_str'])
        except:
            error(self.vim, 'Error occurred calling omnifunction: '
                  + omnifunc)
            candidates = []
        self.__prev_pos = context['complete_position']
        self.__prev_input = context['input']
        self.__prev_candidates = candidates

        return candidates
예제 #16
0
파일: omni.py 프로젝트: tony/deoplete.nvim
    def gather_candidates(self, context):
        if self.__use_previous_result(context):
            return self.__prev_candidates

        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')
        try:
            self.debug(omnifunc)
            candidates = self.vim.call(
                omnifunc, 0, context['complete_str'])
        except:
            error(self.vim, 'Error occurred calling omnifunction: '
                  + omnifunc)
            candidates = []
        self.__prev_linenr = self.vim.funcs.line('.')
        self.__prev_pos = context['complete_position']
        self.__prev_input = context['input']
        self.__prev_candidates = candidates

        return candidates
예제 #17
0
    def _itersource(self, context):
        filetypes = context['filetypes']
        ignore_sources = set(self._ignore_sources)
        for ft in filetypes:
            ignore_sources.update(
                get_buffer_config(context, ft,
                                  'deoplete_ignore_sources',
                                  'deoplete#ignore_sources',
                                  {}))

        for source_name, source in self._sources.items():
            if source.filetypes is None or source_name in ignore_sources:
                continue
            if context['sources'] and source_name not in context['sources']:
                continue
            if source.filetypes and not any(x in filetypes
                                            for x in source.filetypes):
                continue
            if not source.is_initialized and hasattr(source, 'on_init'):
                self.debug('on_init Source: %s', source.name)
                try:
                    source.on_init(context)
                except Exception as exc:
                    if isinstance(exc, SourceInitError):
                        error(self._vim,
                              'Error when loading source {}: {}. '
                              'Ignoring.'.format(source_name, exc))
                    else:
                        error_tb(self._vim,
                                 'Error when loading source {}: {}. '
                                 'Ignoring.'.format(source_name, exc))
                    self._ignore_sources.append(source_name)
                    continue
                else:
                    source.is_initialized = True
            yield source_name, source
예제 #18
0
    def gather_candidates(self, context):
        if self.__use_previous_result(context):
            return self.__prev_candidates

        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')
        try:
            candidates = self.vim.call(
                omnifunc, 0, context['complete_str'])
        except:
            error(self.vim, 'Error occurred calling omnifunction: '
                  + omnifunc)

            candidates = []
        self.__prev_pos = context['complete_position']
        self.__prev_line = self.vim.current.buffer[
            self.vim.current.window.cursor[0] - 1]
        self.__prev_candidates = candidates

        return candidates
예제 #19
0
    def gather_results(self, context):
        # sources = ['buffer', 'neosnippet']
        # sources = ['buffer']
        sources = sorted(self.__sources.items(),
                         key=lambda x: get_custom(self.__vim, x[1].name).get(
                             'rank', x[1].rank),
                         reverse=True)
        results = []
        start_length = self.__vim.vars['deoplete#auto_complete_start_length']
        ignore_sources = get_buffer_config(self.__vim, context['filetype'],
                                           'b:deoplete_ignore_sources',
                                           'g:deoplete#ignore_sources', '{}')
        for source_name, source in sources:
            filetypes = get_custom(self.__vim,
                                   source.name).get('filetypes',
                                                    source.filetypes)

            in_sources = not context['sources'] or (source_name
                                                    in context['sources'])
            in_fts = not filetypes or (context['filetype'] in filetypes)
            in_ignore = source_name in ignore_sources
            if not in_sources or not in_fts or in_ignore:
                continue
            disabled_syntaxes = get_custom(self.__vim, source.name).get(
                'disabled_syntaxes', source.disabled_syntaxes)
            if disabled_syntaxes and 'syntax_name' not in context:
                context['syntax_name'] = get_syn_name(self.__vim)
            cont = copy.deepcopy(context)
            charpos = source.get_complete_position(cont)
            if charpos >= 0 and source.is_bytepos:
                charpos = bytepos2charpos(self.__vim, cont['input'], charpos)
            cont['complete_str'] = cont['input'][charpos:]
            cont['complete_position'] = charpos2bytepos(
                self.__vim, cont['input'], charpos)
            # self.debug(source.rank)
            # self.debug(source_name)
            # self.debug(cont['input'])
            # self.debug(charpos)
            # self.debug(cont['complete_position'])
            # self.debug(cont['complete_str'])

            min_pattern_length = get_custom(self.__vim, source.name).get(
                'min_pattern_length', source.min_pattern_length)
            if min_pattern_length < 0:
                # Use default value
                min_pattern_length = start_length
            max_pattern_length = get_custom(self.__vim, source.name).get(
                'max_pattern_length', source.max_pattern_length)
            input_pattern = get_custom(self.__vim, source.name).get(
                'input_pattern', source.input_pattern)

            if charpos < 0 or self.is_skip(cont, disabled_syntaxes,
                                           min_pattern_length,
                                           max_pattern_length, input_pattern):
                # Skip
                continue
            results.append({
                'name': source_name,
                'source': source,
                'context': cont,
            })

        for result in results:
            context = result['context']
            source = result['source']

            # self.debug(source.name)
            self.profile_start(source.name)
            context['candidates'] = source.gather_candidates(context)
            self.profile_end(source.name)
            if context['candidates'] and isinstance(context['candidates'][0],
                                                    str):
                # Convert to dict
                context['candidates'] = [{
                    'word': x
                } for x in context['candidates']]

            matchers = get_custom(self.__vim,
                                  source.name).get('matchers', source.matchers)
            sorters = get_custom(self.__vim,
                                 source.name).get('sorters', source.sorters)
            converters = get_custom(self.__vim,
                                    source.name).get('converters',
                                                     source.converters)

            ignorecase = context['ignorecase']
            smartcase = context['smartcase']
            camelcase = context['camelcase']
            try:
                # Set ignorecase
                if (smartcase or camelcase) and re.search(
                        r'[A-Z]', context['complete_str']):
                    context['ignorecase'] = 0

                for filter in [
                        self.__filters[x]
                        for x in matchers + sorters + converters
                        if x in self.__filters
                ]:
                    self.profile_start(filter.name)
                    context['candidates'] = filter.filter(context)
                    self.profile_end(filter.name)
            finally:
                context['ignorecase'] = ignorecase
            # self.debug(context['candidates'])

            # On post filter
            if hasattr(source, 'on_post_filter'):
                context['candidates'] = source.on_post_filter(context)

            if context['candidates'] and not (re.match(
                    r'\[.*\]', context['candidates'][0].get('menu', ''))):
                # Set default menu
                for candidate in context['candidates']:
                    candidate['menu'] = source.mark + ' ' + candidate.get(
                        'menu', '')

            # self.debug(context['candidates'])
        return results
예제 #20
0
    def gather_results(self, context):
        # sources = ['buffer', 'neosnippet']
        # sources = ['buffer']
        sources = sorted(self.__sources.items(),
                         key=lambda x: get_custom(self.__vim, x[1].name).get(
                             'rank', x[1].rank),
                         reverse=True)
        results = []
        start_length = self.__vim.vars['deoplete#auto_complete_start_length']
        ignore_sources = get_buffer_config(
            self.__vim, context['filetype'],
            'b:deoplete_ignore_sources',
            'g:deoplete#ignore_sources',
            '{}')
        for source_name, source in sources:
            in_sources = not context['sources'] or (
                source_name in context['sources'])
            in_fts = not source.filetypes or (
                context['filetype'] in source.filetypes)
            in_ignore = source_name in ignore_sources
            if not in_sources or not in_fts or in_ignore:
                continue
            if source.disabled_syntaxes and 'syntax_name' not in context:
                context['syntax_name'] = get_syn_name(self.__vim)
            cont = copy.deepcopy(context)
            charpos = source.get_complete_position(cont)
            if charpos >= 0 and source.is_bytepos:
                charpos = bytepos2charpos(
                    self.__vim, cont['input'], charpos)
            cont['complete_str'] = cont['input'][charpos:]
            cont['complete_position'] = charpos2bytepos(
                self.__vim, cont['input'], charpos)
            cont['max_abbr_width'] = min(source.max_abbr_width,
                                         cont['max_abbr_width'])
            cont['max_menu_width'] = min(source.max_menu_width,
                                         cont['max_menu_width'])
            if cont['max_abbr_width'] > 0:
                cont['max_abbr_width'] = max(20, cont['max_abbr_width'])
            if cont['max_menu_width'] > 0:
                cont['max_menu_width'] = max(10, cont['max_menu_width'])
            # self.debug(source.rank)
            # self.debug(source_name)
            # self.debug(cont['input'])
            # self.debug(charpos)
            # self.debug(cont['complete_position'])
            # self.debug(cont['complete_str'])

            min_pattern_length = source.min_pattern_length
            if min_pattern_length < 0:
                # Use default value
                min_pattern_length = start_length

            if charpos < 0 or self.is_skip(cont, source.disabled_syntaxes,
                                           min_pattern_length,
                                           source.max_pattern_length,
                                           source.input_pattern):
                # Skip
                continue
            results.append({
                'name': source_name,
                'source': source,
                'context': cont,
            })

        for result in results:
            context = result['context']
            source = result['source']

            # self.debug(source.name)
            self.profile_start(source.name)
            context['candidates'] = source.gather_candidates(context)
            self.profile_end(source.name)
            if context['candidates'] and isinstance(
                    context['candidates'][0], str):
                # Convert to dict
                context['candidates'] = [{'word': x}
                                         for x in context['candidates']]

            ignorecase = context['ignorecase']
            smartcase = context['smartcase']
            camelcase = context['camelcase']
            try:
                # Set ignorecase
                if (smartcase or camelcase) and re.search(
                        r'[A-Z]', context['complete_str']):
                    context['ignorecase'] = 0

                for filter in [self.__filters[x] for x
                               in source.matchers +
                               source.sorters +
                               source.converters
                               if x in self.__filters]:
                    self.profile_start(filter.name)
                    context['candidates'] = filter.filter(context)
                    self.profile_end(filter.name)
            finally:
                context['ignorecase'] = ignorecase
            # self.debug(context['candidates'])

            # On post filter
            if hasattr(source, 'on_post_filter'):
                context['candidates'] = source.on_post_filter(context)

            if context['candidates'] and not (
                    re.match(r'\[.*\]',
                             context['candidates'][0].get('menu', ''))):
                # Set default menu
                for candidate in context['candidates']:
                    candidate['menu'] = source.mark + ' ' + candidate.get(
                        'menu', '')

            # self.debug(context['candidates'])
        return results
예제 #21
0
    def gather_results(self, context):
        # sources = ['buffer', 'neosnippet']
        # sources = ['buffer']
        sources = sorted(self.sources.items(),
                         key=lambda x: get_custom(self.vim, x[1].name).get(
                             'rank', x[1].rank),
                         reverse=True)
        results = []
        start_length = self.vim.eval(
            'g:deoplete#auto_completion_start_length')
        ignore_sources = get_buffer_config(
            self.vim, context['filetype'],
            'b:deoplete_ignore_sources',
            'g:deoplete#ignore_sources',
            '{}')
        for source_name, source in sources:
            filetypes = get_custom(self.vim, source.name).get(
                'filetypes', source.filetypes)

            in_sources = not context['sources'] or (
                source_name in context['sources'])
            in_fts = not filetypes or (
                context['filetype'] in filetypes)
            in_ignore = source_name in ignore_sources
            if not in_sources or not in_fts or in_ignore:
                continue
            cont = copy.deepcopy(context)
            charpos = source.get_complete_position(cont)
            if charpos >= 0 and source.is_bytepos:
                charpos = bytepos2charpos(
                    self.vim, cont['input'], charpos)
            cont['complete_str'] = cont['input'][charpos:]
            cont['complete_position'] = charpos2bytepos(
                self.vim, cont['input'], charpos)
            # self.debug(source.rank)
            # self.debug(source_name)
            # self.debug(cont['input'])
            # self.debug(charpos)
            # self.debug(cont['complete_position'])
            # self.debug(cont['complete_str'])

            min_pattern_length = get_custom(self.vim, source.name).get(
                'min_pattern_length', source.min_pattern_length)
            if min_pattern_length < 0:
                # Use default value
                min_pattern_length = start_length
            input_pattern = get_custom(self.vim, source.name).get(
                'input_pattern', source.input_pattern)

            if charpos < 0 or self.is_skip(cont,
                                           min_pattern_length,
                                           input_pattern):
                # Skip
                continue
            results.append({
                'name': source_name,
                'source': source,
                'context': cont,
            })

        for result in results:
            context = result['context']
            source = result['source']

            # self.debug(source.name)
            context['candidates'] = source.gather_candidates(context)
            if context['candidates'] and isinstance(
                    context['candidates'][0], str):
                # Convert to dict
                context['candidates'] = [{'word': x}
                                         for x in context['candidates']]

            matchers = get_custom(self.vim, source.name).get(
                'matchers', source.matchers)
            sorters = get_custom(self.vim, source.name).get(
                'sorters', source.sorters)
            converters = get_custom(self.vim, source.name).get(
                'converters', source.converters)

            ignorecase = context['ignorecase']
            try:
                # Set ignorecase
                if context['smartcase'] and re.match(r'[A-Z]',
                                                     context['complete_str']):
                    context['ignorecase'] = 0

                for filter_name in matchers + sorters + converters:
                    if filter_name in self.filters:
                        context['candidates'] = self.filters[
                            filter_name].filter(context)
            finally:
                context['ignorecase'] = ignorecase
            # self.debug(context['candidates'])

            # On post filter
            if hasattr(source, 'on_post_filter'):
                context['candidates'] = source.on_post_filter(context)

            if context['candidates'] and (
                    not re.match(r'\[.*\]',
                                 context['candidates'][0].get('menu', ''))):
                # Set default menu
                for candidate in context['candidates']:
                    candidate['menu'] = source.mark + ' ' + candidate.get(
                        'menu', '')

            # Set icase
            for candidate in context['candidates']:
                candidate['icase'] = 1
            # self.debug(context['candidates'])
        return results
예제 #22
0
    def gather_results(self, context):
        # sources = ['buffer', 'neosnippet']
        # sources = ['buffer']
        sources = sorted(
            self.__sources.items(), key=lambda x: get_custom(self.__vim, x[1].name).get("rank", x[1].rank), reverse=True
        )
        results = []
        start_length = self.__vim.vars["deoplete#auto_complete_start_length"]
        ignore_sources = get_buffer_config(
            self.__vim, context["filetype"], "b:deoplete_ignore_sources", "g:deoplete#ignore_sources", "{}"
        )
        for source_name, source in sources:
            in_sources = not context["sources"] or (source_name in context["sources"])
            in_fts = not source.filetypes or (context["filetype"] in source.filetypes)
            in_ignore = source_name in ignore_sources
            if not in_sources or not in_fts or in_ignore:
                continue
            if source.disabled_syntaxes and "syntax_name" not in context:
                context["syntax_name"] = get_syn_name(self.__vim)
            cont = copy.deepcopy(context)
            charpos = source.get_complete_position(cont)
            if charpos >= 0 and source.is_bytepos:
                charpos = bytepos2charpos(self.__vim, cont["input"], charpos)
            cont["complete_str"] = cont["input"][charpos:]
            cont["complete_position"] = charpos2bytepos(self.__vim, cont["input"], charpos)
            # self.debug(source.rank)
            # self.debug(source_name)
            # self.debug(cont['input'])
            # self.debug(charpos)
            # self.debug(cont['complete_position'])
            # self.debug(cont['complete_str'])

            min_pattern_length = source.min_pattern_length
            if min_pattern_length < 0:
                # Use default value
                min_pattern_length = start_length

            if charpos < 0 or self.is_skip(
                cont, source.disabled_syntaxes, min_pattern_length, source.max_pattern_length, source.input_pattern
            ):
                # Skip
                continue
            results.append({"name": source_name, "source": source, "context": cont})

        for result in results:
            context = result["context"]
            source = result["source"]

            # self.debug(source.name)
            self.profile_start(source.name)
            context["candidates"] = source.gather_candidates(context)
            self.profile_end(source.name)
            if context["candidates"] and isinstance(context["candidates"][0], str):
                # Convert to dict
                context["candidates"] = [{"word": x} for x in context["candidates"]]

            ignorecase = context["ignorecase"]
            smartcase = context["smartcase"]
            camelcase = context["camelcase"]
            try:
                # Set ignorecase
                if (smartcase or camelcase) and re.search(r"[A-Z]", context["complete_str"]):
                    context["ignorecase"] = 0

                for filter in [
                    self.__filters[x]
                    for x in source.matchers + source.sorters + source.converters
                    if x in self.__filters
                ]:
                    self.profile_start(filter.name)
                    context["candidates"] = filter.filter(context)
                    self.profile_end(filter.name)
            finally:
                context["ignorecase"] = ignorecase
            # self.debug(context['candidates'])

            # On post filter
            if hasattr(source, "on_post_filter"):
                context["candidates"] = source.on_post_filter(context)

            if context["candidates"] and not (re.match(r"\[.*\]", context["candidates"][0].get("menu", ""))):
                # Set default menu
                for candidate in context["candidates"]:
                    candidate["menu"] = source.mark + " " + candidate.get("menu", "")

            # self.debug(context['candidates'])
        return results