mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 06:44:46 +08:00
Make sure to not scan the same directory multiple times
This commit is contained in:
@@ -194,7 +194,6 @@ def _recurse_find_python_files(folder_io, except_paths):
|
|||||||
ignored_paths, ignored_names = \
|
ignored_paths, ignored_names = \
|
||||||
gitignored_lines(root_folder_io, file_io)
|
gitignored_lines(root_folder_io, file_io)
|
||||||
except_paths |= ignored_paths
|
except_paths |= ignored_paths
|
||||||
print(folder_io.path, ignored_paths)
|
|
||||||
|
|
||||||
folder_ios[:] = [
|
folder_ios[:] = [
|
||||||
folder_io
|
folder_io
|
||||||
@@ -204,14 +203,22 @@ def _recurse_find_python_files(folder_io, except_paths):
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def _find_python_files_in_sys_path(inference_state, folder_io):
|
def _find_python_files_in_sys_path(inference_state, module_contexts):
|
||||||
sys_path = inference_state.get_sys_path()
|
sys_path = inference_state.get_sys_path()
|
||||||
except_paths = set()
|
except_paths = set()
|
||||||
|
yielded_paths = [m.py__file__() for m in module_contexts]
|
||||||
|
for module_context in module_contexts:
|
||||||
|
file_io = module_context.get_value().file_io
|
||||||
|
if file_io is None:
|
||||||
|
continue
|
||||||
|
|
||||||
|
folder_io = file_io.get_parent_folder()
|
||||||
while True:
|
while True:
|
||||||
path = folder_io.path
|
path = folder_io.path
|
||||||
if not any(path.startswith(p) for p in sys_path):
|
if not any(path.startswith(p) for p in sys_path) or path in except_paths:
|
||||||
break
|
break
|
||||||
for file_io in _recurse_find_python_files(folder_io, except_paths):
|
for file_io in _recurse_find_python_files(folder_io, except_paths):
|
||||||
|
if file_io.path not in yielded_paths:
|
||||||
yield file_io
|
yield file_io
|
||||||
except_paths.add(path)
|
except_paths.add(path)
|
||||||
folder_io = folder_io.get_parent_folder()
|
folder_io = folder_io.get_parent_folder()
|
||||||
@@ -221,30 +228,20 @@ def get_module_contexts_containing_name(inference_state, module_contexts, name):
|
|||||||
"""
|
"""
|
||||||
Search a name in the directories of modules.
|
Search a name in the directories of modules.
|
||||||
"""
|
"""
|
||||||
def iter_file_ios():
|
|
||||||
yielded_paths = [m.py__file__() for m in module_contexts]
|
|
||||||
for module_context in module_contexts:
|
|
||||||
file_io = module_context.get_value().file_io
|
|
||||||
if file_io is None:
|
|
||||||
continue
|
|
||||||
|
|
||||||
folder_io = file_io.get_parent_folder()
|
|
||||||
for file_io in _find_python_files_in_sys_path(inference_state, folder_io):
|
|
||||||
if file_io.path not in yielded_paths:
|
|
||||||
yield file_io
|
|
||||||
|
|
||||||
# Skip non python modules
|
# Skip non python modules
|
||||||
for module_context in module_contexts:
|
for module_context in module_contexts:
|
||||||
if module_context.is_compiled():
|
if module_context.is_compiled():
|
||||||
continue
|
continue
|
||||||
yield module_context
|
yield module_context
|
||||||
|
|
||||||
|
# Very short names are not searched in other modules for now to avoid lots
|
||||||
|
# of file lookups.
|
||||||
if len(name) <= 2:
|
if len(name) <= 2:
|
||||||
return
|
return
|
||||||
|
|
||||||
file_io_count = 0
|
file_io_count = 0
|
||||||
regex = re.compile(r'\b' + re.escape(name) + r'\b')
|
regex = re.compile(r'\b' + re.escape(name) + r'\b')
|
||||||
for file_io in iter_file_ios():
|
for file_io in _find_python_files_in_sys_path(inference_state, module_contexts):
|
||||||
file_io_count += 1
|
file_io_count += 1
|
||||||
m = _check_fs(inference_state, file_io, regex)
|
m = _check_fs(inference_state, file_io, regex)
|
||||||
if m is not None:
|
if m is not None:
|
||||||
|
|||||||
Reference in New Issue
Block a user