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

Commit fed508f

Browse files
elektronikworkshopadiazulay
authored andcommitted
Filter out invalid include directories
* Filtering out invalid include directories (discovered when compiling for ESP8266) * Compacted IntelliSense message and hint to manual build into a single line
1 parent 194dc92 commit fed508f

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

src/arduino/intellisense.ts

+29-6
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ export function makeCompilerParserContext(dc: DeviceContext): ICoCoPaContext {
6969
// Normalize compiler and include paths (resolve ".." and ".")
7070
runner.result.normalize();
7171

72+
runner.result.includes = await removeInvalidDirs(runner.result.includes);
73+
7274
// Search for Arduino.h in the include paths - we need it for a
7375
// forced include - users expect Arduino symbols to be available
7476
// in main sketch without having to include the header explicitly
@@ -90,30 +92,51 @@ export function makeCompilerParserContext(dc: DeviceContext): ICoCoPaContext {
9092
ccp.CCppPropertiesCppStandard.Cpp11,
9193
forcedIncludes);
9294
try {
95+
const cmd = os.platform() === "darwin"
96+
? "Cmd + Alt + I"
97+
: "Ctrl + Alt + I";
98+
const help = `To manually rebuild your IntelliSense configuration run "${cmd}"`;
9399
const pPath = path.join(ArduinoWorkspace.rootPath, constants.CPP_CONFIG_FILE);
94100
const prop = new ccp.CCppProperties();
95101
prop.read(pPath);
96102
prop.merge(content, ccp.CCppPropertiesMergeMode.ReplaceSameNames);
97103
if (prop.write(pPath)) {
98-
arduinoChannel.info("IntelliSense configuration updated.");
104+
arduinoChannel.info(`IntelliSense configuration updated. ${help}`);
99105
} else {
100-
arduinoChannel.info("IntelliSense configuration already up to date.");
106+
arduinoChannel.info(`IntelliSense configuration already up to date. ${help}`);
101107
}
102108
} catch (e) {
103109
const estr = JSON.stringify(e);
104110
arduinoChannel.error(`Failed to read or write IntelliSense configuration: ${estr}`);
105111
}
106-
const cmd = os.platform() === "darwin"
107-
? "Cmd + Alt + I"
108-
: "Ctrl + Alt + I";
109-
arduinoChannel.info(`To manually rebuild your IntelliSense configuration run "${cmd}"`);
110112
};
111113
return {
112114
callback: runner.callback(),
113115
conclude: _conclude,
114116
}
115117
};
116118

119+
// TODO: move to cocopa
120+
/**
121+
* Filter directory list by directories by their existence.
122+
* @param dirs Directories to be checked.
123+
* @returns The list of directories which exist.
124+
*/
125+
async function removeInvalidDirs(dirs: string[]) {
126+
const fsstat = tp.promisify(fs.stat);
127+
const res: string[] = [];
128+
for (const d of dirs) {
129+
try {
130+
const s = await fsstat(d);
131+
if (s.isDirectory()) {
132+
res.push(d);
133+
}
134+
} catch (e) {
135+
}
136+
}
137+
return res;
138+
}
139+
117140
/**
118141
* Assembles compiler parser engines which then will be used to find the main
119142
* sketch's compile command and parse the infomation from it required for

0 commit comments

Comments
 (0)