예제 #1
0
    def _itersource(self, context):
        filetypes = context['filetypes']
        ignore_sources = set(self._ignore_sources)
        for ft in filetypes:
            ignore_sources.update(
                self._vim.call('deoplete#custom#_get_filetype_option',
                               'ignore_sources', ft, []))

        for source_name, source in self._get_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
예제 #2
0
    def _itersource(self, context):
        filetypes = context['filetypes']
        ignore_sources = set(self._ignore_sources)
        for ft in filetypes:
            ignore_sources.update(
                self._vim.call('deoplete#custom#_get_filetype_option',
                               'ignore_sources', ft, []))

        for source_name, source in self._get_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 '
                              f'{source_name}: {exc}. Ignoring.')
                    else:
                        error_tb(self._vim, 'Error when loading source '
                                 f'{source_name}: {exc}. Ignoring.')
                    self._ignore_sources.append(source_name)
                    continue
                else:
                    source.is_initialized = True
            yield source_name, source
예제 #3
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
예제 #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: UserContext
                    ) -> typing.Generator[typing.Any, None, None]:
        filetypes = context['filetypes']
        ignore_sources = set(self._ignore_sources)
        for ft in filetypes:
            ignore_sources.update(
                self._vim.call('deoplete#custom#_get_filetype_option',
                               'ignore_sources', ft, []))

        for source_name, source in self._get_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: ' + source.name)  # type: ignore
                try:
                    context['vars'] = self._vim.vars
                    source.on_init(context)
                    context['vars'] = None
                except Exception as exc:
                    if isinstance(exc, SourceInitError):
                        error(self._vim, 'Error when loading source '
                              f'{source_name}: {exc}. Ignoring.')
                    else:
                        error_tb(self._vim, 'Error when loading source '
                                 f'{source_name}: {exc}. Ignoring.')
                    self._ignore_sources.append(source_name)
                    continue
                else:
                    source.is_initialized = True
            yield source_name, source
예제 #6
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
예제 #7
0
    def load_sources(self, context):
        # Load sources from runtimepath
        for path in find_rplugins(context, 'source'):
            name = os.path.splitext(os.path.basename(path))[0]
            if name in self.__sources:
                continue

            source = None

            try:
                Source = import_plugin(path, 'source', 'Source')
                if Source is None:
                    continue
                source = Source(self.__vim)
                source.name = getattr(source, 'name', name)

                source.min_pattern_length = getattr(
                    source, 'min_pattern_length',
                    context['vars']['deoplete#auto_complete_start_length'])
                source.max_abbr_width = getattr(
                    source, 'max_abbr_width',
                    context['vars']['deoplete#max_abbr_width'])
                source.max_menu_width = getattr(
                    source, 'max_menu_width',
                    context['vars']['deoplete#max_menu_width'])

                if hasattr(source, 'on_init'):
                    self.debug('on_init Source: %s', source.name)
                    source.on_init(context)
            except Exception:
                error_tb(self.__vim, 'Could not load source: %s' % name)
            finally:
                if source is not None:
                    self.__sources[source.name] = source
                    self.debug('Loaded Source: %s (%s)', source.name, path)

        self.set_source_attributes(context)
        self.__custom = context['custom']
예제 #8
0
    def _itersource(self, context):
        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 self._sources.items():
            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