From 93d013d1f4cd6d5da4e0e830a2803dffa452592c Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 17 Oct 2017 13:45:39 +0200 Subject: [PATCH] autocomplete: improved rendering of completions --- .../autocomplete/ClangCompletionProvider.java | 15 ++++++------- .../autocomplete/CompletionsRenderer.java | 22 +++++++++++-------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/app/src/cc/arduino/autocomplete/ClangCompletionProvider.java b/app/src/cc/arduino/autocomplete/ClangCompletionProvider.java index 5ee4464bc..7ebe9fe52 100644 --- a/app/src/cc/arduino/autocomplete/ClangCompletionProvider.java +++ b/app/src/cc/arduino/autocomplete/ClangCompletionProvider.java @@ -175,26 +175,25 @@ public class ClangCompletionProvider extends LanguageAwareCompletionProvider { } if (chunk.typedtext != null) { template += chunk.typedtext; + shortDesc += chunk.typedtext; typedText = chunk.typedtext; } if (chunk.placeholder != null) { String[] spl = chunk.placeholder.split(" "); template += "${" + spl[spl.length - 1] + "}"; - shortDesc += spl[spl.length - 1] + ", "; + shortDesc += spl[spl.length - 1]; } if (chunk.info != null) { // System.out.println("INFO: "+chunk.info); } } template += "${cursor}"; - int lastComma = shortDesc.lastIndexOf(","); - if (lastComma > 0) { - shortDesc = shortDesc.substring(0, lastComma); - } - shortDesc += ")"; System.out.println("TEMPLATE: " + template); - return new TemplateCompletion(this, typedText, - shortDesc + " : " + returnType, template); + System.out.println("SHORT: " + shortDesc); + if (!returnType.isEmpty()) { + shortDesc += " : " + returnType; + } + return new TemplateCompletion(this, typedText, shortDesc, template); } } } diff --git a/app/src/cc/arduino/autocomplete/CompletionsRenderer.java b/app/src/cc/arduino/autocomplete/CompletionsRenderer.java index 3d915c35d..d7a1a3917 100644 --- a/app/src/cc/arduino/autocomplete/CompletionsRenderer.java +++ b/app/src/cc/arduino/autocomplete/CompletionsRenderer.java @@ -120,21 +120,25 @@ public class CompletionsRenderer extends DefaultListCellRenderer { // // } else if (value instanceof ShorthandCompletion) { - text = ((ShorthandCompletion) value).getShortDescription(); + ShorthandCompletion v = (ShorthandCompletion) value; + text = v.getShortDescription(); tokenType = CompletionType.TEMPLATE; } else if (value instanceof FunctionCompletion) { - text = font(((FunctionCompletion) value).getInputText(), LIGHT_BLUE) - + font(((FunctionCompletion) value).getShortDescription(), GRAY); + FunctionCompletion v = (FunctionCompletion) value; + text = font(v.getInputText(), LIGHT_BLUE) + " " + + font(v.getShortDescription(), GRAY); tokenType = CompletionType.FUNCTION; } else if (value instanceof BasicCompletion) { - text = ((BasicCompletion) value).getInputText(); - if (((BasicCompletion) value).getShortDescription() != null) { - text = ((BasicCompletion) value).getShortDescription(); + BasicCompletion v = (BasicCompletion) value; + if (v.getShortDescription() != null) { + text = v.getShortDescription(); + } else { + text = v.getInputText(); } } else if (value instanceof TemplateCompletion) { - TemplateCompletion template = (TemplateCompletion) value; - text = font(template.getInputText(), LIGHT_BLUE) - + font(template.getDefinitionString(), GRAY); + TemplateCompletion v = (TemplateCompletion) value; + text = font(v.getInputText(), LIGHT_BLUE) + " " + + font(v.getDefinitionString(), GRAY); } if (text == null) {