Skip to content

Commit 93d013d

Browse files
cmagliefacchinm
authored andcommitted
autocomplete: improved rendering of completions
1 parent 3d6af52 commit 93d013d

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

Diff for: app/src/cc/arduino/autocomplete/ClangCompletionProvider.java

+7-8
Original file line numberDiff line numberDiff line change
@@ -175,26 +175,25 @@ private Completion createCompletionFromArduinoCompletion(ArduinoCompletion cc) {
175175
}
176176
if (chunk.typedtext != null) {
177177
template += chunk.typedtext;
178+
shortDesc += chunk.typedtext;
178179
typedText = chunk.typedtext;
179180
}
180181
if (chunk.placeholder != null) {
181182
String[] spl = chunk.placeholder.split(" ");
182183
template += "${" + spl[spl.length - 1] + "}";
183-
shortDesc += spl[spl.length - 1] + ", ";
184+
shortDesc += spl[spl.length - 1];
184185
}
185186
if (chunk.info != null) {
186187
// System.out.println("INFO: "+chunk.info);
187188
}
188189
}
189190
template += "${cursor}";
190-
int lastComma = shortDesc.lastIndexOf(",");
191-
if (lastComma > 0) {
192-
shortDesc = shortDesc.substring(0, lastComma);
193-
}
194-
shortDesc += ")";
195191
System.out.println("TEMPLATE: " + template);
196-
return new TemplateCompletion(this, typedText,
197-
shortDesc + " : " + returnType, template);
192+
System.out.println("SHORT: " + shortDesc);
193+
if (!returnType.isEmpty()) {
194+
shortDesc += " : " + returnType;
195+
}
196+
return new TemplateCompletion(this, typedText, shortDesc, template);
198197
}
199198
}
200199
}

Diff for: app/src/cc/arduino/autocomplete/CompletionsRenderer.java

+13-9
Original file line numberDiff line numberDiff line change
@@ -120,21 +120,25 @@ public Component getListCellRendererComponent(JList list, Object value,
120120
//
121121
// } else
122122
if (value instanceof ShorthandCompletion) {
123-
text = ((ShorthandCompletion) value).getShortDescription();
123+
ShorthandCompletion v = (ShorthandCompletion) value;
124+
text = v.getShortDescription();
124125
tokenType = CompletionType.TEMPLATE;
125126
} else if (value instanceof FunctionCompletion) {
126-
text = font(((FunctionCompletion) value).getInputText(), LIGHT_BLUE)
127-
+ font(((FunctionCompletion) value).getShortDescription(), GRAY);
127+
FunctionCompletion v = (FunctionCompletion) value;
128+
text = font(v.getInputText(), LIGHT_BLUE) + " "
129+
+ font(v.getShortDescription(), GRAY);
128130
tokenType = CompletionType.FUNCTION;
129131
} else if (value instanceof BasicCompletion) {
130-
text = ((BasicCompletion) value).getInputText();
131-
if (((BasicCompletion) value).getShortDescription() != null) {
132-
text = ((BasicCompletion) value).getShortDescription();
132+
BasicCompletion v = (BasicCompletion) value;
133+
if (v.getShortDescription() != null) {
134+
text = v.getShortDescription();
135+
} else {
136+
text = v.getInputText();
133137
}
134138
} else if (value instanceof TemplateCompletion) {
135-
TemplateCompletion template = (TemplateCompletion) value;
136-
text = font(template.getInputText(), LIGHT_BLUE)
137-
+ font(template.getDefinitionString(), GRAY);
139+
TemplateCompletion v = (TemplateCompletion) value;
140+
text = font(v.getInputText(), LIGHT_BLUE) + " "
141+
+ font(v.getDefinitionString(), GRAY);
138142
}
139143

140144
if (text == null) {

0 commit comments

Comments
 (0)