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

Commit

Permalink
Filter out invalid include directories
Browse files Browse the repository at this point in the history
* Filtering out invalid include directories (discovered when compiling for ESP8266)
* Compacted IntelliSense message and hint to manual build into a single line
  • Loading branch information
elektronikworkshop authored and adiazulay committed Jan 19, 2021
1 parent 194dc92 commit fed508f
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions src/arduino/intellisense.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ export function makeCompilerParserContext(dc: DeviceContext): ICoCoPaContext {
// Normalize compiler and include paths (resolve ".." and ".")
runner.result.normalize();

runner.result.includes = await removeInvalidDirs(runner.result.includes);

// Search for Arduino.h in the include paths - we need it for a
// forced include - users expect Arduino symbols to be available
// in main sketch without having to include the header explicitly
Expand All @@ -90,30 +92,51 @@ export function makeCompilerParserContext(dc: DeviceContext): ICoCoPaContext {
ccp.CCppPropertiesCppStandard.Cpp11,
forcedIncludes);
try {
const cmd = os.platform() === "darwin"
? "Cmd + Alt + I"
: "Ctrl + Alt + I";
const help = `To manually rebuild your IntelliSense configuration run "${cmd}"`;
const pPath = path.join(ArduinoWorkspace.rootPath, constants.CPP_CONFIG_FILE);
const prop = new ccp.CCppProperties();
prop.read(pPath);
prop.merge(content, ccp.CCppPropertiesMergeMode.ReplaceSameNames);
if (prop.write(pPath)) {
arduinoChannel.info("IntelliSense configuration updated.");
arduinoChannel.info(`IntelliSense configuration updated. ${help}`);
} else {
arduinoChannel.info("IntelliSense configuration already up to date.");
arduinoChannel.info(`IntelliSense configuration already up to date. ${help}`);
}
} catch (e) {
const estr = JSON.stringify(e);
arduinoChannel.error(`Failed to read or write IntelliSense configuration: ${estr}`);
}
const cmd = os.platform() === "darwin"
? "Cmd + Alt + I"
: "Ctrl + Alt + I";
arduinoChannel.info(`To manually rebuild your IntelliSense configuration run "${cmd}"`);
};
return {
callback: runner.callback(),
conclude: _conclude,
}
};

// TODO: move to cocopa
/**
* Filter directory list by directories by their existence.
* @param dirs Directories to be checked.
* @returns The list of directories which exist.
*/
async function removeInvalidDirs(dirs: string[]) {
const fsstat = tp.promisify(fs.stat);
const res: string[] = [];
for (const d of dirs) {
try {
const s = await fsstat(d);
if (s.isDirectory()) {
res.push(d);
}
} catch (e) {
}
}
return res;
}

/**
* Assembles compiler parser engines which then will be used to find the main
* sketch's compile command and parse the infomation from it required for
Expand Down

0 comments on commit fed508f

Please sign in to comment.