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

Quick fix for Intellisense #1144

Merged
merged 6 commits into from
Nov 20, 2020
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion 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.getDefualtDefines();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: typo

const configuration = cppConfig.configurations[0];

let cppConfigFileUpdated = false;
// cpp exntension 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.getDefualtDefines();

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,12 @@ Please make sure the folder is not occupied by other procedures .`);
return result;
}

public getDefualtDefines(): string[] {
const result = [];
result.push("USBCON");
return result;
}

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