Fix REPL completion param name completion

There were two issues:
1. The filter for parameters was wrong
2. In general the equal sign would not be added in some circumstances
This commit is contained in:
Dave Halter
2018-03-13 21:36:04 +01:00
parent 0dda740c5d
commit f9ec989835
4 changed files with 22 additions and 15 deletions

View File

@@ -406,7 +406,7 @@ class Completion(BaseDefinition):
and self.type == 'Function': and self.type == 'Function':
append = '(' append = '('
if isinstance(self._name, ParamName) and self._stack is not None: if self._name.api_type == 'param' and self._stack is not None:
node_names = list(self._stack.get_node_names(self._evaluator.grammar._pgen_grammar)) node_names = list(self._stack.get_node_names(self._evaluator.grammar._pgen_grammar))
if 'trailer' in node_names and 'argument' not in node_names: if 'trailer' in node_names and 'argument' not in node_names:
append += '=' append += '='

View File

@@ -25,8 +25,10 @@ def get_call_signature_param_names(call_signatures):
# public API and we don't want to make the internal # public API and we don't want to make the internal
# Name object public. # Name object public.
tree_param = tree.search_ancestor(tree_name, 'param') tree_param = tree.search_ancestor(tree_name, 'param')
if tree_param.star_count == 0: # no *args/**kwargs if tree_param.star_count != 0: # no *args/**kwargs
yield p._name continue
yield p._name
def filter_names(evaluator, completion_names, stack, like_name): def filter_names(evaluator, completion_names, stack, like_name):

View File

@@ -95,6 +95,7 @@ def setup_readline(namespace_module=__main__):
) )
before = text[:len(text) - len(name)] before = text[:len(text) - len(name)]
completions = interpreter.completions() completions = interpreter.completions()
logging.debug("REPL completions: %s", completions)
except: except:
logging.error("REPL Completion error:\n" + traceback.format_exc()) logging.error("REPL Completion error:\n" + traceback.format_exc())
raise raise

View File

@@ -4,7 +4,7 @@ Tests of ``jedi.api.Interpreter``.
import pytest import pytest
import jedi import jedi
from jedi._compatibility import is_py3, py_version from jedi._compatibility import is_py3, py_version, is_py35
from jedi.evaluate.compiled import mixed from jedi.evaluate.compiled import mixed
@@ -227,8 +227,7 @@ def test_param_completion():
lambd = lambda xyz: 3 lambd = lambda xyz: 3
_assert_interpreter_complete('foo(bar', locals(), ['bar']) _assert_interpreter_complete('foo(bar', locals(), ['bar'])
# TODO we're not yet using the Python3.5 inspect.signature, yet. assert bool(jedi.Interpreter('lambd(xyz', [locals()]).completions()) == is_py35
assert not jedi.Interpreter('lambd(xyz', [locals()]).completions()
def test_endless_yield(): def test_endless_yield():
@@ -264,6 +263,20 @@ def test_completion_param_annotations():
assert {d.name for d in c._goto_definitions()} == {'int', 'float'} assert {d.name for d in c._goto_definitions()} == {'int', 'float'}
def test_keyword_argument():
def f(some_keyword_argument):
pass
c, = jedi.Interpreter("f(some_keyw", [{'f': f}]).completions()
assert c.name == 'some_keyword_argument'
assert c.complete == 'ord_argument='
# Make it impossible for jedi to find the source of the function.
f.__name__ = 'xSOMETHING'
c, = jedi.Interpreter("x(some_keyw", [{'x': f}]).completions()
assert c.name == 'some_keyword_argument'
def test_more_complex_instances(): def test_more_complex_instances():
class Something: class Something:
def foo(self, other): def foo(self, other):
@@ -326,12 +339,3 @@ def test_dir_magic_method():
foo = [c for c in completions if c.name == 'foo'][0] foo = [c for c in completions if c.name == 'foo'][0]
assert foo._goto_definitions() == [] assert foo._goto_definitions() == []
def test_keyword_argument():
def f(some_keyword_argument):
pass
c, = jedi.Interpreter("f(some_keyw", [{'f': f}]).completions()
assert c.name == 'some_keyword_argument'
assert c.complete == 'ord_argument='