Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/arduino/Arduino.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCristian Maglie <c.maglie@arduino.cc>2017-10-17 13:27:15 +0300
committerMartino Facchin <m.facchin@arduino.cc>2020-04-07 15:09:06 +0300
commit3d6af521db9861191368b377909ccb864579a337 (patch)
tree6e6fc6ec98151732ac852a37f97687485cdde074
parent385a6738e928b83d319c13209214977c54eacc3e (diff)
autocomplete: extracted ArduinoCompletion to Completion generation method
-rw-r--r--app/src/cc/arduino/autocomplete/ClangCompletionProvider.java131
1 files changed, 68 insertions, 63 deletions
diff --git a/app/src/cc/arduino/autocomplete/ClangCompletionProvider.java b/app/src/cc/arduino/autocomplete/ClangCompletionProvider.java
index 7ca7b937c..5ee4464bc 100644
--- a/app/src/cc/arduino/autocomplete/ClangCompletionProvider.java
+++ b/app/src/cc/arduino/autocomplete/ClangCompletionProvider.java
@@ -36,7 +36,6 @@ import javax.swing.text.BadLocationException;
import javax.swing.text.JTextComponent;
import org.fife.ui.autocomplete.Completion;
-import org.fife.ui.autocomplete.CompletionProvider;
import org.fife.ui.autocomplete.DefaultCompletionProvider;
import org.fife.ui.autocomplete.FunctionCompletion;
import org.fife.ui.autocomplete.LanguageAwareCompletionProvider;
@@ -117,74 +116,14 @@ public class ClangCompletionProvider extends LanguageAwareCompletionProvider {
}
String enteredText = getAlreadyEnteredText(textarea);
-
for (ArduinoCompletion cc : allCc) {
// Filter completions based on already entered text
if (!cc.getCompletion().getTypedText().startsWith(enteredText)) {
continue;
}
- if (cc.type.equals("Function")) {
- List<Parameter> params = new ArrayList<>();
- int i=0;
- String fancyParameters = "(";
- for (CompletionChunk chunk : cc.completion.chunks) {
- if (chunk.placeholder != null) {
- ArduinoParameter p = cc.parameters.get(i);
- params.add(new Parameter(p.type, p.name));
- fancyParameters += (p.name.equals("") ? p.type : p.name) + ", ";
- i++;
- }
- }
- int lastComma = fancyParameters.lastIndexOf(",");
- if (lastComma > 0) {
- fancyParameters = fancyParameters.substring(0, lastComma);
- }
- fancyParameters += ")";
-
- FunctionCompletion compl = new FunctionCompletion(this,
- cc.getCompletion().getTypedText(),
- cc.getCompletion().getResultType());
- compl.setParams(params);
- compl.setShortDescription(fancyParameters + " : " + cc.getCompletion().getResultType());
- res.add(compl);
- continue;
- }
-
- String returnType = "";
- String typedText = null;
- String template = "";
- String fancyParameters = "(";
-
- for (CompletionChunk chunk : cc.completion.chunks) {
- if (chunk.t != null) {
- template += chunk.t;
- }
- if (chunk.res != null) {
- returnType = chunk.res;
- }
- if (chunk.typedtext != null) {
- template += chunk.typedtext;
- typedText = chunk.typedtext;
- }
- if (chunk.placeholder != null) {
- String[] spl = chunk.placeholder.split(" ");
- template += "${" + spl[spl.length - 1] + "}";
- fancyParameters += spl[spl.length - 1] + ", ";
- }
- if (chunk.info != null) {
- //System.out.println("INFO: "+chunk.info);
- }
- }
- template += "${cursor}";
- int lastComma = fancyParameters.lastIndexOf(",");
- if (lastComma > 0) {
- fancyParameters = fancyParameters.substring(0, lastComma);
- }
- fancyParameters += ")";
- //System.out.println("TEMPLATE: " + template);
- TemplateCompletion compl = new TemplateCompletion(this, typedText, fancyParameters + " : " + returnType , template);
- res.add(compl);
+ Completion completion = createCompletionFromArduinoCompletion(cc);
+ res.add(completion);
}
return res;
} catch (Exception e) {
@@ -192,4 +131,70 @@ public class ClangCompletionProvider extends LanguageAwareCompletionProvider {
return res;
}
}
+
+ private Completion createCompletionFromArduinoCompletion(ArduinoCompletion cc) {
+ if (cc.type.equals("Function")) {
+ List<Parameter> params = new ArrayList<>();
+ int i = 0;
+ String shortDesc = "(";
+ for (CompletionChunk chunk : cc.completion.chunks) {
+ if (chunk.placeholder != null) {
+ ArduinoParameter p = cc.parameters.get(i);
+ params.add(new Parameter(p.type, p.name));
+ shortDesc += (p.name.equals("") ? p.type : p.name) + ", ";
+ i++;
+ }
+ }
+ int lastComma = shortDesc.lastIndexOf(",");
+ if (lastComma > 0) {
+ shortDesc = shortDesc.substring(0, lastComma);
+ }
+ shortDesc += ")";
+
+ FunctionCompletion compl = new FunctionCompletion(this,
+ cc.getCompletion().getTypedText(),
+ cc.getCompletion().getResultType());
+ compl.setParams(params);
+ compl.setShortDescription(shortDesc + " : "
+ + cc.getCompletion().getResultType());
+ return compl;
+ } else {
+
+ String returnType = "";
+ String typedText = null;
+ String template = "";
+ String shortDesc = "";
+
+ for (CompletionChunk chunk : cc.completion.chunks) {
+ if (chunk.t != null) {
+ template += chunk.t;
+ shortDesc += chunk.t;
+ }
+ if (chunk.res != null) {
+ returnType = chunk.res;
+ }
+ if (chunk.typedtext != null) {
+ template += chunk.typedtext;
+ typedText = chunk.typedtext;
+ }
+ if (chunk.placeholder != null) {
+ String[] spl = chunk.placeholder.split(" ");
+ template += "${" + 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);
+ }
+ }
}