|
36 | 36 | import javax.swing.text.JTextComponent;
|
37 | 37 |
|
38 | 38 | import org.fife.ui.autocomplete.Completion;
|
39 |
| -import org.fife.ui.autocomplete.CompletionProvider; |
40 | 39 | import org.fife.ui.autocomplete.DefaultCompletionProvider;
|
41 | 40 | import org.fife.ui.autocomplete.FunctionCompletion;
|
42 | 41 | import org.fife.ui.autocomplete.LanguageAwareCompletionProvider;
|
@@ -117,79 +116,85 @@ protected List<Completion> getCompletionsImpl(JTextComponent textarea) {
|
117 | 116 | }
|
118 | 117 |
|
119 | 118 | String enteredText = getAlreadyEnteredText(textarea);
|
120 |
| - |
121 | 119 | for (ArduinoCompletion cc : allCc) {
|
122 | 120 | // Filter completions based on already entered text
|
123 | 121 | if (!cc.getCompletion().getTypedText().startsWith(enteredText)) {
|
124 | 122 | continue;
|
125 | 123 | }
|
126 | 124 |
|
127 |
| - if (cc.type.equals("Function")) { |
128 |
| - List<Parameter> params = new ArrayList<>(); |
129 |
| - int i=0; |
130 |
| - String fancyParameters = "("; |
131 |
| - for (CompletionChunk chunk : cc.completion.chunks) { |
132 |
| - if (chunk.placeholder != null) { |
133 |
| - ArduinoParameter p = cc.parameters.get(i); |
134 |
| - params.add(new Parameter(p.type, p.name)); |
135 |
| - fancyParameters += (p.name.equals("") ? p.type : p.name) + ", "; |
136 |
| - i++; |
137 |
| - } |
138 |
| - } |
139 |
| - int lastComma = fancyParameters.lastIndexOf(","); |
140 |
| - if (lastComma > 0) { |
141 |
| - fancyParameters = fancyParameters.substring(0, lastComma); |
142 |
| - } |
143 |
| - fancyParameters += ")"; |
144 |
| - |
145 |
| - FunctionCompletion compl = new FunctionCompletion(this, |
146 |
| - cc.getCompletion().getTypedText(), |
147 |
| - cc.getCompletion().getResultType()); |
148 |
| - compl.setParams(params); |
149 |
| - compl.setShortDescription(fancyParameters + " : " + cc.getCompletion().getResultType()); |
150 |
| - res.add(compl); |
151 |
| - continue; |
152 |
| - } |
153 |
| - |
154 |
| - String returnType = ""; |
155 |
| - String typedText = null; |
156 |
| - String template = ""; |
157 |
| - String fancyParameters = "("; |
158 |
| - |
159 |
| - for (CompletionChunk chunk : cc.completion.chunks) { |
160 |
| - if (chunk.t != null) { |
161 |
| - template += chunk.t; |
162 |
| - } |
163 |
| - if (chunk.res != null) { |
164 |
| - returnType = chunk.res; |
165 |
| - } |
166 |
| - if (chunk.typedtext != null) { |
167 |
| - template += chunk.typedtext; |
168 |
| - typedText = chunk.typedtext; |
169 |
| - } |
170 |
| - if (chunk.placeholder != null) { |
171 |
| - String[] spl = chunk.placeholder.split(" "); |
172 |
| - template += "${" + spl[spl.length - 1] + "}"; |
173 |
| - fancyParameters += spl[spl.length - 1] + ", "; |
174 |
| - } |
175 |
| - if (chunk.info != null) { |
176 |
| - //System.out.println("INFO: "+chunk.info); |
177 |
| - } |
178 |
| - } |
179 |
| - template += "${cursor}"; |
180 |
| - int lastComma = fancyParameters.lastIndexOf(","); |
181 |
| - if (lastComma > 0) { |
182 |
| - fancyParameters = fancyParameters.substring(0, lastComma); |
183 |
| - } |
184 |
| - fancyParameters += ")"; |
185 |
| - //System.out.println("TEMPLATE: " + template); |
186 |
| - TemplateCompletion compl = new TemplateCompletion(this, typedText, fancyParameters + " : " + returnType , template); |
187 |
| - res.add(compl); |
| 125 | + Completion completion = createCompletionFromArduinoCompletion(cc); |
| 126 | + res.add(completion); |
188 | 127 | }
|
189 | 128 | return res;
|
190 | 129 | } catch (Exception e) {
|
191 | 130 | e.printStackTrace();
|
192 | 131 | return res;
|
193 | 132 | }
|
194 | 133 | }
|
| 134 | + |
| 135 | + private Completion createCompletionFromArduinoCompletion(ArduinoCompletion cc) { |
| 136 | + if (cc.type.equals("Function")) { |
| 137 | + List<Parameter> params = new ArrayList<>(); |
| 138 | + int i = 0; |
| 139 | + String shortDesc = "("; |
| 140 | + for (CompletionChunk chunk : cc.completion.chunks) { |
| 141 | + if (chunk.placeholder != null) { |
| 142 | + ArduinoParameter p = cc.parameters.get(i); |
| 143 | + params.add(new Parameter(p.type, p.name)); |
| 144 | + shortDesc += (p.name.equals("") ? p.type : p.name) + ", "; |
| 145 | + i++; |
| 146 | + } |
| 147 | + } |
| 148 | + int lastComma = shortDesc.lastIndexOf(","); |
| 149 | + if (lastComma > 0) { |
| 150 | + shortDesc = shortDesc.substring(0, lastComma); |
| 151 | + } |
| 152 | + shortDesc += ")"; |
| 153 | + |
| 154 | + FunctionCompletion compl = new FunctionCompletion(this, |
| 155 | + cc.getCompletion().getTypedText(), |
| 156 | + cc.getCompletion().getResultType()); |
| 157 | + compl.setParams(params); |
| 158 | + compl.setShortDescription(shortDesc + " : " |
| 159 | + + cc.getCompletion().getResultType()); |
| 160 | + return compl; |
| 161 | + } else { |
| 162 | + |
| 163 | + String returnType = ""; |
| 164 | + String typedText = null; |
| 165 | + String template = ""; |
| 166 | + String shortDesc = ""; |
| 167 | + |
| 168 | + for (CompletionChunk chunk : cc.completion.chunks) { |
| 169 | + if (chunk.t != null) { |
| 170 | + template += chunk.t; |
| 171 | + shortDesc += chunk.t; |
| 172 | + } |
| 173 | + if (chunk.res != null) { |
| 174 | + returnType = chunk.res; |
| 175 | + } |
| 176 | + if (chunk.typedtext != null) { |
| 177 | + template += chunk.typedtext; |
| 178 | + typedText = chunk.typedtext; |
| 179 | + } |
| 180 | + if (chunk.placeholder != null) { |
| 181 | + String[] spl = chunk.placeholder.split(" "); |
| 182 | + template += "${" + spl[spl.length - 1] + "}"; |
| 183 | + shortDesc += spl[spl.length - 1] + ", "; |
| 184 | + } |
| 185 | + if (chunk.info != null) { |
| 186 | + // System.out.println("INFO: "+chunk.info); |
| 187 | + } |
| 188 | + } |
| 189 | + template += "${cursor}"; |
| 190 | + int lastComma = shortDesc.lastIndexOf(","); |
| 191 | + if (lastComma > 0) { |
| 192 | + shortDesc = shortDesc.substring(0, lastComma); |
| 193 | + } |
| 194 | + shortDesc += ")"; |
| 195 | + System.out.println("TEMPLATE: " + template); |
| 196 | + return new TemplateCompletion(this, typedText, |
| 197 | + shortDesc + " : " + returnType, template); |
| 198 | + } |
| 199 | + } |
195 | 200 | }
|
0 commit comments