forked from VimPlug/jedi
Differentiate in finder between get_value_filters and get_global_filters
This commit is contained in:
@@ -66,7 +66,10 @@ class HelperValueMixin(object):
|
|||||||
from jedi.inference import finder
|
from jedi.inference import finder
|
||||||
f = finder.NameFinder(self.infer_state, self, name_value, name_or_str,
|
f = finder.NameFinder(self.infer_state, self, name_value, name_or_str,
|
||||||
position, analysis_errors=analysis_errors)
|
position, analysis_errors=analysis_errors)
|
||||||
filters = f.get_filters(search_global)
|
if search_global:
|
||||||
|
filters = f.get_global_filters()
|
||||||
|
else:
|
||||||
|
filters = f.get_value_filters()
|
||||||
if is_goto:
|
if is_goto:
|
||||||
return f.filter_name(filters)
|
return f.filter_name(filters)
|
||||||
return f.find(filters, attribute_lookup=not search_global)
|
return f.find(filters, attribute_lookup=not search_global)
|
||||||
|
|||||||
@@ -92,33 +92,31 @@ class NameFinder(object):
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_filters(self, search_global=False):
|
def get_global_filters(self):
|
||||||
origin_scope = self._get_origin_scope()
|
origin_scope = self._get_origin_scope()
|
||||||
if search_global:
|
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
|
||||||
# function and get inferred in the value before the function. So
|
# function and get inferred in the value before the function. So
|
||||||
# make sure to exclude the function/class name.
|
# make sure to exclude the function/class name.
|
||||||
if origin_scope is not None:
|
if origin_scope is not None:
|
||||||
ancestor = search_ancestor(origin_scope, 'funcdef', 'classdef', 'lambdef')
|
ancestor = search_ancestor(origin_scope, 'funcdef', 'classdef', 'lambdef')
|
||||||
lambdef = None
|
lambdef = None
|
||||||
if ancestor == 'lambdef':
|
if ancestor == 'lambdef':
|
||||||
# For lambdas it's even more complicated since parts will
|
# For lambdas it's even more complicated since parts will
|
||||||
# be inferred later.
|
# be inferred later.
|
||||||
lambdef = ancestor
|
lambdef = ancestor
|
||||||
ancestor = search_ancestor(origin_scope, 'funcdef', 'classdef')
|
ancestor = search_ancestor(origin_scope, 'funcdef', 'classdef')
|
||||||
if ancestor is not None:
|
if ancestor is not None:
|
||||||
colon = ancestor.children[-2]
|
colon = ancestor.children[-2]
|
||||||
if position is not None and position < colon.start_pos:
|
if position is not None and position < colon.start_pos:
|
||||||
if lambdef is None or position < lambdef.children[-2].start_pos:
|
if lambdef is None or position < lambdef.children[-2].start_pos:
|
||||||
position = ancestor.start_pos
|
position = ancestor.start_pos
|
||||||
|
|
||||||
return get_global_filters(self._infer_state, self._value, position, origin_scope)
|
return get_global_filters(self._infer_state, self._value, position, origin_scope)
|
||||||
else:
|
|
||||||
return self._get_value_filters(origin_scope)
|
|
||||||
|
|
||||||
def _get_value_filters(self, origin_scope):
|
def get_value_filters(self):
|
||||||
|
origin_scope = self._get_origin_scope()
|
||||||
for f in self._value.get_filters(False, self._position, origin_scope=origin_scope):
|
for f in self._value.get_filters(False, self._position, origin_scope=origin_scope):
|
||||||
yield f
|
yield f
|
||||||
# This covers the case where a stub files are incomplete.
|
# This covers the case where a stub files are incomplete.
|
||||||
|
|||||||
@@ -572,7 +572,7 @@ def tree_name_to_values(infer_state, value, tree_name):
|
|||||||
if node.type == 'global_stmt':
|
if node.type == 'global_stmt':
|
||||||
value = infer_state.create_value(value, tree_name)
|
value = infer_state.create_value(value, tree_name)
|
||||||
finder = NameFinder(infer_state, value, value, tree_name.value)
|
finder = NameFinder(infer_state, value, value, tree_name.value)
|
||||||
filters = finder.get_filters(search_global=True)
|
filters = finder.get_global_filters()
|
||||||
# For global_stmt lookups, we only need the first possible scope,
|
# For global_stmt lookups, we only need the first possible scope,
|
||||||
# which means the function itself.
|
# which means the function itself.
|
||||||
filters = [next(filters)]
|
filters = [next(filters)]
|
||||||
|
|||||||
Reference in New Issue
Block a user