Exemplo n.º 1
0
def test_custom():
    custom = {'source':{}}
    custom['source'] = {'_': {'mark': ''}, 'java': {'converters': []}}
    assert util.get_custom(custom, 'java', 'mark', 'foobar') == ''
    assert util.get_custom(custom, 'java', 'converters', 'foobar') == []
    assert util.get_custom(custom, 'foo', 'mark', 'foobar') == ''
    assert util.get_custom(custom, 'foo', 'converters', 'foobar') == 'foobar'
Exemplo n.º 2
0
def test_custom():
    custom = {'source': {}}
    custom['source'] = {'_': {'mark': ''}, 'java': {'converters': []}}
    assert util.get_custom(custom, 'java', 'mark', 'foobar') == ''
    assert util.get_custom(custom, 'java', 'converters', 'foobar') == []
    assert util.get_custom(custom, 'foo', 'mark', 'foobar') == ''
    assert util.get_custom(custom, 'foo', 'converters', 'foobar') == 'foobar'
Exemplo n.º 3
0
    def load_sources(self):
        # Load sources from runtimepath
        for path in globruntime(self.__vim, "rplugin/python3/deoplete/sources/base.py") + globruntime(
            self.__vim, "rplugin/python3/deoplete/sources/*.py"
        ):
            name = os.path.basename(path)[:-3]
            module = importlib.machinery.SourceFileLoader("deoplete.sources." + name, path).load_module()
            if not hasattr(module, "Source") or name in self.__sources:
                continue

            source = module.Source(self.__vim)

            # Set the source attributes.
            source.filetypes = get_custom(self.__vim, source.name).get("filetypes", source.filetypes)
            source.disabled_syntaxes = get_custom(self.__vim, source.name).get(
                "disabled_syntaxes", source.disabled_syntaxes
            )
            source.input_pattern = get_custom(self.__vim, source.name).get("input_pattern", source.input_pattern)
            source.min_pattern_length = get_custom(self.__vim, source.name).get(
                "min_pattern_length", source.min_pattern_length
            )
            source.max_pattern_length = get_custom(self.__vim, source.name).get(
                "max_pattern_length", source.max_pattern_length
            )
            source.matchers = get_custom(self.__vim, source.name).get("matchers", source.matchers)
            source.sorters = get_custom(self.__vim, source.name).get("sorters", source.sorters)
            source.converters = get_custom(self.__vim, source.name).get("converters", source.converters)

            self.__sources[source.name] = source
            self.debug("Loaded Source: %s (%s)", name, module.__file__)
Exemplo n.º 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)
                try:
                    source.on_init(context)
                except Exception as exc:
                    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
Exemplo n.º 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',
                                  {}))

        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
Exemplo n.º 6
0
    def _merge_results(self, context, queue_id):
        self.debug('merged_results: begin')
        results = self._gather_results(context)

        merged_results = []
        for result in [x for x in results
                       if not self._is_skip(x['context'], x['source'])]:
            source_result = self._source_result(result, context['input'])
            if source_result:
                rank = get_custom(self._custom,
                                  result['source'].name, 'rank',
                                  result['source'].rank)
                merged_results.append({
                    'complete_position': source_result['complete_position'],
                    'mark': result['source'].mark,
                    'dup': bool(result['source'].filetypes),
                    'candidates': result['candidates'],
                    'source_name': result['source'].name,
                    'rank': rank,
                })

        is_async = len([x for x in results if x['context']['is_async']]) > 0

        self.debug('merged_results: end')
        return {
            'queue_id': queue_id,
            'is_async': is_async,
            'merged_results': merged_results,
        }
Exemplo n.º 7
0
    def _set_source_attributes(self, context):
        """Set source attributes from the context.

        Each item in `attrs` is the attribute name.  If the default value is in
        context['vars'] under a different name, use a tuple.
        """
        attrs = (
            'filetypes',
            'disabled_syntaxes',
            'input_pattern',
            ('min_pattern_length', 'deoplete#auto_complete_start_length'),
            'max_pattern_length',
            ('max_abbr_width', 'deoplete#max_abbr_width'),
            ('max_kind_width', 'deoplete#max_menu_width'),
            ('max_menu_width', 'deoplete#max_menu_width'),
            'matchers',
            'sorters',
            'converters',
            'mark',
            'is_debug_enabled',
            'is_silent',
        )

        for name, source in self._sources.items():
            for attr in attrs:
                if isinstance(attr, tuple):
                    default_val = context['vars'][attr[1]]
                    attr = attr[0]
                else:
                    default_val = None
                source_attr = getattr(source, attr, default_val)
                setattr(source, attr, get_custom(context['custom'],
                                                 name, attr, source_attr))
Exemplo n.º 8
0
    def set_source_attributes(self, context):
        """Set source attributes from the context.

        Each item in `attrs` is the attribute name.  If the default value is in
        context['vars'] under a different name, use a tuple.
        """
        attrs = (
            'filetypes',
            'disabled_syntaxes',
            'input_pattern',
            ('min_pattern_length', 'deoplete#auto_complete_start_length'),
            'max_pattern_length',
            ('max_abbr_width', 'deoplete#max_abbr_width'),
            ('max_menu_width', 'deoplete#max_menu_width'),
            'matchers',
            'sorters',
            'converters',
            'mark',
            'debug_enabled',
        )

        for name, source in self._sources.items():
            for attr in attrs:
                if isinstance(attr, tuple):
                    default_val = context['vars'][attr[1]]
                    attr = attr[0]
                else:
                    default_val = None
                source_attr = getattr(source, attr, default_val)
                setattr(source, attr, get_custom(context['custom'], name,
                                                 attr, source_attr))
Exemplo n.º 9
0
    def _merge_results(self, context, queue_id):
        results = self._gather_results(context)

        merged_results = []
        for result in [
                x for x in results
                if not self._is_skip(x['context'], x['source'])
        ]:
            candidates = self._get_candidates(result, context['input'],
                                              context['next_input'])
            if candidates:
                rank = get_custom(context['custom'], result['source'].name,
                                  'rank', result['source'].rank)
                merged_results.append({
                    'complete_position':
                    result['complete_position'],
                    'candidates':
                    candidates,
                    'rank':
                    rank,
                })

        is_async = len([x for x in results if x['is_async']]) > 0

        return {
            'queue_id': queue_id,
            'is_async': is_async,
            'merged_results': merged_results,
        }
Exemplo n.º 10
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
Exemplo n.º 11
0
    def _merge_results(self, context, queue_id):
        results = self._gather_results(context)

        merged_results = []
        for result in [x for x in results
                       if not self._is_skip(x['context'], x['source'])]:
            candidates = self._get_candidates(
                result, context['input'], context['next_input'])
            if candidates:
                rank = get_custom(context['custom'],
                                  result['source'].name, 'rank',
                                  result['source'].rank)
                merged_results.append({
                    'complete_position': result['complete_position'],
                    'candidates': candidates,
                    'rank': rank,
                })

        is_async = len([x for x in results if x['is_async']]) > 0

        return {
            'queue_id': queue_id,
            'is_async': is_async,
            'merged_results': merged_results,
        }
Exemplo n.º 12
0
    def load_sources(self):
        # Load sources from runtimepath
        for path in globruntime(self.__vim,
                                'rplugin/python3/deoplete/sources/base.py'
                                ) + globruntime(
                                    self.__vim,
                                    'rplugin/python3/deoplete/sources/*.py'):
            name = os.path.basename(path)[: -3]
            module = importlib.machinery.SourceFileLoader(
                'deoplete.sources.' + name, path).load_module()
            if not hasattr(module, 'Source') or name in self.__sources:
                continue

            source = module.Source(self.__vim)

            # Set the source attributes.
            source.filetypes = get_custom(
                self.__vim, source.name).get(
                    'filetypes', source.filetypes)
            source.disabled_syntaxes = get_custom(
                self.__vim, source.name).get(
                    'disabled_syntaxes', source.disabled_syntaxes)
            source.input_pattern = get_custom(
                self.__vim, source.name).get(
                    'input_pattern', source.input_pattern)
            source.min_pattern_length = get_custom(
                self.__vim, source.name).get(
                    'min_pattern_length', source.min_pattern_length)
            source.max_pattern_length = get_custom(
                self.__vim, source.name).get(
                    'max_pattern_length', source.max_pattern_length)
            source.max_abbr_width = get_custom(
                self.__vim, source.name).get(
                    'max_abbr_width', source.max_abbr_width)
            source.max_menu_width = get_custom(
                self.__vim, source.name).get(
                    'max_menu_width', source.max_menu_width)
            source.matchers = get_custom(
                self.__vim, source.name).get('matchers', source.matchers)
            source.sorters = get_custom(self.__vim, source.name).get(
                'sorters', source.sorters)
            source.converters = get_custom(self.__vim, source.name).get(
                'converters', source.converters)

            self.__sources[source.name] = source
            self.debug('Loaded Source: %s (%s)', name, module.__file__)
Exemplo n.º 13
0
    def _set_source_attributes(self, context: UserContext) -> None:
        """Set source attributes from the context.

        Each item in `attrs` is the attribute name.
        """
        attrs = (
            'camel_case',
            'converters',
            'disabled_syntaxes',
            'dup',
            'filetypes',
            'ignore_case',
            'input_pattern',
            'input_patterns',
            'is_debug_enabled',
            'is_silent',
            'is_volatile',
            'mark',
            'matchers',
            'max_abbr_width',
            'max_candidates',
            'max_info_width',
            'max_kind_width',
            'max_menu_width',
            'max_pattern_length',
            'min_pattern_length',
            'smart_case',
            'sorters',
        )

        for name, source in self._get_sources().items():
            self.debug('Set Source attributes: %s', name)  # type: ignore

            source.dup = bool(source.filetypes)

            for attr in attrs:
                source_attr = getattr(source, attr, None)
                custom = get_custom(context['custom'], name, attr, source_attr)
                if type(getattr(source, attr)) != type(custom):
                    # Type check
                    error(
                        self._vim, f'source {source.name}: '
                        f'custom attr "{attr}" is wrong type.')
                elif custom and isinstance(source_attr, dict):
                    # Update values if it is dict
                    source_attr.update(custom)
                else:
                    setattr(source, attr, custom)

                self.debug(
                    'Attribute: %s (%s)',  # type: ignore
                    attr,
                    getattr(source, attr))

            # Default min_pattern_length
            if source.min_pattern_length < 0:
                source.min_pattern_length = self._vim.call(
                    'deoplete#custom#_get_option', 'min_pattern_length')
Exemplo n.º 14
0
    def _set_source_attributes(self, context):
        """Set source attributes from the context.

        Each item in `attrs` is the attribute name.
        """
        attrs = (
            'converters',
            'disabled_syntaxes',
            'dup',
            'filetypes',
            'input_pattern',
            'is_debug_enabled',
            'is_silent',
            'is_volatile',
            'mark',
            'matchers',
            'max_abbr_width',
            'max_candidates',
            'max_info_width',
            'max_kind_width',
            'max_menu_width',
            'max_pattern_length',
            'min_pattern_length',
            'sorters',
        )

        for name, source in self._get_sources().items():
            self.debug('Set Source attributes: %s', name)

            source.dup = bool(source.filetypes)

            for attr in attrs:
                source_attr = getattr(source, attr, None)
                custom = get_custom(context['custom'],
                                    name, attr, source_attr)
                if type(getattr(source, attr)) != type(custom):
                    # Type check
                    error(self._vim, f'source {source.name}: '
                          f'custom attr "{attr}" is wrong type.')
                elif custom and isinstance(source_attr, dict):
                    # Update values if it is dict
                    source_attr.update(custom)
                else:
                    setattr(source, attr, custom)

                self.debug('Attribute: %s (%s)', attr, getattr(source, attr))

            # Default min_pattern_length
            if source.min_pattern_length < 0:
                source.min_pattern_length = self._vim.call(
                    'deoplete#custom#_get_option', 'min_pattern_length')

            if not source.is_volatile:
                source.is_volatile = bool(source.filetypes)
Exemplo n.º 15
0
    def load_sources(self):
        # Load sources from runtimepath
        for path in globruntime(
                self.__vim,
                'rplugin/python3/deoplete/sources/base.py') + globruntime(
                    self.__vim, 'rplugin/python3/deoplete/sources/*.py'):
            name = os.path.basename(path)[:-3]
            module = importlib.machinery.SourceFileLoader(
                'deoplete.sources.' + name, path).load_module()
            if not hasattr(module, 'Source') or name in self.__sources:
                continue

            source = module.Source(self.__vim)

            # Set the source attributes.
            source.filetypes = get_custom(self.__vim, source.name).get(
                'filetypes', source.filetypes)
            source.disabled_syntaxes = get_custom(self.__vim, source.name).get(
                'disabled_syntaxes', source.disabled_syntaxes)
            source.input_pattern = get_custom(self.__vim, source.name).get(
                'input_pattern', source.input_pattern)
            source.min_pattern_length = get_custom(
                self.__vim, source.name).get('min_pattern_length',
                                             source.min_pattern_length)
            source.max_pattern_length = get_custom(
                self.__vim, source.name).get('max_pattern_length',
                                             source.max_pattern_length)
            source.max_abbr_width = get_custom(self.__vim, source.name).get(
                'max_abbr_width', source.max_abbr_width)
            source.max_menu_width = get_custom(self.__vim, source.name).get(
                'max_menu_width', source.max_menu_width)
            source.matchers = get_custom(self.__vim, source.name).get(
                'matchers', source.matchers)
            source.sorters = get_custom(self.__vim, source.name).get(
                'sorters', source.sorters)
            source.converters = get_custom(self.__vim, source.name).get(
                'converters', source.converters)

            self.__sources[source.name] = source
            self.debug('Loaded Source: %s (%s)', name, module.__file__)
Exemplo n.º 16
0
    def _set_source_attributes(self, context):
        """Set source attributes from the context.

        Each item in `attrs` is the attribute name.
        """
        attrs = (
            'converters',
            'disabled_syntaxes',
            'dup',
            'filetypes',
            'input_pattern',
            'is_debug_enabled',
            'is_silent',
            'is_volatile',
            'mark',
            'matchers',
            'max_abbr_width',
            'max_candidates',
            'max_kind_width',
            'max_menu_width',
            'max_pattern_length',
            'min_pattern_length',
            'sorters',
        )

        for name, source in self._get_sources().items():
            self.debug('Set Source attributes: %s', name)

            source.dup = bool(source.filetypes)

            for attr in attrs:
                source_attr = getattr(source, attr, None)
                custom = get_custom(context['custom'], name, attr, source_attr)
                if custom and isinstance(source_attr, dict):
                    # Update values if it is dict
                    source_attr.update(custom)
                else:
                    setattr(source, attr, custom)

                self.debug('Attribute: %s (%s)', attr, getattr(source, attr))

            # Default min_pattern_length
            if source.min_pattern_length < 0:
                source.min_pattern_length = self._vim.call(
                    'deoplete#custom#_get_option', 'min_pattern_length')

            if not source.is_volatile:
                source.is_volatile = bool(source.filetypes)
Exemplo n.º 17
0
 def __config(self, context):
     config = util.get_custom(context['custom'], 'm*******t', 'config', '')
     if config:
         try:
             with open(config) as search:
                 for line in search:
                     result = self.__cache_breaker.search(line)
                     if result is not None:
                         cache_breaker = result[1]
                     result = self.__prefix.search(line)
                     if result is not None:
                         prefix = result[1]
             if prefix and cache_breaker:
                 return (prefix, cache_breaker)
         except:
             pass
Exemplo n.º 18
0
 def __config(self, context):
     config = util.get_custom(context['custom'], 'm*******t', 'config', '')
     if config:
         try:
             with open(config) as search:
                 for line in search:
                     result = self.__cache_breaker.search(line)
                     if result is not None:
                         cache_breaker = result[1]
                     result = self.__prefix.search(line)
                     if result is not None:
                         prefix = result[1]
             if prefix and cache_breaker:
                 return (prefix, cache_breaker)
         except:
             pass
Exemplo n.º 19
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
Exemplo n.º 20
0
    def _set_source_attributes(self, context):
        """Set source attributes from the context.

        Each item in `attrs` is the attribute name.  If the default value is in
        context['vars'] under a different name, use a tuple.
        """
        attrs = (
            'converters',
            'disabled_syntaxes',
            'filetypes',
            'input_pattern',
            'is_debug_enabled',
            'is_silent',
            'keyword_patterns',
            'mark',
            'matchers',
            'max_abbr_width',
            'max_candidates',
            'max_kind_width',
            'max_menu_width',
            'max_pattern_length',
            'min_pattern_length',
            'sorters',
            'vars',
        )

        for name, source in self._sources.items():
            for attr in attrs:
                source_attr = getattr(source, attr, None)
                custom = get_custom(context['custom'], name, attr, source_attr)
                if custom and isinstance(source_attr, dict):
                    # Update values if it is dict
                    source_attr.update(custom)
                else:
                    setattr(source, attr, custom)

            # Default min_pattern_length
            if source.min_pattern_length < 0:
                source.min_pattern_length = self._vim.call(
                    'deoplete#custom#_get_option', 'min_pattern_length')

            if not source.is_volatile:
                source.is_volatile = bool(source.filetypes)
Exemplo n.º 21
0
    def _set_source_attributes(self, context):
        """Set source attributes from the context.

        Each item in `attrs` is the attribute name.
        """
        attrs = (
            'converters',
            'disabled_syntaxes',
            'filetypes',
            'input_pattern',
            'is_debug_enabled',
            'is_silent',
            'keyword_patterns',
            'mark',
            'matchers',
            'max_abbr_width',
            'max_candidates',
            'max_kind_width',
            'max_menu_width',
            'max_pattern_length',
            'min_pattern_length',
            'sorters',
        )

        for name, source in self._get_sources().items():
            for attr in attrs:
                source_attr = getattr(source, attr, None)
                custom = get_custom(context['custom'],
                                    name, attr, source_attr)
                if custom and isinstance(source_attr, dict):
                    # Update values if it is dict
                    source_attr.update(custom)
                else:
                    setattr(source, attr, custom)

            # Default min_pattern_length
            if source.min_pattern_length < 0:
                source.min_pattern_length = self._vim.call(
                    'deoplete#custom#_get_option', 'min_pattern_length')

            if not source.is_volatile:
                source.is_volatile = bool(source.filetypes)
Exemplo n.º 22
0
    def _merge_results(self, context, queue_id):
        self.debug('merged_results: begin')
        results = self._gather_results(context)

        merged_results = []
        for result in [
                x for x in results
                if not self._is_skip(x['context'], x['source'])
        ]:
            if self._update_result(result, context['input']):
                rank = get_custom(self._custom, result['source'].name, 'rank',
                                  result['source'].rank)
                dup = bool(result['source'].filetypes)
                candidates = result['candidates']
                # Note: cannot use set() for dict
                if dup:
                    # Remove duplicates
                    candidates = uniq_list_dict(candidates)
                merged_results.append({
                    'complete_position':
                    result['complete_position'],
                    'mark':
                    result['source'].mark,
                    'dup':
                    dup,
                    'candidates':
                    candidates,
                    'source_name':
                    result['source'].name,
                    'rank':
                    rank,
                })

        is_async = len([x for x in results if x['is_async']]) > 0

        self.debug('merged_results: end')
        return {
            'queue_id': queue_id,
            'is_async': is_async,
            'merged_results': merged_results,
        }
Exemplo n.º 23
0
 def __active(self, context):
     path = self.vim.call('expand', '%:p') or self.vim.call('getcwd')
     content = util.get_custom(context['custom'], 'm*******t', 'content',
                               '')
     return content and path.find(content) == 0
Exemplo n.º 24
0
 def set_source_attributes(self, context):
     for source in self.__sources.values():
         source.filetypes = get_custom(
             context['custom'], source.name,
             'filetypes', source.filetypes)
         source.disabled_syntaxes = get_custom(
             context['custom'], source.name,
             'disabled_syntaxes', source.disabled_syntaxes)
         source.input_pattern = get_custom(
             context['custom'], source.name,
             'input_pattern', source.input_pattern)
         source.min_pattern_length = get_custom(
             context['custom'], source.name,
             'min_pattern_length',
             getattr(source, 'min_pattern_length',
                     context['vars'][
                         'deoplete#auto_complete_start_length']))
         source.max_pattern_length = get_custom(
             context['custom'], source.name,
             'max_pattern_length', source.max_pattern_length)
         source.max_abbr_width = get_custom(
             context['custom'], source.name,
             'max_abbr_width',
             getattr(source, 'max_abbr_width',
                     context['vars']['deoplete#max_abbr_width']))
         source.max_menu_width = get_custom(
             context['custom'], source.name,
             'max_menu_width',
             getattr(source, 'max_menu_width',
                     context['vars']['deoplete#max_menu_width']))
         source.matchers = get_custom(
             context['custom'], source.name,
             'matchers', source.matchers)
         source.sorters = get_custom(
             context['custom'], source.name,
             'sorters', source.sorters)
         source.converters = get_custom(
             context['custom'], source.name,
             'converters', source.converters)
         source.mark = get_custom(
             context['custom'], source.name,
             'mark', source.mark)
         source.debug_enabled = get_custom(
             context['custom'], source.name,
             'debug_enabled', source.debug_enabled)
Exemplo n.º 25
0
 def test_custom(self):
     custom = {'_': {'mark': ''}, 'java': {'converters': []}}
     eq_(get_custom(custom, 'java', 'mark', 'foobar'), '')
     eq_(get_custom(custom, 'java', 'converters', 'foobar'), [])
     eq_(get_custom(custom, 'foo', 'mark', 'foobar'), '')
     eq_(get_custom(custom, 'foo', 'converters', 'foobar'), 'foobar')
Exemplo n.º 26
0
    def gather_results(self, context):
        # sources = ['buffer', 'neosnippet']
        # sources = ['buffer']
        sources = context['sources']
        results = []
        start_length = self.vim.eval(
            'g:deoplete#auto_completion_start_length')
        for source_name, source in sorted(self.sources.items(),
                key=lambda x: x[1].rank, reverse=True):
            if (sources and not source_name in sources) \
                    or (source.filetypes and
                        not context['filetype'] in source.filetypes):
                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 = source.min_pattern_length
            if min_pattern_length < 0:
                # Use default value
                min_pattern_length = start_length

            if charpos < 0 \
                    or (cont['event'] != 'Manual' \
                        and len(cont['complete_str']) < min_pattern_length):
                # Skip
                continue
            results.append({
                'name': source_name,
                'source': source,
                'context': cont,
            })

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

            context['candidates'] = source.gather_candidates(context)
            if context['candidates'] \
                    and type(context['candidates'][0]) == type(''):
                # Convert to dict
                context['candidates'] = \
                    [{ 'word': x } for x in context['candidates'] ]

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

            # self.debug(context['complete_str'])
            # self.debug(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)
            for filter_name in matchers + sorters + converters:
                if filter_name in self.filters:
                    context['candidates'] = \
                        self.filters[filter_name].filter(context)
            # self.debug(context['candidates'])

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

            # Set default menu
            for candidate in context['candidates']:
                candidate['menu'] = \
                    source.mark + ' ' + candidate.get('menu', '')
            # self.debug(context['candidates'])
        return results
Exemplo n.º 27
0
 def __active(self, context):
     path = self.vim.call('expand', '%:p') or self.vim.call('getcwd')
     content = util.get_custom(context['custom'], 'm*******t', 'content', '')
     return content and path.find(content) == 0
Exemplo n.º 28
0
    def load_sources(self, context):
        # Load sources from runtimepath
        for path in globruntime(
                context['runtimepath'],
                'rplugin/python3/deoplete/sources/base.py') + globruntime(
                    context['runtimepath'],
                    'rplugin/python3/deoplete/sources/*.py'):
            name = os.path.basename(path)[:-3]
            module = importlib.machinery.SourceFileLoader(
                'deoplete.sources.' + name, path).load_module()
            self.debug(path)
            if not hasattr(module, 'Source') or name in self.__sources:
                continue

            source = module.Source(self.__vim)

            # Set the source attributes.
            source.filetypes = get_custom(context['custom'], source.name,
                                          'filetypes', source.filetypes)
            source.disabled_syntaxes = get_custom(context['custom'],
                                                  source.name,
                                                  'disabled_syntaxes',
                                                  source.disabled_syntaxes)
            source.input_pattern = get_custom(context['custom'], source.name,
                                              'input_pattern',
                                              source.input_pattern)
            source.min_pattern_length = get_custom(
                context['custom'], source.name, 'min_pattern_length',
                getattr(
                    source, 'min_pattern_length',
                    context['vars']['deoplete#auto_complete_start_length']))
            source.max_pattern_length = get_custom(context['custom'],
                                                   source.name,
                                                   'max_pattern_length',
                                                   source.max_pattern_length)
            source.max_abbr_width = get_custom(
                context['custom'], source.name, 'max_abbr_width',
                getattr(source, 'max_abbr_width',
                        context['vars']['deoplete#max_abbr_width']))
            source.max_menu_width = get_custom(
                context['custom'], source.name, 'max_menu_width',
                getattr(source, 'max_menu_width',
                        context['vars']['deoplete#max_menu_width']))
            source.matchers = get_custom(context['custom'], source.name,
                                         'matchers', source.matchers)
            source.sorters = get_custom(context['custom'], source.name,
                                        'sorters', source.sorters)
            source.converters = get_custom(context['custom'], source.name,
                                           'converters', source.converters)
            source.mark = get_custom(context['custom'], source.name, 'mark',
                                     source.mark)
            source.debug_enabled = get_custom(context['custom'], source.name,
                                              'debug_enabled',
                                              source.debug_enabled)

            self.__sources[source.name] = source
            self.debug('Loaded Source: %s (%s)', name, module.__file__)
Exemplo n.º 29
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']
        for source_name, source in self.itersource(context, sources):
            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
Exemplo n.º 30
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
Exemplo n.º 31
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
Exemplo n.º 32
0
    def gather_results(self, context):
        # sources = ['buffer', 'neosnippet']
        # sources = ['buffer']
        sources = context['sources']
        results = []
        start_length = self.vim.eval('g:deoplete#auto_completion_start_length')
        for source_name, source in sorted(self.sources.items(),
                                          key=lambda x: x[1].rank,
                                          reverse=True):
            if (sources and source_name not in sources) or (
                    source.filetypes
                    and not context['filetype'] in source.filetypes):
                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)
            # debug(self.vim, source.rank)
            # debug(self.vim, source_name)
            # debug(self.vim, cont['input'])
            # debug(self.vim, charpos)
            # debug(self.vim, cont['complete_position'])
            # debug(self.vim, 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

            if charpos < 0 or (cont['event'] != 'Manual' and
                               len(cont['complete_str']) < min_pattern_length):
                # Skip
                continue
            results.append({
                'name': source_name,
                'source': source,
                'context': cont,
            })

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

            # debug(self.vim, 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
            # debug(self.vim, 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', '')
            # debug(self.vim, context['candidates'])
        return results
Exemplo n.º 33
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
Exemplo n.º 34
0
    def gather_results(self, context):
        # sources = ['buffer', 'neosnippet']
        # sources = ['buffer']
        sources = context["sources"]
        results = []
        start_length = self.vim.eval("g:deoplete#auto_completion_start_length")
        for source_name, source in sorted(self.sources.items(), key=lambda x: x[1].rank, reverse=True):
            if (sources and not source_name in sources) or (
                source.filetypes and not context["filetype"] in source.filetypes
            ):
                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)
            # debug(self.vim, source.rank)
            # debug(self.vim, source_name)
            # debug(self.vim, cont['input'])
            # debug(self.vim, charpos)
            # debug(self.vim, cont['complete_position'])
            # debug(self.vim, 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 (cont["event"] != "Manual" and len(cont["complete_str"]) < min_pattern_length):
                # Skip
                continue
            results.append({"name": source_name, "source": source, "context": cont})

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

            # debug(self.vim, source.name)
            context["candidates"] = source.gather_candidates(context)
            if context["candidates"] and type(context["candidates"][0]) == type(""):
                # 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
            # debug(self.vim, 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", "")
            # debug(self.vim, context['candidates'])
        return results