Skip to content

Commit 9498b38

Browse files
committed
host: more robust way of finding the script host
1 parent 27dbfce commit 9498b38

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

neovim/plugin/host.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from traceback import format_exc
1111

12+
from . import script_host
1213
from ..api import DecodeHook
1314
from ..compat import IS_PYTHON3, find_module
1415
from ..msgpack_rpc import ErrorResponse
@@ -105,15 +106,14 @@ def _load(self, plugins):
105106
if path in self._loaded:
106107
error('{0} is already loaded'.format(path))
107108
continue
108-
if path == "script_host.py":
109-
directory = os.path.dirname(__file__)
110-
name = "script_host"
111-
else:
112-
directory, name = os.path.split(os.path.splitext(path)[0])
113-
file, pathname, description = find_module(name, [directory])
114-
handlers = []
115109
try:
116-
module = imp.load_module(name, file, pathname, description)
110+
if path == "script_host.py":
111+
module = script_host
112+
else:
113+
directory, name = os.path.split(os.path.splitext(path)[0])
114+
file, pathname, descr = find_module(name, [directory])
115+
module = imp.load_module(name, file, pathname, descr)
116+
handlers = []
117117
self._discover_classes(module, handlers, path)
118118
self._discover_functions(module, handlers, path)
119119
if not handlers:

neovim/plugin/script_host.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
import os
66
import sys
77

8-
import neovim
8+
from .decorators import plugin, rpc_export
9+
from ..api import SessionHook
910

1011
__all__ = ('ScriptHost',)
1112

@@ -22,7 +23,7 @@
2223
from importlib.machinery import PathFinder
2324

2425

25-
@neovim.plugin
26+
@plugin
2627
class ScriptHost(object):
2728

2829
"""Provides an environment for running python plugins created for Vim."""
@@ -59,9 +60,6 @@ def setup(self, nvim):
5960

6061
def teardown(self):
6162
"""Restore state modified from the `setup` call."""
62-
for plugin in self.installed_plugins:
63-
if hasattr(plugin, 'on_teardown'):
64-
plugin.teardown()
6563
nvim = self.nvim
6664
info('uninstall import hook/path')
6765
sys.path.remove(nvim.VIM_SPECIAL_PATH)
@@ -70,21 +68,21 @@ def teardown(self):
7068
sys.stdout = self.saved_stdout
7169
sys.stderr = self.saved_stderr
7270

73-
@neovim.rpc_export('python_execute', sync=True)
71+
@rpc_export('python_execute', sync=True)
7472
def python_execute(self, script, range_start, range_stop):
7573
"""Handle the `python` ex command."""
7674
self._set_current_range(range_start, range_stop)
7775
exec(script, self.module.__dict__)
7876

79-
@neovim.rpc_export('python_execute_file', sync=True)
77+
@rpc_export('python_execute_file', sync=True)
8078
def python_execute_file(self, file_path, range_start, range_stop):
8179
"""Handle the `pyfile` ex command."""
8280
self._set_current_range(range_start, range_stop)
8381
with open(file_path) as f:
8482
script = compile(f.read(), file_path, 'exec')
8583
exec(script, self.module.__dict__)
8684

87-
@neovim.rpc_export('python_do_range', sync=True)
85+
@rpc_export('python_do_range', sync=True)
8886
def python_do_range(self, start, stop, code):
8987
"""Handle the `pydo` ex command."""
9088
self._set_current_range(start, stop)
@@ -142,7 +140,7 @@ def python_do_range(self, start, stop, code):
142140
# delete the function
143141
del self.module.__dict__[fname]
144142

145-
@neovim.rpc_export('python_eval', sync=True)
143+
@rpc_export('python_eval', sync=True)
146144
def python_eval(self, expr):
147145
"""Handle the `pyeval` vim function."""
148146
return eval(expr, self.module.__dict__)
@@ -163,7 +161,7 @@ def writelines(self, seq):
163161
self.redirect_handler('\n'.join(seq))
164162

165163

166-
class LegacyEvalHook(neovim.SessionHook):
164+
class LegacyEvalHook(SessionHook):
167165

168166
"""Injects legacy `vim.eval` behavior to a Nvim instance."""
169167

0 commit comments

Comments
 (0)