mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 22:14:27 +08:00
Make sure param completions work the right way
This commit is contained in:
@@ -216,6 +216,8 @@ class Completion:
|
|||||||
elif nonterminals[-1] in ('trailer', 'dotted_name') and nodes[-1] == '.':
|
elif nonterminals[-1] in ('trailer', 'dotted_name') and nodes[-1] == '.':
|
||||||
dot = self._module_node.get_leaf_for_position(self._position)
|
dot = self._module_node.get_leaf_for_position(self._position)
|
||||||
completion_names += self._complete_trailer(dot.get_previous_leaf())
|
completion_names += self._complete_trailer(dot.get_previous_leaf())
|
||||||
|
elif self._is_parameter_completion():
|
||||||
|
pass
|
||||||
else:
|
else:
|
||||||
completion_names += self._complete_global_scope()
|
completion_names += self._complete_global_scope()
|
||||||
completion_names += self._complete_inherited(is_function=False)
|
completion_names += self._complete_inherited(is_function=False)
|
||||||
@@ -234,6 +236,19 @@ class Completion:
|
|||||||
|
|
||||||
return completion_names
|
return completion_names
|
||||||
|
|
||||||
|
def _is_parameter_completion(self):
|
||||||
|
tos = self.stack[-1]
|
||||||
|
if tos.nonterminal == 'lambdef' and len(tos.nodes) == 1:
|
||||||
|
# We are at the position `lambda `, where basically the next node
|
||||||
|
# is a param.
|
||||||
|
return True
|
||||||
|
if tos.nonterminal in 'parameters':
|
||||||
|
# Basically we are at the position `foo(`, there's nothing there
|
||||||
|
# yet, so we have no `typedargslist`.
|
||||||
|
return True
|
||||||
|
# var args is for lambdas and typed args for normal functions
|
||||||
|
return tos.nonterminal in ('typedargslist', 'varargslist') and tos.nodes[-1] == ','
|
||||||
|
|
||||||
def _complete_keywords(self, allowed_transitions):
|
def _complete_keywords(self, allowed_transitions):
|
||||||
for k in allowed_transitions:
|
for k in allowed_transitions:
|
||||||
if isinstance(k, str) and k.isalpha():
|
if isinstance(k, str) and k.isalpha():
|
||||||
|
|||||||
@@ -319,6 +319,35 @@ def foo3(my_param=my_param):
|
|||||||
pass
|
pass
|
||||||
foo3("")
|
foo3("")
|
||||||
|
|
||||||
|
some_default = ''
|
||||||
|
#? []
|
||||||
|
def foo(my_t
|
||||||
|
#? []
|
||||||
|
def foo(my_t, my_ty
|
||||||
|
#? ['some_default']
|
||||||
|
def foo(my_t=some_defa
|
||||||
|
#? ['some_default']
|
||||||
|
def foo(my_t=some_defa, my_t2=some_defa
|
||||||
|
|
||||||
|
#? ['my_type']
|
||||||
|
def foo(my_t: lala=some_defa, my_t2: my_typ
|
||||||
|
#? ['my_type']
|
||||||
|
def foo(my_t: lala=some_defa, my_t2: my_typ
|
||||||
|
#? []
|
||||||
|
def foo(my_t: lala=some_defa, my_t
|
||||||
|
|
||||||
|
#? []
|
||||||
|
lambda my_t
|
||||||
|
#? []
|
||||||
|
lambda my_, my_t
|
||||||
|
#? ['some_default']
|
||||||
|
lambda x=some_defa
|
||||||
|
#? ['some_default']
|
||||||
|
lambda y, x=some_defa
|
||||||
|
|
||||||
|
# Just make sure we're not in some weird parsing recovery after opening brackets
|
||||||
|
def
|
||||||
|
|
||||||
# -----------------
|
# -----------------
|
||||||
# continuations
|
# continuations
|
||||||
# -----------------
|
# -----------------
|
||||||
|
|||||||
@@ -40,4 +40,4 @@ str(def
|
|||||||
class Foo(object):
|
class Foo(object):
|
||||||
@property
|
@property
|
||||||
#? ['str']
|
#? ['str']
|
||||||
def bar(str
|
def bar(x=str
|
||||||
|
|||||||
Reference in New Issue
Block a user