@@ -304,6 +304,68 @@ export class ArduinoApp {
304
304
305
305
}
306
306
307
+ public tryToUpdateIncludePaths ( ) {
308
+ const configFilePath = path . join ( ArduinoWorkspace . rootPath , constants . CPP_CONFIG_FILE ) ;
309
+ if ( ! fs . existsSync ( configFilePath ) ) {
310
+ return ;
311
+ }
312
+ const cppConfigFile = fs . readFileSync ( configFilePath , "utf8" ) ;
313
+ const cppConfig = JSON . parse ( cppConfigFile ) as { configurations : Array < { includePath : string [ ] , forcedInclude : string [ ] } > } ;
314
+ const libPaths = this . getDefaultPackageLibPaths ( ) ;
315
+ const defaultForcedInclude = this . getDefaultForcedIncludeFiles ( ) ;
316
+ const configuration = cppConfig . configurations [ 0 ] ;
317
+
318
+ let cppConfigFileUpdated = false ;
319
+ // cpp exntension changes \\ to \\\\ in paths in JSON string, revert them first
320
+ configuration . includePath = configuration . includePath . map ( ( path ) => path . replace ( / \\ \\ / g, "\\" ) ) ;
321
+ configuration . forcedInclude = configuration . forcedInclude . map ( ( path ) => path . replace ( / \\ \\ / g, "\\" ) ) ;
322
+
323
+ for ( const libPath of libPaths ) {
324
+ if ( configuration . includePath . indexOf ( libPath ) === - 1 ) {
325
+ cppConfigFileUpdated = true ;
326
+ configuration . includePath . push ( libPath ) ;
327
+ }
328
+ }
329
+ for ( const forcedIncludePath of defaultForcedInclude ) {
330
+ if ( configuration . forcedInclude . indexOf ( forcedIncludePath ) === - 1 ) {
331
+ cppConfigFileUpdated = true ;
332
+ configuration . forcedInclude . push ( forcedIncludePath ) ;
333
+ }
334
+ }
335
+
336
+ // remove all unexisting paths
337
+ // concern mistake removal, comment temporary
338
+ // for (let pathIndex = 0; pathIndex < configuration.includePath.length; pathIndex++) {
339
+ // let libPath = configuration.includePath[pathIndex];
340
+ // if (libPath.indexOf("${workspaceFolder}") !== -1) {
341
+ // continue;
342
+ // }
343
+ // if (/\*$/.test(libPath)) {
344
+ // libPath = libPath.match(/^[^\*]*/)[0];
345
+ // }
346
+ // if (!fs.existsSync(libPath)) {
347
+ // cppConfigFileUpdated = true;
348
+ // configuration.includePath.splice(pathIndex, 1);
349
+ // pathIndex--;
350
+ // }
351
+ // }
352
+ // for (let pathIndex = 0; pathIndex < configuration.forcedInclude.length; pathIndex++) {
353
+ // const forcedIncludePath = configuration.forcedInclude[pathIndex];
354
+ // if (forcedIncludePath.indexOf("${workspaceFolder}") !== -1) {
355
+ // continue;
356
+ // }
357
+ // if (!fs.existsSync(forcedIncludePath)) {
358
+ // cppConfigFileUpdated = true;
359
+ // configuration.forcedInclude.splice(pathIndex, 1);
360
+ // pathIndex--;
361
+ // }
362
+ // }
363
+
364
+ if ( cppConfigFileUpdated ) {
365
+ fs . writeFileSync ( configFilePath , JSON . stringify ( cppConfig , null , 4 ) ) ;
366
+ }
367
+ }
368
+
307
369
// Add selected library path to the intellisense search path.
308
370
public addLibPath ( libraryPath : string ) {
309
371
let libPaths ;
0 commit comments