@@ -125,7 +125,7 @@ public class Compiler implements MessageConsumer {
125125 }
126126
127127 enum BuilderAction {
128- COMPILE ("-compile" ), DUMP_PREFS ("-dump-prefs" );
128+ COMPILE ("-compile" ), DUMP_PREFS ("-dump-prefs" ), CODE_COMPLETE ( "-code-complete-at" ) ;
129129
130130 final String value ;
131131
@@ -143,6 +143,10 @@ enum BuilderAction {
143143 private final boolean verbose ;
144144 private RunnerException exception ;
145145
146+ private File codeCompleteFile ;
147+ private int codeCompleteLine ;
148+ private int codeCompleteCol ;
149+
146150 public Compiler (Sketch data ) {
147151 this (data .getPrimaryFile ().getFile (), data );
148152 }
@@ -193,6 +197,34 @@ public String build(List<CompilerProgressListener> progListeners, boolean export
193197 return sketch .getPrimaryFile ().getFileName ();
194198 }
195199
200+ public String codeComplete (ArrayList <CompilerProgressListener > progListeners , File file , int line , int col ) throws RunnerException , PreferencesMapException , IOException {
201+ this .buildPath = sketch .getBuildPath ().getAbsolutePath ();
202+ this .buildCache = BaseNoGui .getCachePath ();
203+
204+ TargetBoard board = BaseNoGui .getTargetBoard ();
205+ if (board == null ) {
206+ throw new RunnerException ("Board is not selected" );
207+ }
208+
209+ TargetPlatform platform = board .getContainerPlatform ();
210+ TargetPackage aPackage = platform .getContainerPackage ();
211+ String vidpid = VIDPID ();
212+
213+ ByteArrayOutputStream completions = new ByteArrayOutputStream ();
214+ MessageConsumerOutputStream out = new MessageConsumerOutputStream (new ProgressAwareMessageConsumer (new I18NAwareMessageConsumer (new PrintStream (completions ), System .err ), progListeners ), "\n " );
215+ MessageConsumerOutputStream err = new MessageConsumerOutputStream (new I18NAwareMessageConsumer (System .err , Compiler .this ), "\n " );
216+
217+ codeCompleteFile = file ;
218+ codeCompleteLine = line ;
219+ codeCompleteCol = col ;
220+ callArduinoBuilder (board , platform , aPackage , vidpid , BuilderAction .CODE_COMPLETE , out , err );
221+
222+ out .flush ();
223+ err .flush ();
224+
225+ return completions .toString ();
226+ }
227+
196228 private String VIDPID () {
197229 BoardPort boardPort = BaseNoGui .getDiscoveryManager ().find (PreferencesData .get ("serial.port" ));
198230 if (boardPort == null ) {
@@ -234,6 +266,9 @@ private void callArduinoBuilder(TargetBoard board, TargetPlatform platform, Targ
234266 List <String > cmd = new ArrayList <>();
235267 cmd .add (BaseNoGui .getContentFile ("arduino-builder" ).getAbsolutePath ());
236268 cmd .add (action .value );
269+ if (action == BuilderAction .CODE_COMPLETE ) {
270+ cmd .add (codeCompleteFile .getAbsolutePath () + ":" + codeCompleteLine + ":" + codeCompleteCol );
271+ }
237272 cmd .add ("-logger=machine" );
238273
239274 File installedPackagesFolder = new File (BaseNoGui .getSettingsFolder (), "packages" );
@@ -280,9 +315,7 @@ private void callArduinoBuilder(TargetBoard board, TargetPlatform platform, Targ
280315 }
281316 }
282317
283- //commandLine.addArgument("-debug-level=10", false);
284-
285- if (verbose ) {
318+ if (verbose && action != BuilderAction .CODE_COMPLETE ) {
286319 cmd .add ("-verbose" );
287320 }
288321
0 commit comments