filter imported names during completion

This commit is contained in:
wutingjia
2024-10-15 20:15:58 +08:00
parent 8ee4c26ae4
commit d2bef68018

View File

@@ -65,12 +65,14 @@ def _must_be_kwarg(signatures, positional_count, used_kwargs):
return must_be_kwarg
def filter_names(inference_state, completion_names, stack, like_name, fuzzy, cached_name):
def filter_names(inference_state, completion_names, stack, like_name, fuzzy, imported_names, cached_name):
comp_dct = set()
if settings.case_insensitive_completion:
like_name = like_name.lower()
for name in completion_names:
string = name.string_name
if string in imported_names:
continue
if settings.case_insensitive_completion:
string = string.lower()
if helpers.match(string, like_name, fuzzy=fuzzy):
@@ -169,9 +171,15 @@ class Completion:
cached_name, completion_names = self._complete_python(leaf)
imported_names = []
if leaf.parent is not None and leaf.parent.type == 'import_as_names':
for child in leaf.parent.children:
if child.type == 'name':
imported_names.append(child.value)
completions = list(filter_names(self._inference_state, completion_names,
self.stack, self._like_name,
self._fuzzy, cached_name=cached_name))
self._fuzzy, imported_names, cached_name=cached_name))
return (
# Removing duplicates mostly to remove False/True/None duplicates.