1
0
forked from VimPlug/jedi

Move the filter search to a different place

This commit is contained in:
Dave Halter
2019-08-23 16:29:13 +02:00
parent ead0964282
commit 3fcecb3d6d
2 changed files with 15 additions and 18 deletions

View File

@@ -8,7 +8,7 @@ just one.
""" """
from functools import reduce from functools import reduce
from operator import add from operator import add
from parso.python.tree import ExprStmt, SyncCompFor from parso.python.tree import ExprStmt, SyncCompFor, Name
from jedi import debug from jedi import debug
from jedi._compatibility import zip_longest, unicode from jedi._compatibility import zip_longest, unicode
@@ -58,6 +58,17 @@ class HelperValueMixin(object):
for lazy_value in self.iterate(contextualized_node, is_async) for lazy_value in self.iterate(contextualized_node, is_async)
) )
def _get_value_filters(self, name_or_str):
origin_scope = name_or_str if isinstance(name_or_str, Name) else None
for f in self.get_filters(origin_scope=origin_scope):
yield f
# This covers the case where a stub files are incomplete.
if self.is_stub():
from jedi.inference.gradual.conversion import convert_values
for c in convert_values(ValueSet({self})):
for f in c.get_filters():
yield f
def py__getattribute__(self, name_or_str, name_context=None, position=None, def py__getattribute__(self, name_or_str, name_context=None, position=None,
analysis_errors=True): analysis_errors=True):
""" """
@@ -68,7 +79,7 @@ class HelperValueMixin(object):
from jedi.inference import finder from jedi.inference import finder
f = finder.NameFinder(self.inference_state, self, name_context, name_or_str, f = finder.NameFinder(self.inference_state, self, name_context, name_or_str,
position, analysis_errors=analysis_errors) position, analysis_errors=analysis_errors)
filters = f.get_value_filters() filters = self._get_value_filters(name_or_str)
return f.find(filters, attribute_lookup=True) return f.find(filters, attribute_lookup=True)
def goto(self, name_or_str, name_context=None, analysis_errors=True): def goto(self, name_or_str, name_context=None, analysis_errors=True):
@@ -80,7 +91,7 @@ class HelperValueMixin(object):
from jedi.inference import finder from jedi.inference import finder
f = finder.NameFinder(self.inference_state, self, name_context, name_or_str, f = finder.NameFinder(self.inference_state, self, name_context, name_or_str,
analysis_errors=analysis_errors) analysis_errors=analysis_errors)
filters = f.get_value_filters() filters = self._get_value_filters(name_or_str)
return f.filter_name(filters) return f.filter_name(filters)
def py__await__(self): def py__await__(self):

View File

@@ -29,7 +29,6 @@ from jedi.inference.filters import get_global_filters
from jedi.inference.names import TreeNameDefinition from jedi.inference.names import TreeNameDefinition
from jedi.inference.base_value import ValueSet, NO_VALUES from jedi.inference.base_value import ValueSet, NO_VALUES
from jedi.parser_utils import is_scope, get_parent_scope from jedi.parser_utils import is_scope, get_parent_scope
from jedi.inference.gradual.conversion import convert_values
class NameFinder(object): class NameFinder(object):
@@ -80,11 +79,8 @@ class NameFinder(object):
return types return types
def _get_origin_scope(self):
return self._name if isinstance(self._name, tree.Name) else None
def get_global_filters(self): def get_global_filters(self):
origin_scope = self._get_origin_scope() origin_scope = self._name if isinstance(self._name, tree.Name) else None
position = self._position position = self._position
# For functions and classes the defaults don't belong to the # For functions and classes the defaults don't belong to the
@@ -106,16 +102,6 @@ class NameFinder(object):
return get_global_filters(self._inference_state, self._context, position, origin_scope) return get_global_filters(self._inference_state, self._context, position, origin_scope)
def get_value_filters(self):
origin_scope = self._get_origin_scope()
for f in self._context.get_filters(origin_scope=origin_scope):
yield f
# This covers the case where a stub files are incomplete.
if self._context.is_stub():
for c in convert_values(ValueSet({self._context})):
for f in c.get_filters():
yield f
def filter_name(self, filters): def filter_name(self, filters):
""" """
Searches names that are defined in a scope (the different Searches names that are defined in a scope (the different