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

Commit 03ca266

Browse files
authored
Quick fix for Intellisense (#1144)
* add hardware tool path * intellisense quick fix * add hardware tool path * intellisense quick fix * fix typo
1 parent 8fc91d6 commit 03ca266

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

src/arduino/arduino.ts

+36-2
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.getDefaultDefines();
326331
const configuration = cppConfig.configurations[0];
327332

328333
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
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.getDefaultDefines();
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

@@ -577,6 +594,16 @@ Please make sure the folder is not occupied by other procedures .`);
577594
}
578595
const toolsPath = boardDescriptor.platform.rootBoardPath;
579596
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);
580607
// if (util.directoryExistsSync(path.join(toolsPath, "cores"))) {
581608
// const coreLibs = fs.readdirSync(path.join(toolsPath, "cores"));
582609
// if (coreLibs && coreLibs.length > 0) {
@@ -608,6 +635,13 @@ Please make sure the folder is not occupied by other procedures .`);
608635
return result;
609636
}
610637

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+
611645
public openExample(example) {
612646
function tmpName(name) {
613647
let counter = 0;

0 commit comments

Comments
 (0)