forked from VimPlug/jedi
Move the stdlib executions into a plugin
This commit is contained in:
+10
-18
@@ -1,4 +1,4 @@
|
||||
from functools import partial
|
||||
from jedi.plugins.stdlib import StdlibPlugin
|
||||
|
||||
|
||||
class _PluginManager(object):
|
||||
@@ -21,23 +21,15 @@ class _PluginManager(object):
|
||||
|
||||
class _PluginCallbacks(object):
|
||||
def __init__(self, plugins):
|
||||
plugins = list(plugins)
|
||||
self.execute = self._wrap(plugins, 'execute')
|
||||
self._plugins = list(plugins)
|
||||
|
||||
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
|
||||
def decorate(self, name, callback):
|
||||
for plugin in reversed(self._plugins):
|
||||
# Need to reverse so the first plugin is run first.
|
||||
callback = getattr(plugin, name)(callback)
|
||||
return callback
|
||||
|
||||
|
||||
plugin_manager = _PluginManager()
|
||||
plugin_manager = _PluginManager([
|
||||
StdlibPlugin,
|
||||
])
|
||||
|
||||
@@ -6,5 +6,8 @@ class BasePlugin(object):
|
||||
# In __init__ you can do some caching.
|
||||
self._evaluator = evaluator
|
||||
|
||||
def execute(self, default_callback, arguments):
|
||||
return default_callback(arguments)
|
||||
def execute(self, callback):
|
||||
"""
|
||||
Decorates the execute(context, arguments) function.
|
||||
"""
|
||||
return callback
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
from jedi import debug
|
||||
from jedi.plugins.base import BasePlugin
|
||||
|
||||
|
||||
class StdlibPlugin(BasePlugin):
|
||||
def execute(self, callback):
|
||||
def wrapper(context, arguments):
|
||||
debug.dbg('execute: %s %s', context, arguments)
|
||||
from jedi.evaluate import stdlib
|
||||
try:
|
||||
# Some stdlib functions like super(), namedtuple(), etc. have been
|
||||
# hard-coded in Jedi to support them.
|
||||
return stdlib.execute(self._evaluator, context, arguments)
|
||||
except stdlib.NotInStdLib:
|
||||
pass
|
||||
return callback(context, arguments)
|
||||
|
||||
return wrapper
|
||||
Reference in New Issue
Block a user