2
2
// Licensed under the MIT license.
3
3
4
4
import * as ccp from "cocopa" ;
5
- import * as fs from "fs" ;
6
5
import * as os from "os" ;
7
6
import * as path from "path" ;
8
- import * as tp from "typed-promisify" ;
9
7
10
8
import * as constants from "../common/constants" ;
11
9
import { arduinoChannel } from "../common/outputChannel" ;
@@ -79,22 +77,23 @@ export function makeCompilerParserContext(dc: DeviceContext): ICoCoPaContext {
79
77
80
78
// Normalize compiler and include paths (resolve ".." and ".")
81
79
runner . result . normalize ( ) ;
82
-
83
- runner . result . includes = await removeInvalidDirs ( runner . result . includes ) ;
80
+ // Remove invalid paths
81
+ await runner . result . cleanup ( ) ;
84
82
85
83
// Search for Arduino.h in the include paths - we need it for a
86
84
// forced include - users expect Arduino symbols to be available
87
85
// in main sketch without having to include the header explicitly
88
- const ardHeader = await locateArduinoHeader ( runner . result . includes ) ;
89
- const forcedIncludes = ardHeader
90
- ? [ ardHeader ]
86
+ const ardHeader = await runner . result . findFile ( "Arduino.h" ) ;
87
+ const forcedIncludes = ardHeader . length > 0
88
+ ? ardHeader
91
89
: undefined ;
92
- if ( ! ardHeader ) {
90
+ if ( ! forcedIncludes ) {
93
91
arduinoChannel . warning ( "Unable to locate \"Arduino.h\" within IntelliSense include paths." ) ;
94
92
}
95
93
96
94
// TODO: check what kind of result we've got: gcc or other architecture:
97
95
// and instantiate content accordingly (to be implemented within cocopa)
96
+ // -> move result to the parser engine itself
98
97
const content = new ccp . CCppPropertiesContentResult ( runner . result ,
99
98
constants . C_CPP_PROPERTIES_CONFIG_NAME ,
100
99
ccp . CCppPropertiesISMode . Gcc_X64 ,
@@ -103,10 +102,8 @@ export function makeCompilerParserContext(dc: DeviceContext): ICoCoPaContext {
103
102
ccp . CCppPropertiesCppStandard . Cpp11 ,
104
103
forcedIncludes ) ;
105
104
try {
106
- const cmd = os . platform ( ) === "darwin"
107
- ? "Cmd + Alt + I"
108
- : "Ctrl + Alt + I" ;
109
- const help = `To manually rebuild your IntelliSense configuration run "${ cmd } "` ;
105
+ const cmd = os . platform ( ) === "darwin" ? "Cmd" : "Ctrl" ;
106
+ const help = `To manually rebuild your IntelliSense configuration run "${ cmd } +Alt+I"` ;
110
107
const pPath = path . join ( ArduinoWorkspace . rootPath , constants . CPP_CONFIG_FILE ) ;
111
108
const prop = new ccp . CCppProperties ( ) ;
112
109
prop . read ( pPath ) ;
@@ -127,27 +124,6 @@ export function makeCompilerParserContext(dc: DeviceContext): ICoCoPaContext {
127
124
}
128
125
} ;
129
126
130
- // TODO: move to cocopa
131
- /**
132
- * Filter directory list by directories by their existence.
133
- * @param dirs Directories to be checked.
134
- * @returns The list of directories which exist.
135
- */
136
- async function removeInvalidDirs ( dirs : string [ ] ) {
137
- const fsstat = tp . promisify ( fs . stat ) ;
138
- const res : string [ ] = [ ] ;
139
- for ( const d of dirs ) {
140
- try {
141
- const s = await fsstat ( d ) ;
142
- if ( s . isDirectory ( ) ) {
143
- res . push ( d ) ;
144
- }
145
- } catch ( e ) {
146
- }
147
- }
148
- return res ;
149
- }
150
-
151
127
/**
152
128
* Assembles compiler parser engines which then will be used to find the main
153
129
* sketch's compile command and parse the infomation from it required for
@@ -166,55 +142,6 @@ function makeCompilerParserEngines(dc: DeviceContext) {
166
142
return [ gccParserEngine ] ;
167
143
}
168
144
169
- /**
170
- * Search directories recursively for a file.
171
- * @param dir Directory where the search should begin.
172
- * @param what The file we're looking for.
173
- * @returns The path of the directory which contains the file else undefined.
174
- */
175
- async function findDirContaining ( dir : string , what : string ) : Promise < string | undefined > {
176
- const readdir = tp . promisify ( fs . readdir ) ;
177
- const fsstat = tp . promisify ( fs . stat ) ;
178
-
179
- let entries : string [ ] ;
180
- try {
181
- entries = await readdir ( dir ) ;
182
- } catch ( e ) {
183
- return undefined ;
184
- }
185
- for ( const entry of entries ) {
186
- const p = path . join ( dir , entry ) ;
187
- const s = await fsstat ( p ) ;
188
- if ( s . isDirectory ( ) ) {
189
- const result = await findDirContaining ( p , what ) ;
190
- if ( result ) {
191
- return result ;
192
- }
193
- } else if ( entry === what ) {
194
- return dir ;
195
- }
196
- }
197
- return undefined ;
198
- } ;
199
-
200
- /**
201
- * Tries to find the main Arduino header (i.e. Arduino.h) in the given include
202
- * paths.
203
- * @param includes Array containing all include paths in which we should look
204
- * for Arduino.h
205
- * @returns The full path of the main Arduino header.
206
- */
207
- async function locateArduinoHeader ( includes : string [ ] ) {
208
- const header = "Arduino.h" ;
209
- for ( const i of includes ) {
210
- const result = await findDirContaining ( i , header ) ;
211
- if ( result ) {
212
- return path . join ( result , header ) ;
213
- }
214
- }
215
- return undefined ;
216
- }
217
-
218
145
/**
219
146
* Possible states of AnalysisManager's state machine.
220
147
*/
0 commit comments