36
36
import javax .swing .text .JTextComponent ;
37
37
38
38
import org .fife .ui .autocomplete .Completion ;
39
+ import org .fife .ui .autocomplete .CompletionProvider ;
39
40
import org .fife .ui .autocomplete .DefaultCompletionProvider ;
40
41
import org .fife .ui .autocomplete .FunctionCompletion ;
42
+ import org .fife .ui .autocomplete .LanguageAwareCompletionProvider ;
41
43
import org .fife .ui .autocomplete .ParameterizedCompletion .Parameter ;
42
44
import org .fife .ui .autocomplete .TemplateCompletion ;
43
45
46
48
import processing .app .Editor ;
47
49
import processing .app .EditorTab ;
48
50
49
- public class ClangCompletionProvider extends DefaultCompletionProvider {
51
+ public class ClangCompletionProvider extends LanguageAwareCompletionProvider {
50
52
51
53
private Editor editor ;
54
+ private String completeCache ;
55
+ private int completeCacheLine ;
56
+ private int completeCacheColumn ;
52
57
53
- public ClangCompletionProvider (Editor e ) {
54
- super ();
58
+ public ClangCompletionProvider (Editor e , DefaultCompletionProvider cp ) {
59
+ super (cp );
55
60
editor = e ;
56
- setParameterizedCompletionParams ('(' , ", " , ')' );
57
- }
58
-
59
- @ Override
60
- public List <Completion > getCompletionByInputText (String inputText ) {
61
- System .out .println ("INPUTTEXT: " + inputText );
62
- return super .getCompletionByInputText (inputText );
61
+ //setParameterizedCompletionParams('(', ", ", ')');
63
62
}
64
63
65
64
@ Override
@@ -84,14 +83,21 @@ protected List<Completion> getCompletionsImpl(JTextComponent textarea) {
84
83
85
84
try {
86
85
// Run codecompletion engine
87
- String out = editor .getSketchController ()
86
+ String out = completeCache ;
87
+ if (completeCacheLine != line || (completeCacheColumn != (col + 1 )) && (completeCacheColumn != (col - 1 ))) {
88
+ out = editor .getSketchController ()
88
89
.codeComplete (tab .getSketchFile (), line , col );
90
+ completeCache = out ;
91
+ completeCacheLine = line ;
92
+ }
93
+ completeCacheColumn = col ;
89
94
90
95
// Parse engine output and build code completions
91
96
ObjectMapper mapper = new ObjectMapper ();
92
97
ArduinoCompletionsList allCc ;
93
98
allCc = mapper .readValue (out , ArduinoCompletionsList .class );
94
99
for (ArduinoCompletion cc : allCc ) {
100
+
95
101
if (cc .type .equals ("Macro" )) {
96
102
// for now skip macro
97
103
continue ;
@@ -108,6 +114,10 @@ protected List<Completion> getCompletionsImpl(JTextComponent textarea) {
108
114
}
109
115
}
110
116
117
+ if (!cc .getCompletion ().getTypedText ().startsWith (getAlreadyEnteredText (textarea ))) {
118
+ continue ;
119
+ }
120
+
111
121
FunctionCompletion compl = new FunctionCompletion (this ,
112
122
cc .getCompletion ().getTypedText (),
113
123
cc .getCompletion ().getResultType ());
@@ -135,13 +145,15 @@ protected List<Completion> getCompletionsImpl(JTextComponent textarea) {
135
145
template += "${" + spl [spl .length - 1 ] + "}" ;
136
146
}
137
147
if (chunk .info != null ) {
138
- System .out .println ("INFO: " +chunk .info );
148
+ // System.out.println("INFO: "+chunk.info);
139
149
}
140
150
}
141
151
template += "${cursor}" ;
142
- System .out .println ("TEMPLATE: " + template );
152
+ //System.out.println("TEMPLATE: " + template);
153
+ if (typedText .startsWith (getAlreadyEnteredText (textarea ))) {
143
154
res .add (new TemplateCompletion (this , typedText , typedText + returnType ,
144
155
template ));
156
+ }
145
157
}
146
158
return res ;
147
159
} catch (Exception e ) {
0 commit comments