forked from VimPlug/jedi
Add a plugin infrastructure
This commit is contained in:
@@ -108,6 +108,8 @@ class Evaluator(object):
|
|||||||
|
|
||||||
self.reset_recursion_limitations()
|
self.reset_recursion_limitations()
|
||||||
self.allow_different_encoding = True
|
self.allow_different_encoding = True
|
||||||
|
from jedi.plugins import plugin_manager
|
||||||
|
self.plugin_callbacks = plugin_manager.get_callbacks(self)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@evaluator_function_cache()
|
@evaluator_function_cache()
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ class Context(BaseContext):
|
|||||||
except stdlib.NotInStdLib:
|
except stdlib.NotInStdLib:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def default(arguments):
|
||||||
try:
|
try:
|
||||||
func = self.py__call__
|
func = self.py__call__
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
@@ -62,8 +63,7 @@ class Context(BaseContext):
|
|||||||
context_set = func(arguments)
|
context_set = func(arguments)
|
||||||
debug.dbg('execute result: %s in %s', context_set, self)
|
debug.dbg('execute result: %s in %s', context_set, self)
|
||||||
return context_set
|
return context_set
|
||||||
|
return self.evaluator.plugin_callbacks.execute(default, arguments)
|
||||||
return self.evaluator.execute(self, arguments)
|
|
||||||
|
|
||||||
def execute_evaluated(self, *value_list):
|
def execute_evaluated(self, *value_list):
|
||||||
"""
|
"""
|
||||||
|
|||||||
43
jedi/plugins/__init__.py
Normal file
43
jedi/plugins/__init__.py
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
from functools import partial
|
||||||
|
|
||||||
|
|
||||||
|
class _PluginManager(object):
|
||||||
|
def __init__(self, registered_plugin_classes=()):
|
||||||
|
self._registered_plugin_classes = list(registered_plugin_classes)
|
||||||
|
|
||||||
|
def register(self, plugin_class):
|
||||||
|
"""
|
||||||
|
Makes it possible to register your plugin.
|
||||||
|
"""
|
||||||
|
self._registered_plugins.append(plugin_class)
|
||||||
|
|
||||||
|
def _build_chain(self, evaluator):
|
||||||
|
for plugin_class in self._registered_plugin_classes:
|
||||||
|
yield plugin_class(evaluator)
|
||||||
|
|
||||||
|
def get_callbacks(self, evaluator):
|
||||||
|
return _PluginCallbacks(self._build_chain(evaluator))
|
||||||
|
|
||||||
|
|
||||||
|
class _PluginCallbacks(object):
|
||||||
|
def __init__(self, plugins):
|
||||||
|
plugins = list(plugins)
|
||||||
|
self.execute = self._wrap(plugins, 'execute')
|
||||||
|
|
||||||
|
def _wrap(self, plugins, name):
|
||||||
|
if not plugins:
|
||||||
|
def default_callback(callback, *args, **kwargs):
|
||||||
|
return callback(*args, **kwargs)
|
||||||
|
|
||||||
|
return default_callback
|
||||||
|
|
||||||
|
func = None
|
||||||
|
for plugin in plugins:
|
||||||
|
if func is None:
|
||||||
|
func = getattr(plugin, name)
|
||||||
|
else:
|
||||||
|
func = partial(getattr(plugin, name), func)
|
||||||
|
return func
|
||||||
|
|
||||||
|
|
||||||
|
plugin_manager = _PluginManager()
|
||||||
10
jedi/plugins/base.py
Normal file
10
jedi/plugins/base.py
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
class BasePlugin(object):
|
||||||
|
"""
|
||||||
|
Plugins are created each time an evaluator is created.
|
||||||
|
"""
|
||||||
|
def __init__(self, evaluator):
|
||||||
|
# In __init__ you can do some caching.
|
||||||
|
self._evaluator = evaluator
|
||||||
|
|
||||||
|
def execute(self, default_callback, arguments):
|
||||||
|
return default_callback(arguments)
|
||||||
Reference in New Issue
Block a user