diff --git a/jedi/api/project.py b/jedi/api/project.py index dfcc7ff2..95c1ca23 100644 --- a/jedi/api/project.py +++ b/jedi/api/project.py @@ -328,7 +328,8 @@ class Project: ) # 2. Search for identifiers in the project. - for module_context in search_in_file_ios(inference_state, file_ios, name): + for module_context in search_in_file_ios(inference_state, file_ios, + name, complete=complete): names = get_module_names(module_context.tree_node, all_scopes=all_scopes) names = [module_context.create_name(n) for n in names] names = _remove_imports(names) diff --git a/jedi/inference/references.py b/jedi/inference/references.py index df47dabb..6ffa160e 100644 --- a/jedi/inference/references.py +++ b/jedi/inference/references.py @@ -282,12 +282,13 @@ def get_module_contexts_containing_name(inference_state, module_contexts, name, limit_reduction=limit_reduction) -def search_in_file_ios(inference_state, file_io_iterator, name, limit_reduction=1): +def search_in_file_ios(inference_state, file_io_iterator, name, + limit_reduction=1, complete=False): parse_limit = _PARSED_FILE_LIMIT / limit_reduction open_limit = _OPENED_FILE_LIMIT / limit_reduction file_io_count = 0 parsed_file_count = 0 - regex = re.compile(r'\b' + re.escape(name) + r'\b') + regex = re.compile(r'\b' + re.escape(name) + (r'' if complete else r'\b')) for file_io in file_io_iterator: file_io_count += 1 m = _check_fs(inference_state, file_io, regex) diff --git a/test/test_api/test_project.py b/test/test_api/test_project.py index 9ca4686c..f2a5e991 100644 --- a/test/test_api/test_project.py +++ b/test/test_api/test_project.py @@ -68,6 +68,10 @@ def test_load_save_project(tmpdir): dict(all_scopes=True)), ('some_search_test_var', ['test_api.test_project.test_search.some_search_test_var'], dict(complete=True, all_scopes=True)), + # Make sure that the searched name is not part of the file, by + # splitting it up. + ('some_search_test_v' + 'a', ['test_api.test_project.test_search.some_search_test_var'], + dict(complete=True, all_scopes=True)), ('sample_int', ['helpers.sample_int'], {}), ('sample_int', ['helpers.sample_int'], dict(all_scopes=True)), @@ -146,7 +150,7 @@ def test_search(string, full_names, kwargs): defs = project.complete_search(string, **kwargs) else: defs = project.search(string, **kwargs) - assert sorted([('stub:' if d.is_stub() else '') + d.full_name for d in defs]) == full_names + assert sorted([('stub:' if d.is_stub() else '') + (d.full_name or d.name) for d in defs]) == full_names @pytest.mark.parametrize(