mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-26 20:54:22 +01:00
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
This commit is contained in:
parent
d8d06134c7
commit
8b53785c9f
@ -58,7 +58,7 @@ public class ClangCompletionProvider extends LanguageAwareCompletionProvider {
|
|||||||
public ClangCompletionProvider(Editor e, DefaultCompletionProvider cp) {
|
public ClangCompletionProvider(Editor e, DefaultCompletionProvider cp) {
|
||||||
super(cp);
|
super(cp);
|
||||||
editor = e;
|
editor = e;
|
||||||
//setParameterizedCompletionParams('(', ", ", ')');
|
cp.setParameterizedCompletionParams('(', ", ", ')');
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -98,21 +98,23 @@ public class ClangCompletionProvider extends LanguageAwareCompletionProvider {
|
|||||||
allCc = mapper.readValue(out, ArduinoCompletionsList.class);
|
allCc = mapper.readValue(out, ArduinoCompletionsList.class);
|
||||||
for (ArduinoCompletion cc : allCc) {
|
for (ArduinoCompletion cc : allCc) {
|
||||||
|
|
||||||
if (cc.type.equals("Macro")) {
|
if (cc.type.equals("Function") || cc.type.equals("Macro")) {
|
||||||
// for now skip macro
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cc.type.equals("Function")) {
|
|
||||||
List<Parameter> params = new ArrayList<>();
|
List<Parameter> params = new ArrayList<>();
|
||||||
int i=0;
|
int i=0;
|
||||||
|
String fancyParameters = "(";
|
||||||
for (CompletionChunk chunk : cc.completion.chunks) {
|
for (CompletionChunk chunk : cc.completion.chunks) {
|
||||||
if (chunk.placeholder != null) {
|
if (chunk.placeholder != null) {
|
||||||
ArduinoParameter p = cc.parameters.get(i);
|
ArduinoParameter p = cc.parameters.get(i);
|
||||||
params.add(new Parameter(p.type, p.name));
|
params.add(new Parameter(p.type, p.name));
|
||||||
|
fancyParameters += (p.name.equals("") ? p.type : p.name) + ", ";
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
int lastComma = fancyParameters.lastIndexOf(",");
|
||||||
|
if (lastComma > 0) {
|
||||||
|
fancyParameters = fancyParameters.substring(0, lastComma);
|
||||||
|
}
|
||||||
|
fancyParameters += ")";
|
||||||
|
|
||||||
if (!cc.getCompletion().getTypedText().startsWith(getAlreadyEnteredText(textarea))) {
|
if (!cc.getCompletion().getTypedText().startsWith(getAlreadyEnteredText(textarea))) {
|
||||||
continue;
|
continue;
|
||||||
@ -122,6 +124,7 @@ public class ClangCompletionProvider extends LanguageAwareCompletionProvider {
|
|||||||
cc.getCompletion().getTypedText(),
|
cc.getCompletion().getTypedText(),
|
||||||
cc.getCompletion().getResultType());
|
cc.getCompletion().getResultType());
|
||||||
compl.setParams(params);
|
compl.setParams(params);
|
||||||
|
compl.setShortDescription(fancyParameters + " : " + cc.getCompletion().getResultType());
|
||||||
res.add(compl);
|
res.add(compl);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -129,12 +132,14 @@ public class ClangCompletionProvider extends LanguageAwareCompletionProvider {
|
|||||||
String returnType = "";
|
String returnType = "";
|
||||||
String typedText = null;
|
String typedText = null;
|
||||||
String template = "";
|
String template = "";
|
||||||
|
String fancyParameters = "(";
|
||||||
|
|
||||||
for (CompletionChunk chunk : cc.completion.chunks) {
|
for (CompletionChunk chunk : cc.completion.chunks) {
|
||||||
if (chunk.t != null) {
|
if (chunk.t != null) {
|
||||||
template += chunk.t;
|
template += chunk.t;
|
||||||
}
|
}
|
||||||
if (chunk.res != null) {
|
if (chunk.res != null) {
|
||||||
returnType = " - " + chunk.res;
|
returnType = chunk.res;
|
||||||
}
|
}
|
||||||
if (chunk.typedtext != null) {
|
if (chunk.typedtext != null) {
|
||||||
template += chunk.typedtext;
|
template += chunk.typedtext;
|
||||||
@ -143,16 +148,22 @@ public class ClangCompletionProvider extends LanguageAwareCompletionProvider {
|
|||||||
if (chunk.placeholder != null) {
|
if (chunk.placeholder != null) {
|
||||||
String[] spl = chunk.placeholder.split(" ");
|
String[] spl = chunk.placeholder.split(" ");
|
||||||
template += "${" + spl[spl.length - 1] + "}";
|
template += "${" + spl[spl.length - 1] + "}";
|
||||||
|
fancyParameters += spl[spl.length - 1] + ", ";
|
||||||
}
|
}
|
||||||
if (chunk.info != null) {
|
if (chunk.info != null) {
|
||||||
//System.out.println("INFO: "+chunk.info);
|
//System.out.println("INFO: "+chunk.info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
template += "${cursor}";
|
template += "${cursor}";
|
||||||
|
int lastComma = fancyParameters.lastIndexOf(",");
|
||||||
|
if (lastComma > 0) {
|
||||||
|
fancyParameters = fancyParameters.substring(0, lastComma);
|
||||||
|
}
|
||||||
|
fancyParameters += ")";
|
||||||
//System.out.println("TEMPLATE: " + template);
|
//System.out.println("TEMPLATE: " + template);
|
||||||
if (typedText.startsWith(getAlreadyEnteredText(textarea))) {
|
if (typedText.startsWith(getAlreadyEnteredText(textarea))) {
|
||||||
res.add(new TemplateCompletion(this, typedText, typedText + returnType,
|
TemplateCompletion compl = new TemplateCompletion(this, typedText, fancyParameters + " : " + returnType , template);
|
||||||
template));
|
res.add(compl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
|
@ -123,7 +123,8 @@ public class CompletionsRenderer extends DefaultListCellRenderer {
|
|||||||
text = ((ShorthandCompletion) value).getShortDescription();
|
text = ((ShorthandCompletion) value).getShortDescription();
|
||||||
tokenType = CompletionType.TEMPLATE;
|
tokenType = CompletionType.TEMPLATE;
|
||||||
} else if (value instanceof FunctionCompletion) {
|
} else if (value instanceof FunctionCompletion) {
|
||||||
text = ((FunctionCompletion) value).getShortDescription();
|
text = font(((FunctionCompletion) value).getInputText(), LIGHT_BLUE)
|
||||||
|
+ font(((FunctionCompletion) value).getShortDescription(), GRAY);
|
||||||
tokenType = CompletionType.FUNCTION;
|
tokenType = CompletionType.FUNCTION;
|
||||||
} else if (value instanceof BasicCompletion) {
|
} else if (value instanceof BasicCompletion) {
|
||||||
text = ((BasicCompletion) value).getInputText();
|
text = ((BasicCompletion) value).getInputText();
|
||||||
@ -133,7 +134,7 @@ public class CompletionsRenderer extends DefaultListCellRenderer {
|
|||||||
} else if (value instanceof TemplateCompletion) {
|
} else if (value instanceof TemplateCompletion) {
|
||||||
TemplateCompletion template = (TemplateCompletion) value;
|
TemplateCompletion template = (TemplateCompletion) value;
|
||||||
text = font(template.getInputText(), LIGHT_BLUE)
|
text = font(template.getInputText(), LIGHT_BLUE)
|
||||||
+ font(" - " + template.getDefinitionString(), GRAY);
|
+ font(template.getDefinitionString(), GRAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (text == null) {
|
if (text == null) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user