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

Commit

Permalink
Quick fix for Intellisense (#1144)
Browse files Browse the repository at this point in the history
* add hardware tool path

* intellisense quick fix

* add hardware tool path

* intellisense quick fix

* fix typo
  • Loading branch information
adiazulay authored Nov 20, 2020
1 parent 8fc91d6 commit 03ca266
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions src/arduino/arduino.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,15 +320,21 @@ export class ArduinoApp {
return;
}
const cppConfigFile = fs.readFileSync(configFilePath, "utf8");
const cppConfig = JSON.parse(cppConfigFile) as { configurations: Array<{ includePath: string[], forcedInclude: string[] }> };
const cppConfig = JSON.parse(cppConfigFile) as { configurations: Array<{
includePath: string[],
forcedInclude: string[],
defines: string[],
}> };
const libPaths = this.getDefaultPackageLibPaths();
const defaultForcedInclude = this.getDefaultForcedIncludeFiles();
const defines = this.getDefaultDefines();
const configuration = cppConfig.configurations[0];

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

for (const libPath of libPaths) {
if (configuration.includePath.indexOf(libPath) === -1) {
Expand All @@ -343,6 +349,12 @@ export class ArduinoApp {
}
}

for (const define of defines) {
if (configuration.defines.indexOf(define) === -1) {
cppConfigFileUpdated = true;
configuration.defines.push(define);
}
}
// remove all unexisting paths
// concern mistake removal, comment temporary
// for (let pathIndex = 0; pathIndex < configuration.includePath.length; pathIndex++) {
Expand Down Expand Up @@ -386,6 +398,7 @@ export class ArduinoApp {
}

const defaultForcedInclude = this.getDefaultForcedIncludeFiles();
const defaultDefines = this.getDefaultDefines();

if (!ArduinoWorkspace.rootPath) {
return;
Expand Down Expand Up @@ -444,6 +457,10 @@ export class ArduinoApp {
configSection.forcedInclude = defaultForcedInclude.concat(configSection.forcedInclude);
}

if (!configSection.defines) {
configSection.defines = defaultDefines;
}

fs.writeFileSync(configFilePath, JSON.stringify(deviceContext, null, 4));
}

Expand Down Expand Up @@ -577,6 +594,16 @@ Please make sure the folder is not occupied by other procedures .`);
}
const toolsPath = boardDescriptor.platform.rootBoardPath;
result.push(path.normalize(path.join(toolsPath, "**")));
const hardwareToolPath = path.join(toolsPath, "..", "..", "tools");
if (fs.existsSync(hardwareToolPath)) {
result.push(path.normalize(path.join(hardwareToolPath, "**")));
}

// Add default libraries to include path
result.push(path.normalize(path.join(this._settings.defaultLibPath, "**")));

const userLibsPath = (path.join(this._settings.sketchbookPath, "libraries", "**"));
result.push(userLibsPath);
// if (util.directoryExistsSync(path.join(toolsPath, "cores"))) {
// const coreLibs = fs.readdirSync(path.join(toolsPath, "cores"));
// if (coreLibs && coreLibs.length > 0) {
Expand Down Expand Up @@ -608,6 +635,13 @@ Please make sure the folder is not occupied by other procedures .`);
return result;
}

public getDefaultDefines(): string[] {
const result = [];
// USBCON is required in order for Serial to be recognized by intellisense
result.push("USBCON");
return result;
}

public openExample(example) {
function tmpName(name) {
let counter = 0;
Expand Down

0 comments on commit 03ca266

Please sign in to comment.