Skip to content

Commit 44f006c

Browse files
easyfrogmarijnh
authored andcommitted
Change the way types are shown in completions
1 parent c4006c6 commit 44f006c

File tree

1 file changed

+29
-16
lines changed

1 file changed

+29
-16
lines changed

tern.py

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -354,16 +354,21 @@ def report_error(message, project):
354354
project.disabled = True
355355

356356
def completion_icon(type):
357-
if type is None or type == "?": return " (?)"
358-
if type.startswith("fn("): return " (fn)"
359-
if type.startswith("["): return " ([])"
360-
if type == "number": return " (num)"
361-
if type == "string": return " (str)"
362-
if type == "bool": return " (bool)"
363-
return " (obj)"
364-
365-
def fn_completion_icon(arguments):
366-
return " (fn/"+str(len(arguments))+")"
357+
if type is None or type == "?": return "\t? "
358+
if type.startswith("fn("): return "\tfn "
359+
if type.startswith("["): return "\t[] "
360+
if type == "number": return "\tnum "
361+
if type == "string": return "\tstr "
362+
if type == "bool": return "\tbool "
363+
return "\t{} "
364+
365+
def fn_completion_icon(arguments, retval):
366+
# return " (fn/"+str(len(arguments))+")"
367+
ret = ""
368+
if retval is not None:
369+
ret = retval
370+
371+
return "(" + ", ".join(arguments) + ")" + ret + ("\tfn ")
367372

368373
# create auto complete string from list arguments
369374
def create_arg_str(arguments):
@@ -421,14 +426,22 @@ def ensure_completions_cached(pfile, view):
421426
for rec in data["completions"]:
422427
rec_name = rec.get('name').replace('$', '\\$')
423428
rec_type = rec.get("type", None)
424-
if arg_completion_enabled and completion_icon(rec_type) == " (fn)":
429+
if arg_completion_enabled and rec_type is not None and rec_type.startswith("fn("):
430+
retval = parse_function_type(rec).get('retval')
431+
432+
if retval is None or retval == "()":
433+
retval = ""
434+
elif retval.startswith("{"):
435+
retval = "{}"
436+
elif retval.startswith("["):
437+
retval = "[]"
438+
439+
if retval != "":
440+
retval = " -> " + retval
441+
425442
arguments = get_arguments(rec_type)
426443
fn_name = rec_name + "(" + create_arg_str(arguments) + ")"
427-
completions.append((rec.get("name") + fn_completion_icon(arguments), fn_name))
428-
429-
for i in range(len(arguments) - 1, -1, -1):
430-
fn_name = rec_name + "(" + create_arg_str(arguments[0:i]) + ")"
431-
completions_arity.append((rec.get("name") + fn_completion_icon(arguments[0:i]), fn_name))
444+
completions.append((rec.get("name") + fn_completion_icon(arguments, retval), fn_name))
432445
else:
433446
completions.append((rec.get("name") + completion_icon(rec_type), rec_name))
434447

0 commit comments

Comments
 (0)