forked from VimPlug/jedi
preload_module function for IDEs, to control which modules to load on startup, refs #102
This commit is contained in:
@@ -42,7 +42,8 @@ import sys
|
||||
# imports and circular imports... Just avoid it:
|
||||
sys.path.insert(0, __path__[0])
|
||||
|
||||
from .api import Script, NotFoundError, set_debug_function, _quick_complete
|
||||
from .api import Script, NotFoundError, set_debug_function, _quick_complete, \
|
||||
preload_module
|
||||
from . import settings
|
||||
|
||||
sys.path.pop(0)
|
||||
|
||||
12
jedi/api.py
12
jedi/api.py
@@ -522,6 +522,18 @@ def defined_names(source, source_path=None, source_encoding='utf-8'):
|
||||
return api_classes._defined_names(parser.scope)
|
||||
|
||||
|
||||
def preload_module(*modules):
|
||||
"""
|
||||
Preloading modules tells Jedi to load a module now, instead of lazy parsing
|
||||
of modules. Usful for IDEs, to control which modules to load on startup.
|
||||
|
||||
:param modules: different module names, list of string.
|
||||
"""
|
||||
for m in modules:
|
||||
s = "import %s as x; x." % m
|
||||
Script(s, 1, len(s), None).complete()
|
||||
|
||||
|
||||
def set_debug_function(func_cb=debug.print_to_stdout, warnings=True,
|
||||
notices=True, speed=True):
|
||||
"""
|
||||
|
||||
@@ -15,11 +15,9 @@ from .base import TestBase, unittest, cwd_at
|
||||
|
||||
import jedi
|
||||
from jedi._compatibility import utf8, unicode
|
||||
from jedi import api, parsing
|
||||
from jedi import api, parsing, common
|
||||
api_classes = api.api_classes
|
||||
|
||||
import pytest
|
||||
|
||||
#jedi.set_debug_function(jedi.debug.print_to_stdout)
|
||||
|
||||
|
||||
@@ -231,11 +229,9 @@ class TestRegression(TestBase):
|
||||
# jedi-vim #70
|
||||
s = """def foo("""
|
||||
assert self.function_definition(s) is None
|
||||
jedi.set_debug_function(jedi.debug.print_to_stdout)
|
||||
# jedi-vim #116
|
||||
s = """import functools; test = getattr(functools, 'partial'); test("""
|
||||
check(self.function_definition(s), 'partial', 0)
|
||||
jedi.set_debug_function(None)
|
||||
|
||||
def test_function_definition_empty_paren_pre_space(self):
|
||||
s = textwrap.dedent("""\
|
||||
@@ -437,6 +433,26 @@ class TestFeature(TestBase):
|
||||
any_re"""
|
||||
self.assertEqual(self.goto_definitions(s)[0].full_name, 're.RegexObject')
|
||||
|
||||
def test_preload_modules(self):
|
||||
def check_loaded(*modules):
|
||||
# + 1 for builtin, +1 for None module (currently used)
|
||||
assert len(new) == len(modules) + 2
|
||||
for i in modules + ('__builtin__',):
|
||||
assert [i in k for k in new.keys() if k is not None]
|
||||
|
||||
from jedi import cache
|
||||
temp_cache, cache.parser_cache = cache.parser_cache, {}
|
||||
new = cache.parser_cache
|
||||
with common.ignored(KeyError): # performance of tests -> no reload
|
||||
new['__builtin__'] = temp_cache['__builtin__']
|
||||
|
||||
jedi.preload_module('datetime')
|
||||
check_loaded('datetime')
|
||||
jedi.preload_module('json', 'token')
|
||||
check_loaded('datetime', 'json', 'token')
|
||||
|
||||
cache.parser_cache = temp_cache
|
||||
|
||||
def test_quick_completion(self):
|
||||
sources = [
|
||||
('import json; json.l', (1, 19)),
|
||||
|
||||
Reference in New Issue
Block a user