Esempio n. 1
0
    def load_sources(self, context):
        # Load sources from runtimepath
        rtps = globruntime(
            context['runtimepath'],
            'rplugin/python3/denite/source/base.py')
        rtps.extend(globruntime(context['runtimepath'],
                                'rplugin/python3/denite/source/*.py'))
        for path in rtps:
            name = os.path.basename(path)[: -3]
            module = importlib.machinery.SourceFileLoader(
                'denite.source.' + 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.matchers = get_custom_source(
                self.__custom, source.name,
                'matchers', source.matchers)
            source.sorters = get_custom_source(
                self.__custom, source.name,
                'sorters', source.sorters)
            source.converters = get_custom_source(
                self.__custom, source.name,
                'converters', source.converters)
            source.vars.update(
                get_custom_source(self.__custom, source.name,
                                  'vars', source.vars))

            self.__sources[source.name] = source
Esempio n. 2
0
    def on_init(self, context):
        self.__current_sources = []
        for [name, args] in [[x['name'], x['args']]
                             for x in context['sources']]:
            if name not in self.__sources:
                self.error('Source "' + name + '" is not found.')
                continue
            source = self.__sources[name]
            source.context = copy.deepcopy(context)
            source.context['args'] = args
            source.context['is_async'] = False
            source.context['all_candidates'] = []
            source.context['candidates'] = []

            # Set the source attributes.
            source.matchers = get_custom_source(
                self.__custom, source.name,
                'matchers', source.matchers)
            source.sorters = get_custom_source(
                self.__custom, source.name,
                'sorters', source.sorters)
            source.converters = get_custom_source(
                self.__custom, source.name,
                'converters', source.converters)
            source.vars.update(
                get_custom_source(self.__custom, source.name,
                                  'vars', source.vars))

            if hasattr(source, 'on_init'):
                source.on_init(source.context)
            self.__current_sources.append(source)
Esempio n. 3
0
    def on_init(self, context):
        self._current_sources = []
        index = 0
        for [name,
             args] in [[x['name'], x['args']] for x in context['sources']]:
            if name not in self._sources:
                raise NameError('Source "' + name + '" is not found.')

            source = copy.copy(self._sources[name])
            source.context = copy.copy(context)
            source.context['args'] = args
            source.context['is_async'] = False
            source.context['is_interactive'] = False
            source.context['all_candidates'] = []
            source.context['candidates'] = []
            source.index = index

            # Set the source attributes.
            source.matchers = get_custom_source(self._custom, source.name,
                                                'matchers', source.matchers)
            source.sorters = get_custom_source(self._custom, source.name,
                                               'sorters', source.sorters)
            source.converters = get_custom_source(self._custom, source.name,
                                                  'converters',
                                                  source.converters)
            source.vars.update(
                get_custom_source(self._custom, source.name, 'vars',
                                  source.vars))
            if not source.context['args']:
                source.context['args'] = get_custom_source(
                    self._custom, source.name, 'args', [])

            if hasattr(source, 'on_init'):
                source.on_init(source.context)
            self._current_sources.append(source)
            index += 1

        for filter in [
                x for x in self._filters.values()
                if x.vars and x.name in self._custom['filter']
        ]:
            filter.vars.update(self._custom['filter'][filter.name])
Esempio n. 4
0
    def on_init(self, context):
        self._current_sources = []
        index = 0
        for [name, args] in [[x['name'], x['args']]
                             for x in context['sources']]:
            if name not in self._sources:
                raise NameError('Source "' + name + '" is not found.')

            source = copy.copy(self._sources[name])
            source.context = copy.copy(context)
            source.context['args'] = args
            source.context['is_async'] = False
            source.context['is_skipped'] = False
            source.context['is_interactive'] = False
            source.context['all_candidates'] = []
            source.context['candidates'] = []
            source.context['prev_time'] = time.time()
            source.index = index

            # Set the source attributes.
            self._set_source_attribute(source, 'matchers')
            self._set_source_attribute(source, 'sorters')
            self._set_source_attribute(source, 'converters')
            self._set_source_attribute(source, 'max_candidates')
            source.vars.update(
                get_custom_source(self._custom, source.name,
                                  'vars', source.vars))
            if not source.context['args']:
                source.context['args'] = get_custom_source(
                    self._custom, source.name, 'args', [])

            if hasattr(source, 'on_init'):
                source.on_init(source.context)
            self._current_sources.append(source)
            index += 1

        for filter in [x for x in self._filters.values()
                       if x.vars and x.name in self._custom['filter']]:
            filter.vars.update(self._custom['filter'][filter.name])
Esempio n. 5
0
    def on_init(self, context):
        self.__current_sources = []
        for [name, args] in [[x['name'], x['args']]
                             for x in context['sources']]:
            if name not in self.__sources:
                self.error('Source "' + name + '" is not found.')
                continue
            source = self.__sources[name]
            source.context = copy.deepcopy(context)
            source.context['args'] = args
            source.context['is_async'] = False
            source.context['all_candidates'] = []
            source.context['candidates'] = []

            # Set the source attributes.
            source.matchers = get_custom_source(
                self.__custom, source.name,
                'matchers', source.matchers)
            source.sorters = get_custom_source(
                self.__custom, source.name,
                'sorters', source.sorters)
            source.converters = get_custom_source(
                self.__custom, source.name,
                'converters', source.converters)
            source.vars.update(
                get_custom_source(self.__custom, source.name,
                                  'vars', source.vars))
            if not source.context['args']:
                source.context['args'] = get_custom_source(
                    self.__custom, source.name, 'args', [])

            if hasattr(source, 'on_init'):
                source.on_init(source.context)
            self.__current_sources.append(source)

        for filter in [x for x in self.__filters.values()
                       if x.vars and x.name in self.__custom['filter']]:
            filter.vars.update(self.__custom['filter'][filter.name])
Esempio n. 6
0
 def _set_source_attribute(self, source, attr):
     source_attr = getattr(source, attr)
     setattr(
         source, attr,
         get_custom_source(self._custom, source.name, attr, source_attr))
Esempio n. 7
0
 def _set_source_attribute(self, source, attr):
     source_attr = getattr(source, attr)
     setattr(source, attr, get_custom_source(
         self._custom, source.name, attr, source_attr))