Skip to content
This repository was archived by the owner on Oct 1, 2024. It is now read-only.

Commit 5878335

Browse files
committed
intellisense quick fix
1 parent 7a21b5b commit 5878335

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

src/arduino/arduino.ts

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,15 +320,21 @@ export class ArduinoApp {
320320
return;
321321
}
322322
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+
}> };
324328
const libPaths = this.getDefaultPackageLibPaths();
325329
const defaultForcedInclude = this.getDefaultForcedIncludeFiles();
330+
const defines = this.getDefualtDefines();
326331
const configuration = cppConfig.configurations[0];
327332

328333
let cppConfigFileUpdated = false;
329334
// cpp exntension changes \\ to \\\\ in paths in JSON string, revert them first
330335
configuration.includePath = configuration.includePath.map((path) => path.replace(/\\\\/g, "\\"));
331336
configuration.forcedInclude = configuration.forcedInclude.map((path) => path.replace(/\\\\/g, "\\"));
337+
configuration.defines = configuration.defines.map((path) => path.replace(/\\\\/g, "\\"));
332338

333339
for (const libPath of libPaths) {
334340
if (configuration.includePath.indexOf(libPath) === -1) {
@@ -343,6 +349,12 @@ export class ArduinoApp {
343349
}
344350
}
345351

352+
for (const define of defines) {
353+
if (configuration.defines.indexOf(define) === -1) {
354+
cppConfigFileUpdated = true;
355+
configuration.defines.push(define);
356+
}
357+
}
346358
// remove all unexisting paths
347359
// concern mistake removal, comment temporary
348360
// for (let pathIndex = 0; pathIndex < configuration.includePath.length; pathIndex++) {
@@ -386,6 +398,7 @@ export class ArduinoApp {
386398
}
387399

388400
const defaultForcedInclude = this.getDefaultForcedIncludeFiles();
401+
const defaultDefines = this.getDefualtDefines();
389402

390403
if (!ArduinoWorkspace.rootPath) {
391404
return;
@@ -444,6 +457,10 @@ export class ArduinoApp {
444457
configSection.forcedInclude = defaultForcedInclude.concat(configSection.forcedInclude);
445458
}
446459

460+
if (!configSection.defines) {
461+
configSection.defines = defaultDefines;
462+
}
463+
447464
fs.writeFileSync(configFilePath, JSON.stringify(deviceContext, null, 4));
448465
}
449466

@@ -578,9 +595,15 @@ Please make sure the folder is not occupied by other procedures .`);
578595
const toolsPath = boardDescriptor.platform.rootBoardPath;
579596
result.push(path.normalize(path.join(toolsPath, "**")));
580597
const hardwareToolPath = path.join(toolsPath, "..", "..", "tools");
581-
if (fs.existsSync(hardwareToolPath)){
598+
if (fs.existsSync(hardwareToolPath)) {
582599
result.push(path.normalize(path.join(hardwareToolPath, "**")));
583-
}
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);
584607
// if (util.directoryExistsSync(path.join(toolsPath, "cores"))) {
585608
// const coreLibs = fs.readdirSync(path.join(toolsPath, "cores"));
586609
// if (coreLibs && coreLibs.length > 0) {
@@ -612,6 +635,12 @@ Please make sure the folder is not occupied by other procedures .`);
612635
return result;
613636
}
614637

638+
public getDefualtDefines(): string[] {
639+
const result = [];
640+
result.push("USBCON");
641+
return result;
642+
}
643+
615644
public openExample(example) {
616645
function tmpName(name) {
617646
let counter = 0;

0 commit comments

Comments
 (0)