1
0
forked from VimPlug/jedi

Make sure param completions work the right way

This commit is contained in:
Dave Halter
2019-12-27 11:48:39 +01:00
parent 70bf3d9586
commit a8782d0070
3 changed files with 45 additions and 1 deletions

View File

@@ -216,6 +216,8 @@ class Completion:
elif nonterminals[-1] in ('trailer', 'dotted_name') and nodes[-1] == '.':
dot = self._module_node.get_leaf_for_position(self._position)
completion_names += self._complete_trailer(dot.get_previous_leaf())
elif self._is_parameter_completion():
pass
else:
completion_names += self._complete_global_scope()
completion_names += self._complete_inherited(is_function=False)
@@ -234,6 +236,19 @@ class Completion:
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):
for k in allowed_transitions:
if isinstance(k, str) and k.isalpha():

View File

@@ -319,6 +319,35 @@ def foo3(my_param=my_param):
pass
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
# -----------------

View File

@@ -40,4 +40,4 @@ str(def
class Foo(object):
@property
#? ['str']
def bar(str
def bar(x=str