mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-26 20:54:22 +01:00
autocomplete: extracted ArduinoCompletion to Completion generation method
This commit is contained in:
parent
385a6738e9
commit
3d6af521db
@ -36,7 +36,6 @@ import javax.swing.text.BadLocationException;
|
|||||||
import javax.swing.text.JTextComponent;
|
import javax.swing.text.JTextComponent;
|
||||||
|
|
||||||
import org.fife.ui.autocomplete.Completion;
|
import org.fife.ui.autocomplete.Completion;
|
||||||
import org.fife.ui.autocomplete.CompletionProvider;
|
|
||||||
import org.fife.ui.autocomplete.DefaultCompletionProvider;
|
import org.fife.ui.autocomplete.DefaultCompletionProvider;
|
||||||
import org.fife.ui.autocomplete.FunctionCompletion;
|
import org.fife.ui.autocomplete.FunctionCompletion;
|
||||||
import org.fife.ui.autocomplete.LanguageAwareCompletionProvider;
|
import org.fife.ui.autocomplete.LanguageAwareCompletionProvider;
|
||||||
@ -117,48 +116,59 @@ public class ClangCompletionProvider extends LanguageAwareCompletionProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String enteredText = getAlreadyEnteredText(textarea);
|
String enteredText = getAlreadyEnteredText(textarea);
|
||||||
|
|
||||||
for (ArduinoCompletion cc : allCc) {
|
for (ArduinoCompletion cc : allCc) {
|
||||||
// Filter completions based on already entered text
|
// Filter completions based on already entered text
|
||||||
if (!cc.getCompletion().getTypedText().startsWith(enteredText)) {
|
if (!cc.getCompletion().getTypedText().startsWith(enteredText)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Completion completion = createCompletionFromArduinoCompletion(cc);
|
||||||
|
res.add(completion);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Completion createCompletionFromArduinoCompletion(ArduinoCompletion cc) {
|
||||||
if (cc.type.equals("Function")) {
|
if (cc.type.equals("Function")) {
|
||||||
List<Parameter> params = new ArrayList<>();
|
List<Parameter> params = new ArrayList<>();
|
||||||
int i=0;
|
int i = 0;
|
||||||
String fancyParameters = "(";
|
String shortDesc = "(";
|
||||||
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) + ", ";
|
shortDesc += (p.name.equals("") ? p.type : p.name) + ", ";
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int lastComma = fancyParameters.lastIndexOf(",");
|
int lastComma = shortDesc.lastIndexOf(",");
|
||||||
if (lastComma > 0) {
|
if (lastComma > 0) {
|
||||||
fancyParameters = fancyParameters.substring(0, lastComma);
|
shortDesc = shortDesc.substring(0, lastComma);
|
||||||
}
|
}
|
||||||
fancyParameters += ")";
|
shortDesc += ")";
|
||||||
|
|
||||||
FunctionCompletion compl = new FunctionCompletion(this,
|
FunctionCompletion compl = new FunctionCompletion(this,
|
||||||
cc.getCompletion().getTypedText(),
|
cc.getCompletion().getTypedText(),
|
||||||
cc.getCompletion().getResultType());
|
cc.getCompletion().getResultType());
|
||||||
compl.setParams(params);
|
compl.setParams(params);
|
||||||
compl.setShortDescription(fancyParameters + " : " + cc.getCompletion().getResultType());
|
compl.setShortDescription(shortDesc + " : "
|
||||||
res.add(compl);
|
+ cc.getCompletion().getResultType());
|
||||||
continue;
|
return compl;
|
||||||
}
|
} else {
|
||||||
|
|
||||||
String returnType = "";
|
String returnType = "";
|
||||||
String typedText = null;
|
String typedText = null;
|
||||||
String template = "";
|
String template = "";
|
||||||
String fancyParameters = "(";
|
String shortDesc = "";
|
||||||
|
|
||||||
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;
|
||||||
|
shortDesc += chunk.t;
|
||||||
}
|
}
|
||||||
if (chunk.res != null) {
|
if (chunk.res != null) {
|
||||||
returnType = chunk.res;
|
returnType = chunk.res;
|
||||||
@ -170,26 +180,21 @@ 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] + ", ";
|
shortDesc += 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(",");
|
int lastComma = shortDesc.lastIndexOf(",");
|
||||||
if (lastComma > 0) {
|
if (lastComma > 0) {
|
||||||
fancyParameters = fancyParameters.substring(0, lastComma);
|
shortDesc = shortDesc.substring(0, lastComma);
|
||||||
}
|
}
|
||||||
fancyParameters += ")";
|
shortDesc += ")";
|
||||||
//System.out.println("TEMPLATE: " + template);
|
System.out.println("TEMPLATE: " + template);
|
||||||
TemplateCompletion compl = new TemplateCompletion(this, typedText, fancyParameters + " : " + returnType , template);
|
return new TemplateCompletion(this, typedText,
|
||||||
res.add(compl);
|
shortDesc + " : " + returnType, template);
|
||||||
}
|
|
||||||
return res;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user