Commit 6d57a9c7 authored by Matias Guijarro's avatar Matias Guijarro

Merge branch 'typing_helper_advancement' into 'master'

typing helper advancement

Closes #726 and #733

See merge request bliss/bliss!1305
parents 6b492110 d9cc61e2
......@@ -50,7 +50,7 @@ class TypingHelper(object):
)
cs_plus_open_bracket = ji_plus_open_bracket.call_signatures()
# add open bracket or '
# add open bracket or ,
if len(cs) < len(cs_plus_open_bracket):
repl.default_buffer.insert_text("(")
elif len(cs) > len(cs_plus_open_bracket):
......@@ -62,11 +62,19 @@ class TypingHelper(object):
except ValidationError as e: # e.g. inside string ... print('bla bla
if e.message == "Syntax Error":
repl.default_buffer.insert_text(" ")
elif self.is_float_str(re.split(r",|\(", text)[-1]): # e.g. ascan(m0,1
repl.default_buffer.insert_text(",")
else:
repl.default_buffer.insert_text(" ")
try: # e.g. ascan(m0,1 or ascan(run=False,1
tmp = re.split(r",|\(", text)[-1]
if len(tmp) > 0 and tmp[-1] != "," and cs != []:
doc = Document(text=tmp, cursor_position=len(tmp))
self.validator.validate(doc)
repl.default_buffer.insert_text(",")
else:
repl.default_buffer.insert_text(" ")
except ValidationError as e:
repl.default_buffer.insert_text(" ")
else:
repl.default_buffer.insert_text(" ")
......@@ -111,7 +119,7 @@ class TypingHelper(object):
text = repl.default_buffer.text
curs_pos = repl.default_buffer.cursor_position
if curs_pos == len(text) & len(text) > 0:
if curs_pos == len(text) & len(text) > 0 and text[-1] != ",":
doc = Document(text=text, cursor_position=curs_pos)
try:
self.validator.validate(doc)
......@@ -158,8 +166,20 @@ class TypingHelper(object):
try:
self.validator.validate(new_doc)
repl.default_buffer.insert_text("()")
return True
# check if any parameters that are not keyword-arguments
# are needed, if yes -> don't complete!
try:
if len(cs_plus_open_bracket[-1].params) > 0:
for p in cs_plus_open_bracket[-1].params:
assert p.defined_names() != []
repl.default_buffer.insert_text("()")
return True
except AssertionError:
pass
except ValidationError:
pass
return False
......@@ -122,7 +122,55 @@ def test_shell_function_with_return_only(clean_gevent):
assert result == ""
def test_shell_callable_with_args(clean_gevent):
clean_gevent["end-check"] = False
result, cli, _ = _feed_cli_with_input("sum\r")
assert result == "sum"
def test_shell_callable_with_kwargs_only(clean_gevent):
clean_gevent["end-check"] = False
result, cli, _ = _feed_cli_with_input("property\r")
assert result == "property()"
def test_shell_callable_with_args_and_kwargs(clean_gevent):
clean_gevent["end-check"] = False
result, cli, _ = _feed_cli_with_input("compile\r")
assert result == "compile"
def test_shell_semicolon(clean_gevent):
clean_gevent["end-check"] = False
result, cli, _ = _feed_cli_with_input("print 1 2;print 1\r")
assert result == "print(1,2);print(1)"
def test_shell_comma_outside_callable_assignment(clean_gevent):
clean_gevent["end-check"] = False
result, cli, _ = _feed_cli_with_input("a=True \r")
assert result == "a=True"
def test_shell_comma_outside_callable_bool(clean_gevent):
clean_gevent["end-check"] = False
result, cli, _ = _feed_cli_with_input("True \r")
assert result == "True"
def test_shell_comma_outside_callable_string(clean_gevent):
clean_gevent["end-check"] = False
result, cli, _ = _feed_cli_with_input("'bla' \r")
assert result == "'bla'"
def test_shell_comma_outside_callable_number(clean_gevent):
clean_gevent["end-check"] = False
result, cli, _ = _feed_cli_with_input("1.1 + 1 \r")
assert result == "1.1 + 1"
def test_shell_comma_after_comma(clean_gevent):
clean_gevent["end-check"] = False
result, cli, _ = _feed_cli_with_input("1, \r")
assert result == "1,"
......@@ -115,3 +115,45 @@ def test_shell_autocomplete_property(clean_gevent):
br = _run_incomplete("tpc.z.", {"tpc": tpc})
completions = _get_completion(br)
assert "b" in completions
def test_shell_comma_object(clean_gevent):
clean_gevent["end-check"] = False
br = _run_incomplete("print self \r", {})
assert br.default_buffer.text == "print(self,\n"
def test_shell_comma_after_comma_inside_callable(clean_gevent):
clean_gevent["end-check"] = False
br = _run_incomplete("print(1, ", {})
assert br.default_buffer.text == "print(1, "
def test_shell_comma_int(clean_gevent):
clean_gevent["end-check"] = False
br = _run_incomplete("print 1 ", {})
assert br.default_buffer.text == "print(1,"
def test_shell_comma_float(clean_gevent):
clean_gevent["end-check"] = False
br = _run_incomplete("print 1.1 ", {})
assert br.default_buffer.text == "print(1.1,"
def test_shell_comma_bool(clean_gevent):
clean_gevent["end-check"] = False
br = _run_incomplete("print False ", {})
assert br.default_buffer.text == "print(False,"
def test_shell_comma_string(clean_gevent):
clean_gevent["end-check"] = False
br = _run_incomplete("print 'bla' ", {})
assert br.default_buffer.text == "print('bla',"
def test_shell_comma_kwarg(clean_gevent):
clean_gevent["end-check"] = False
br = _run_incomplete("print run=True ", {})
assert br.default_buffer.text == "print(run=True,"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment