forked from VimPlug/jedi
moved another method away from dynamic
This commit is contained in:
@@ -745,7 +745,7 @@ def usages(evaluator, definitions, search_name, mods):
|
|||||||
compare_definitions = compare_array(definitions)
|
compare_definitions = compare_array(definitions)
|
||||||
mods |= set([d.get_parent_until() for d in definitions])
|
mods |= set([d.get_parent_until() for d in definitions])
|
||||||
names = []
|
names = []
|
||||||
for m in dynamic.get_directory_modules_for_name(mods, search_name):
|
for m in helpers.get_modules_containing_name(mods, search_name):
|
||||||
try:
|
try:
|
||||||
stmts = m.used_names[search_name]
|
stmts = m.used_names[search_name]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
|||||||
@@ -51,12 +51,9 @@ would check whether a flow has the form of ``if isinstance(a, type_or_tuple)``.
|
|||||||
Unfortunately every other thing is being ignored (e.g. a == '' would be easy to
|
Unfortunately every other thing is being ignored (e.g. a == '' would be easy to
|
||||||
check for -> a is a string). There's big potential in these checks.
|
check for -> a is a string). There's big potential in these checks.
|
||||||
"""
|
"""
|
||||||
import os
|
|
||||||
|
|
||||||
from jedi import cache
|
|
||||||
from jedi.common import source_to_unicode
|
|
||||||
from jedi.parser import representation as pr
|
from jedi.parser import representation as pr
|
||||||
from jedi import settings
|
from jedi import settings
|
||||||
|
from jedi.evaluate import helpers
|
||||||
from jedi.evaluate.cache import memoize_default
|
from jedi.evaluate.cache import memoize_default
|
||||||
|
|
||||||
# This is something like the sys.path, but only for searching params. It means
|
# This is something like the sys.path, but only for searching params. It means
|
||||||
@@ -64,50 +61,6 @@ from jedi.evaluate.cache import memoize_default
|
|||||||
search_param_modules = ['.']
|
search_param_modules = ['.']
|
||||||
|
|
||||||
|
|
||||||
def get_directory_modules_for_name(mods, name):
|
|
||||||
"""
|
|
||||||
Search a name in the directories of modules.
|
|
||||||
"""
|
|
||||||
def check_python_file(path):
|
|
||||||
try:
|
|
||||||
return cache.parser_cache[path].parser.module
|
|
||||||
except KeyError:
|
|
||||||
try:
|
|
||||||
return check_fs(path)
|
|
||||||
except IOError:
|
|
||||||
return None
|
|
||||||
|
|
||||||
def check_fs(path):
|
|
||||||
with open(path) as f:
|
|
||||||
source = source_to_unicode(f.read())
|
|
||||||
if name in source:
|
|
||||||
from jedi.evaluate import imports
|
|
||||||
return imports.load_module(path, source)
|
|
||||||
|
|
||||||
# skip non python modules
|
|
||||||
mods = set(m for m in mods if m.path is None or m.path.endswith('.py'))
|
|
||||||
mod_paths = set()
|
|
||||||
for m in mods:
|
|
||||||
mod_paths.add(m.path)
|
|
||||||
yield m
|
|
||||||
|
|
||||||
if settings.dynamic_params_for_other_modules:
|
|
||||||
paths = set(settings.additional_dynamic_modules)
|
|
||||||
for p in mod_paths:
|
|
||||||
if p is not None:
|
|
||||||
d = os.path.dirname(p)
|
|
||||||
for entry in os.listdir(d):
|
|
||||||
if entry not in mod_paths:
|
|
||||||
if entry.endswith('.py'):
|
|
||||||
paths.add(d + os.path.sep + entry)
|
|
||||||
|
|
||||||
for p in sorted(paths):
|
|
||||||
# make testing easier, sort it - same results on every interpreter
|
|
||||||
c = check_python_file(p)
|
|
||||||
if c is not None and c not in mods:
|
|
||||||
yield c
|
|
||||||
|
|
||||||
|
|
||||||
class ParamListener(object):
|
class ParamListener(object):
|
||||||
"""
|
"""
|
||||||
This listener is used to get the params for a function.
|
This listener is used to get the params for a function.
|
||||||
@@ -220,7 +173,7 @@ def search_params(evaluator, param):
|
|||||||
|
|
||||||
result = []
|
result = []
|
||||||
# This is like backtracking: Get the first possible result.
|
# This is like backtracking: Get the first possible result.
|
||||||
for mod in get_directory_modules_for_name([current_module], func_name):
|
for mod in helpers.get_modules_containing_name([current_module], func_name):
|
||||||
result = get_params_for_module(mod)
|
result = get_params_for_module(mod)
|
||||||
if result:
|
if result:
|
||||||
break
|
break
|
||||||
|
|||||||
@@ -1,9 +1,55 @@
|
|||||||
from __future__ import with_statement
|
import os
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
|
|
||||||
|
from jedi import cache
|
||||||
from jedi import common
|
from jedi import common
|
||||||
from jedi.parser import representation as pr
|
from jedi.parser import representation as pr
|
||||||
|
from jedi.common import source_to_unicode
|
||||||
|
from jedi import settings
|
||||||
|
|
||||||
|
|
||||||
|
def get_modules_containing_name(mods, name):
|
||||||
|
"""
|
||||||
|
Search a name in the directories of modules.
|
||||||
|
"""
|
||||||
|
def check_python_file(path):
|
||||||
|
try:
|
||||||
|
return cache.parser_cache[path].parser.module
|
||||||
|
except KeyError:
|
||||||
|
try:
|
||||||
|
return check_fs(path)
|
||||||
|
except IOError:
|
||||||
|
return None
|
||||||
|
|
||||||
|
def check_fs(path):
|
||||||
|
with open(path) as f:
|
||||||
|
source = source_to_unicode(f.read())
|
||||||
|
if name in source:
|
||||||
|
from jedi.evaluate import imports
|
||||||
|
return imports.load_module(path, source)
|
||||||
|
|
||||||
|
# skip non python modules
|
||||||
|
mods = set(m for m in mods if m.path is None or m.path.endswith('.py'))
|
||||||
|
mod_paths = set()
|
||||||
|
for m in mods:
|
||||||
|
mod_paths.add(m.path)
|
||||||
|
yield m
|
||||||
|
|
||||||
|
if settings.dynamic_params_for_other_modules:
|
||||||
|
paths = set(settings.additional_dynamic_modules)
|
||||||
|
for p in mod_paths:
|
||||||
|
if p is not None:
|
||||||
|
d = os.path.dirname(p)
|
||||||
|
for entry in os.listdir(d):
|
||||||
|
if entry not in mod_paths:
|
||||||
|
if entry.endswith('.py'):
|
||||||
|
paths.add(d + os.path.sep + entry)
|
||||||
|
|
||||||
|
for p in sorted(paths):
|
||||||
|
# make testing easier, sort it - same results on every interpreter
|
||||||
|
c = check_python_file(p)
|
||||||
|
if c is not None and c not in mods:
|
||||||
|
yield c
|
||||||
|
|
||||||
|
|
||||||
def fast_parent_copy(obj):
|
def fast_parent_copy(obj):
|
||||||
|
|||||||
Reference in New Issue
Block a user