@@ -69,6 +69,8 @@ export function makeCompilerParserContext(dc: DeviceContext): ICoCoPaContext {
69
69
// Normalize compiler and include paths (resolve ".." and ".")
70
70
runner . result . normalize ( ) ;
71
71
72
+ runner . result . includes = await removeInvalidDirs ( runner . result . includes ) ;
73
+
72
74
// Search for Arduino.h in the include paths - we need it for a
73
75
// forced include - users expect Arduino symbols to be available
74
76
// in main sketch without having to include the header explicitly
@@ -90,30 +92,51 @@ export function makeCompilerParserContext(dc: DeviceContext): ICoCoPaContext {
90
92
ccp . CCppPropertiesCppStandard . Cpp11 ,
91
93
forcedIncludes ) ;
92
94
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 } "` ;
93
99
const pPath = path . join ( ArduinoWorkspace . rootPath , constants . CPP_CONFIG_FILE ) ;
94
100
const prop = new ccp . CCppProperties ( ) ;
95
101
prop . read ( pPath ) ;
96
102
prop . merge ( content , ccp . CCppPropertiesMergeMode . ReplaceSameNames ) ;
97
103
if ( prop . write ( pPath ) ) {
98
- arduinoChannel . info ( " IntelliSense configuration updated." ) ;
104
+ arduinoChannel . info ( ` IntelliSense configuration updated. ${ help } ` ) ;
99
105
} else {
100
- arduinoChannel . info ( " IntelliSense configuration already up to date." ) ;
106
+ arduinoChannel . info ( ` IntelliSense configuration already up to date. ${ help } ` ) ;
101
107
}
102
108
} catch ( e ) {
103
109
const estr = JSON . stringify ( e ) ;
104
110
arduinoChannel . error ( `Failed to read or write IntelliSense configuration: ${ estr } ` ) ;
105
111
}
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 } "` ) ;
110
112
} ;
111
113
return {
112
114
callback : runner . callback ( ) ,
113
115
conclude : _conclude ,
114
116
}
115
117
} ;
116
118
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
+
117
140
/**
118
141
* Assembles compiler parser engines which then will be used to find the main
119
142
* sketch's compile command and parse the infomation from it required for
0 commit comments