@@ -320,15 +320,21 @@ export class ArduinoApp {
320
320
return ;
321
321
}
322
322
const cppConfigFile = fs . readFileSync ( configFilePath , "utf8" ) ;
323
- const cppConfig = JSON . parse ( cppConfigFile ) as { configurations : Array < { includePath : string [ ] , forcedInclude : string [ ] } > } ;
323
+ const cppConfig = JSON . parse ( cppConfigFile ) as { configurations : Array < {
324
+ includePath : string [ ] ,
325
+ forcedInclude : string [ ] ,
326
+ defines : string [ ] ,
327
+ } > } ;
324
328
const libPaths = this . getDefaultPackageLibPaths ( ) ;
325
329
const defaultForcedInclude = this . getDefaultForcedIncludeFiles ( ) ;
330
+ const defines = this . getDefaultDefines ( ) ;
326
331
const configuration = cppConfig . configurations [ 0 ] ;
327
332
328
333
let cppConfigFileUpdated = false ;
329
- // cpp exntension changes \\ to \\\\ in paths in JSON string, revert them first
334
+ // cpp extension changes \\ to \\\\ in paths in JSON string, revert them first
330
335
configuration . includePath = configuration . includePath . map ( ( path ) => path . replace ( / \\ \\ / g, "\\" ) ) ;
331
336
configuration . forcedInclude = configuration . forcedInclude . map ( ( path ) => path . replace ( / \\ \\ / g, "\\" ) ) ;
337
+ configuration . defines = configuration . defines . map ( ( path ) => path . replace ( / \\ \\ / g, "\\" ) ) ;
332
338
333
339
for ( const libPath of libPaths ) {
334
340
if ( configuration . includePath . indexOf ( libPath ) === - 1 ) {
@@ -343,6 +349,12 @@ export class ArduinoApp {
343
349
}
344
350
}
345
351
352
+ for ( const define of defines ) {
353
+ if ( configuration . defines . indexOf ( define ) === - 1 ) {
354
+ cppConfigFileUpdated = true ;
355
+ configuration . defines . push ( define ) ;
356
+ }
357
+ }
346
358
// remove all unexisting paths
347
359
// concern mistake removal, comment temporary
348
360
// for (let pathIndex = 0; pathIndex < configuration.includePath.length; pathIndex++) {
@@ -386,6 +398,7 @@ export class ArduinoApp {
386
398
}
387
399
388
400
const defaultForcedInclude = this . getDefaultForcedIncludeFiles ( ) ;
401
+ const defaultDefines = this . getDefaultDefines ( ) ;
389
402
390
403
if ( ! ArduinoWorkspace . rootPath ) {
391
404
return ;
@@ -444,6 +457,10 @@ export class ArduinoApp {
444
457
configSection . forcedInclude = defaultForcedInclude . concat ( configSection . forcedInclude ) ;
445
458
}
446
459
460
+ if ( ! configSection . defines ) {
461
+ configSection . defines = defaultDefines ;
462
+ }
463
+
447
464
fs . writeFileSync ( configFilePath , JSON . stringify ( deviceContext , null , 4 ) ) ;
448
465
}
449
466
@@ -577,6 +594,16 @@ Please make sure the folder is not occupied by other procedures .`);
577
594
}
578
595
const toolsPath = boardDescriptor . platform . rootBoardPath ;
579
596
result . push ( path . normalize ( path . join ( toolsPath , "**" ) ) ) ;
597
+ const hardwareToolPath = path . join ( toolsPath , ".." , ".." , "tools" ) ;
598
+ if ( fs . existsSync ( hardwareToolPath ) ) {
599
+ result . push ( path . normalize ( path . join ( hardwareToolPath , "**" ) ) ) ;
600
+ }
601
+
602
+ // Add default libraries to include path
603
+ result . push ( path . normalize ( path . join ( this . _settings . defaultLibPath , "**" ) ) ) ;
604
+
605
+ const userLibsPath = ( path . join ( this . _settings . sketchbookPath , "libraries" , "**" ) ) ;
606
+ result . push ( userLibsPath ) ;
580
607
// if (util.directoryExistsSync(path.join(toolsPath, "cores"))) {
581
608
// const coreLibs = fs.readdirSync(path.join(toolsPath, "cores"));
582
609
// if (coreLibs && coreLibs.length > 0) {
@@ -608,6 +635,13 @@ Please make sure the folder is not occupied by other procedures .`);
608
635
return result ;
609
636
}
610
637
638
+ public getDefaultDefines ( ) : string [ ] {
639
+ const result = [ ] ;
640
+ // USBCON is required in order for Serial to be recognized by intellisense
641
+ result . push ( "USBCON" ) ;
642
+ return result ;
643
+ }
644
+
611
645
public openExample ( example ) {
612
646
function tmpName ( name ) {
613
647
let counter = 0 ;
0 commit comments