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.context['prev_time'] = time.time() source.index = index # Set the source attributes. self._set_custom_attribute('source', source, 'matchers') self._set_custom_attribute('source', source, 'sorters') self._set_custom_attribute('source', source, 'converters') self._set_custom_attribute('source', source, 'max_candidates') self._set_custom_attribute('source', source, 'default_action') source.vars.update( get_custom(self._custom, 'source', source.name, 'vars', source.vars)) if not source.context['args']: source.context['args'] = get_custom(self._custom, 'source', 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])
def load_sources(self): # Load sources from runtimepath for path in globruntime( self.__vim, 'rplugin/python3/denite/source/base.py') + globruntime( self.__vim, 'rplugin/python3/denite/source/*.py'): 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(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
def _set_custom_attribute(self, kind: str, obj: typing.Any, attr: str) -> None: setattr( obj, attr, get_custom(self._custom, kind, obj.name, attr, getattr(obj, attr)))
def _set_custom_attribute(self, kind, obj, attr): setattr( obj, attr, get_custom(self._custom, kind, obj.name, attr, getattr(obj, attr)))