1
0
forked from VimPlug/jedi

Move some finder stuff around

This commit is contained in:
Dave Halter
2019-08-24 02:28:58 +02:00
parent 3828532065
commit e148d5120f
4 changed files with 13 additions and 16 deletions

View File

@@ -96,7 +96,7 @@ class HelperValueMixin(object):
if name_context is None: if name_context is None:
name_context = self name_context = self
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, name_context, name_or_str,
analysis_errors=analysis_errors) analysis_errors=analysis_errors)
filters = self._get_value_filters(name_or_str) filters = self._get_value_filters(name_or_str)
names = f.filter_name(filters) names = f.filter_name(filters)

View File

@@ -25,7 +25,7 @@ class AbstractContext(object):
def _goto(self, name_or_str, position): def _goto(self, name_or_str, position):
from jedi.inference import finder from jedi.inference import finder
f = finder.NameFinder(self.inference_state, self, self, name_or_str, position) f = finder.NameFinder(self, self, name_or_str, position)
filters = _get_global_filters_for_name( filters = _get_global_filters_for_name(
self, name_or_str if isinstance(name_or_str, Name) else None, position, self, name_or_str if isinstance(name_or_str, Name) else None, position,
) )

View File

@@ -19,21 +19,17 @@ from parso.python import tree
from parso.tree import search_ancestor from parso.tree import search_ancestor
from jedi import debug from jedi import debug
from jedi import settings from jedi import settings
from jedi.inference import compiled
from jedi.inference import analysis
from jedi.inference import flow_analysis from jedi.inference import flow_analysis
from jedi.inference.arguments import TreeArguments from jedi.inference.arguments import TreeArguments
from jedi.inference import helpers from jedi.inference import helpers
from jedi.inference.value import iterable from jedi.inference.value import iterable
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
class NameFinder(object): class NameFinder(object):
def __init__(self, inference_state, context, name_value, name_or_str, def __init__(self, context, name_value, name_or_str,
position=None, analysis_errors=True): position=None, analysis_errors=True):
self._inference_state = inference_state
# Make sure that it's not just a syntax tree node. # Make sure that it's not just a syntax tree node.
self._context = context self._context = context
self._name_context = name_value self._name_context = name_value
@@ -77,7 +73,11 @@ class NameFinder(object):
return NO_VALUES return NO_VALUES
return found_predefined_types return found_predefined_types
return self._names_to_types(names) values = ValueSet.from_sets(name.infer() for name in names)
debug.dbg('finder._names_to_types: %s -> %s', names, values)
if values:
return values
return self._add_other_knowledge()
def filter_name(self, filters): def filter_name(self, filters):
""" """
@@ -92,18 +92,15 @@ class NameFinder(object):
return list(names) return list(names)
def _names_to_types(self, names): def _add_other_knowledge(self):
values = ValueSet.from_sets(name.infer() for name in names)
debug.dbg('finder._names_to_types: %s -> %s', names, values)
# Add isinstance and other if/assert knowledge. # Add isinstance and other if/assert knowledge.
if not values and isinstance(self._name, tree.Name) and \ if isinstance(self._name, tree.Name) and \
not self._name_context.is_instance() and not self._context.is_compiled(): not self._name_context.is_instance() and not self._context.is_compiled():
flow_scope = self._name flow_scope = self._name
base_nodes = [self._name_context.tree_node] base_nodes = [self._name_context.tree_node]
if any(b.type in ('comp_for', 'sync_comp_for') for b in base_nodes): if any(b.type in ('comp_for', 'sync_comp_for') for b in base_nodes):
return values return NO_VALUES
while True: while True:
flow_scope = get_parent_scope(flow_scope, include_flows=True) flow_scope = get_parent_scope(flow_scope, include_flows=True)
n = _check_flow_information(self._name_context, flow_scope, n = _check_flow_information(self._name_context, flow_scope,
@@ -112,7 +109,7 @@ class NameFinder(object):
return n return n
if flow_scope in base_nodes: if flow_scope in base_nodes:
break break
return values return NO_VALUES
def _check_flow_information(value, flow, search_name, pos): def _check_flow_information(value, flow, search_name, pos):

View File

@@ -571,7 +571,7 @@ def tree_name_to_values(inference_state, context, tree_name):
node = tree_name.parent node = tree_name.parent
if node.type == 'global_stmt': if node.type == 'global_stmt':
c = context.create_context(tree_name) c = context.create_context(tree_name)
finder = NameFinder(inference_state, c, c, tree_name.value) finder = NameFinder(c, c, tree_name.value)
# 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(c.get_filters())] filters = [next(c.get_filters())]