Skip to content

Commit bc65629

Browse files
committed
autocomplete: restore braces on functions
Also make the output more uniform (no differences between templates and funxtions) New format is: functionName (bold) parameters (light grey) : returnType
1 parent 2793266 commit bc65629

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

app/src/cc/arduino/autocomplete/ClangCompletionProvider.java

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public class ClangCompletionProvider extends LanguageAwareCompletionProvider {
5858
public ClangCompletionProvider(Editor e, DefaultCompletionProvider cp) {
5959
super(cp);
6060
editor = e;
61-
//setParameterizedCompletionParams('(', ", ", ')');
61+
cp.setParameterizedCompletionParams('(', ", ", ')');
6262
}
6363

6464
@Override
@@ -98,21 +98,23 @@ protected List<Completion> getCompletionsImpl(JTextComponent textarea) {
9898
allCc = mapper.readValue(out, ArduinoCompletionsList.class);
9999
for (ArduinoCompletion cc : allCc) {
100100

101-
if (cc.type.equals("Macro")) {
102-
// for now skip macro
103-
continue;
104-
}
105-
106-
if (cc.type.equals("Function")) {
101+
if (cc.type.equals("Function") || cc.type.equals("Macro")) {
107102
List<Parameter> params = new ArrayList<>();
108103
int i=0;
104+
String fancyParameters = "(";
109105
for (CompletionChunk chunk : cc.completion.chunks) {
110106
if (chunk.placeholder != null) {
111107
ArduinoParameter p = cc.parameters.get(i);
112108
params.add(new Parameter(p.type, p.name));
109+
fancyParameters += (p.name.equals("") ? p.type : p.name) + ", ";
113110
i++;
114111
}
115112
}
113+
int lastComma = fancyParameters.lastIndexOf(",");
114+
if (lastComma > 0) {
115+
fancyParameters = fancyParameters.substring(0, lastComma);
116+
}
117+
fancyParameters += ")";
116118

117119
if (!cc.getCompletion().getTypedText().startsWith(getAlreadyEnteredText(textarea))) {
118120
continue;
@@ -122,19 +124,22 @@ protected List<Completion> getCompletionsImpl(JTextComponent textarea) {
122124
cc.getCompletion().getTypedText(),
123125
cc.getCompletion().getResultType());
124126
compl.setParams(params);
127+
compl.setShortDescription(fancyParameters + " : " + cc.getCompletion().getResultType());
125128
res.add(compl);
126129
continue;
127130
}
128131

129132
String returnType = "";
130133
String typedText = null;
131134
String template = "";
135+
String fancyParameters = "(";
136+
132137
for (CompletionChunk chunk : cc.completion.chunks) {
133138
if (chunk.t != null) {
134139
template += chunk.t;
135140
}
136141
if (chunk.res != null) {
137-
returnType = " - " + chunk.res;
142+
returnType = chunk.res;
138143
}
139144
if (chunk.typedtext != null) {
140145
template += chunk.typedtext;
@@ -143,16 +148,22 @@ protected List<Completion> getCompletionsImpl(JTextComponent textarea) {
143148
if (chunk.placeholder != null) {
144149
String[] spl = chunk.placeholder.split(" ");
145150
template += "${" + spl[spl.length - 1] + "}";
151+
fancyParameters += spl[spl.length - 1] + ", ";
146152
}
147153
if (chunk.info != null) {
148154
//System.out.println("INFO: "+chunk.info);
149155
}
150156
}
151157
template += "${cursor}";
158+
int lastComma = fancyParameters.lastIndexOf(",");
159+
if (lastComma > 0) {
160+
fancyParameters = fancyParameters.substring(0, lastComma);
161+
}
162+
fancyParameters += ")";
152163
//System.out.println("TEMPLATE: " + template);
153164
if (typedText.startsWith(getAlreadyEnteredText(textarea))) {
154-
res.add(new TemplateCompletion(this, typedText, typedText + returnType,
155-
template));
165+
TemplateCompletion compl = new TemplateCompletion(this, typedText, fancyParameters + " : " + returnType , template);
166+
res.add(compl);
156167
}
157168
}
158169
return res;

app/src/cc/arduino/autocomplete/CompletionsRenderer.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ public Component getListCellRendererComponent(JList list, Object value,
123123
text = ((ShorthandCompletion) value).getShortDescription();
124124
tokenType = CompletionType.TEMPLATE;
125125
} else if (value instanceof FunctionCompletion) {
126-
text = ((FunctionCompletion) value).getShortDescription();
126+
text = font(((FunctionCompletion) value).getInputText(), LIGHT_BLUE)
127+
+ font(((FunctionCompletion) value).getShortDescription(), GRAY);
127128
tokenType = CompletionType.FUNCTION;
128129
} else if (value instanceof BasicCompletion) {
129130
text = ((BasicCompletion) value).getInputText();
@@ -133,7 +134,7 @@ public Component getListCellRendererComponent(JList list, Object value,
133134
} else if (value instanceof TemplateCompletion) {
134135
TemplateCompletion template = (TemplateCompletion) value;
135136
text = font(template.getInputText(), LIGHT_BLUE)
136-
+ font(" - " + template.getDefinitionString(), GRAY);
137+
+ font(template.getDefinitionString(), GRAY);
137138
}
138139

139140
if (text == null) {

0 commit comments

Comments
 (0)