mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 14:04:26 +08:00
Start trying to find param names
This commit is contained in:
@@ -384,12 +384,12 @@ def extract_function(inference_state, path, module_context, name, pos, until_pos
|
|||||||
is_expression = True
|
is_expression = True
|
||||||
nodes = _find_nodes(module_context.tree_node, pos, until_pos)
|
nodes = _find_nodes(module_context.tree_node, pos, until_pos)
|
||||||
return_variables = []
|
return_variables = []
|
||||||
params = _find_non_global_names(nodes)
|
context = module_context.create_context(nodes[0])
|
||||||
|
params = list(_find_non_global_names(context, nodes))
|
||||||
|
|
||||||
dct = {}
|
dct = {}
|
||||||
# Find variables
|
# Find variables
|
||||||
# Is a class method / method
|
# Is a class method / method
|
||||||
context = module_context.create_context(nodes[0])
|
|
||||||
if context.is_module():
|
if context.is_module():
|
||||||
insert_before_leaf = None # Leaf will be determined later
|
insert_before_leaf = None # Leaf will be determined later
|
||||||
else:
|
else:
|
||||||
@@ -424,8 +424,16 @@ def extract_function(inference_state, path, module_context, name, pos, until_pos
|
|||||||
return Refactoring(inference_state.grammar, file_to_node_changes)
|
return Refactoring(inference_state.grammar, file_to_node_changes)
|
||||||
|
|
||||||
|
|
||||||
def _find_non_global_names(nodes):
|
def _find_non_global_names(context, nodes):
|
||||||
return []
|
for node in nodes:
|
||||||
|
try:
|
||||||
|
children = node.children
|
||||||
|
except AttributeError:
|
||||||
|
if node.type == 'name':
|
||||||
|
yield node.value
|
||||||
|
else:
|
||||||
|
for x in _find_non_global_names(context, children): # Python 2...
|
||||||
|
yield x
|
||||||
|
|
||||||
|
|
||||||
def _get_code_insertion_node(context):
|
def _get_code_insertion_node(context):
|
||||||
|
|||||||
@@ -3,11 +3,11 @@
|
|||||||
test(100, (30 + b, c) + 1)
|
test(100, (30 + b, c) + 1)
|
||||||
# ++++++++++++++++++++++++++++++++++++++++++++++++++
|
# ++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
#? 11 text {'new_name': 'a'}
|
#? 11 text {'new_name': 'a'}
|
||||||
def a():
|
def a(b):
|
||||||
return 30 + b
|
return 30 + b
|
||||||
|
|
||||||
|
|
||||||
test(100, (a(), c) + 1)
|
test(100, (a(b), c) + 1)
|
||||||
# -------------------------------------------------- in-module-2
|
# -------------------------------------------------- in-module-2
|
||||||
#? 0 text {'new_name': 'ab'}
|
#? 0 text {'new_name': 'ab'}
|
||||||
100 + 1 * 2
|
100 + 1 * 2
|
||||||
@@ -23,27 +23,27 @@ def f(x):
|
|||||||
#? 11 text {'new_name': 'ab'}
|
#? 11 text {'new_name': 'ab'}
|
||||||
return x + 1 * 2
|
return x + 1 * 2
|
||||||
# ++++++++++++++++++++++++++++++++++++++++++++++++++
|
# ++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
def ab():
|
def ab(x):
|
||||||
return x + 1 * 2
|
return x + 1 * 2
|
||||||
|
|
||||||
|
|
||||||
def f(x):
|
def f(x):
|
||||||
#? 11 text {'new_name': 'ab'}
|
#? 11 text {'new_name': 'ab'}
|
||||||
return ab()
|
return ab(x)
|
||||||
# -------------------------------------------------- in-function-with-dec
|
# -------------------------------------------------- in-function-with-dec
|
||||||
@classmethod
|
@classmethod
|
||||||
def f(x):
|
def f(x):
|
||||||
#? 11 text {'new_name': 'ab'}
|
#? 11 text {'new_name': 'ab'}
|
||||||
return x + 1 * 2
|
return x + 1 * 2
|
||||||
# ++++++++++++++++++++++++++++++++++++++++++++++++++
|
# ++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
def ab():
|
def ab(x):
|
||||||
return x + 1 * 2
|
return x + 1 * 2
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def f(x):
|
def f(x):
|
||||||
#? 11 text {'new_name': 'ab'}
|
#? 11 text {'new_name': 'ab'}
|
||||||
return ab()
|
return ab(x)
|
||||||
# -------------------------------------------------- in-method-1
|
# -------------------------------------------------- in-method-1
|
||||||
class X:
|
class X:
|
||||||
def z(self): pass
|
def z(self): pass
|
||||||
@@ -55,12 +55,12 @@ class X:
|
|||||||
class X:
|
class X:
|
||||||
def z(self): pass
|
def z(self): pass
|
||||||
|
|
||||||
def ab():
|
def ab(x):
|
||||||
return x + 1 * 2
|
return x + 1 * 2
|
||||||
|
|
||||||
def f(x):
|
def f(x):
|
||||||
#? 11 text {'new_name': 'ab'}
|
#? 11 text {'new_name': 'ab'}
|
||||||
return ab()
|
return ab(x)
|
||||||
# -------------------------------------------------- in-classmethod-1
|
# -------------------------------------------------- in-classmethod-1
|
||||||
class X:
|
class X:
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -98,11 +98,11 @@ class Ya():
|
|||||||
#? 11 text {'new_name': 'f'}
|
#? 11 text {'new_name': 'f'}
|
||||||
c = a + 2
|
c = a + 2
|
||||||
# ++++++++++++++++++++++++++++++++++++++++++++++++++
|
# ++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
def f():
|
def f(a):
|
||||||
return a + 2
|
return a + 2
|
||||||
|
|
||||||
|
|
||||||
class Ya():
|
class Ya():
|
||||||
a = 3
|
a = 3
|
||||||
#? 11 text {'new_name': 'f'}
|
#? 11 text {'new_name': 'f'}
|
||||||
c = f()
|
c = f(a)
|
||||||
|
|||||||
Reference in New Issue
Block a user