forked from VimPlug/jedi
Use create_name instead of duplicated logic
This commit is contained in:
+1
-11
@@ -34,7 +34,6 @@ from jedi.inference import usages
|
|||||||
from jedi.inference.arguments import try_iter_content
|
from jedi.inference.arguments import try_iter_content
|
||||||
from jedi.inference.helpers import get_module_names, infer_call_of_leaf
|
from jedi.inference.helpers import get_module_names, infer_call_of_leaf
|
||||||
from jedi.inference.sys_path import transform_path_to_dotted
|
from jedi.inference.sys_path import transform_path_to_dotted
|
||||||
from jedi.inference.names import TreeNameDefinition, AnonymousParamName
|
|
||||||
from jedi.inference.syntax_tree import tree_name_to_values
|
from jedi.inference.syntax_tree import tree_name_to_values
|
||||||
from jedi.inference.value import ModuleValue
|
from jedi.inference.value import ModuleValue
|
||||||
from jedi.inference.base_value import ValueSet
|
from jedi.inference.base_value import ValueSet
|
||||||
@@ -503,22 +502,13 @@ def names(source=None, path=None, encoding='utf-8', all_scopes=False,
|
|||||||
is_def = _def._name.tree_name.is_definition()
|
is_def = _def._name.tree_name.is_definition()
|
||||||
return definitions and is_def or references and not is_def
|
return definitions and is_def or references and not is_def
|
||||||
|
|
||||||
def create_name(name):
|
|
||||||
context = module_context.create_context(name)
|
|
||||||
if name.parent.type == 'param':
|
|
||||||
func = tree.search_ancestor(name, 'funcdef', 'lambdef')
|
|
||||||
func = context.get_root_context().create_value(func)
|
|
||||||
return AnonymousParamName(func, name)
|
|
||||||
else:
|
|
||||||
return TreeNameDefinition(context, name)
|
|
||||||
|
|
||||||
# Set line/column to a random position, because they don't matter.
|
# Set line/column to a random position, because they don't matter.
|
||||||
script = Script(source, line=1, column=0, path=path, encoding=encoding, environment=environment)
|
script = Script(source, line=1, column=0, path=path, encoding=encoding, environment=environment)
|
||||||
module_context = script._get_module_context()
|
module_context = script._get_module_context()
|
||||||
defs = [
|
defs = [
|
||||||
classes.Definition(
|
classes.Definition(
|
||||||
script._inference_state,
|
script._inference_state,
|
||||||
create_name(name)
|
module_context.create_name(name)
|
||||||
) for name in get_module_names(script._module_node, all_scopes)
|
) for name in get_module_names(script._module_node, all_scopes)
|
||||||
]
|
]
|
||||||
return sorted(filter(def_ref_filter, defs), key=lambda x: (x.line, x.column))
|
return sorted(filter(def_ref_filter, defs), key=lambda x: (x.line, x.column))
|
||||||
|
|||||||
Reference in New Issue
Block a user