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" ;
@@ -45,11 +43,6 @@ export function isCompilerParserEnabled(dc?: DeviceContext) {
45
43
*
46
44
* Possible enhancements:
47
45
*
48
- * * Parse c++ standard from arduino command line
49
- *
50
- * Arduino currently sets the C++ standard during compilation with the
51
- * flag -std=gnu++11
52
- *
53
46
* * Order of includes: Perhaps insert the internal includes at the front
54
47
* as at least for the forcedIncludes IntelliSense seems to take the
55
48
* order into account.
@@ -79,34 +72,30 @@ export function makeCompilerParserContext(dc: DeviceContext): ICoCoPaContext {
79
72
80
73
// Normalize compiler and include paths (resolve ".." and ".")
81
74
runner . result . normalize ( ) ;
82
-
83
- runner . result . includes = await removeInvalidDirs ( runner . result . includes ) ;
75
+ // Remove invalid paths
76
+ await runner . result . cleanup ( ) ;
84
77
85
78
// Search for Arduino.h in the include paths - we need it for a
86
79
// forced include - users expect Arduino symbols to be available
87
80
// in main sketch without having to include the header explicitly
88
- const ardHeader = await locateArduinoHeader ( runner . result . includes ) ;
89
- const forcedIncludes = ardHeader
90
- ? [ ardHeader ]
81
+ const ardHeader = await runner . result . findFile ( "Arduino.h" ) ;
82
+ const forcedIncludes = ardHeader . length > 0
83
+ ? ardHeader
91
84
: undefined ;
92
- if ( ! ardHeader ) {
85
+ if ( ! forcedIncludes ) {
93
86
arduinoChannel . warning ( "Unable to locate \"Arduino.h\" within IntelliSense include paths." ) ;
94
87
}
95
88
96
- // TODO: check what kind of result we've got: gcc or other architecture:
97
- // and instantiate content accordingly (to be implemented within cocopa)
89
+ // The C++ standard is set to the following default value if no compiler flag has been found.
98
90
const content = new ccp . CCppPropertiesContentResult ( runner . result ,
99
91
constants . C_CPP_PROPERTIES_CONFIG_NAME ,
100
92
ccp . CCppPropertiesISMode . Gcc_X64 ,
101
93
ccp . CCppPropertiesCStandard . C11 ,
102
- // as of 1.8.11 arduino is on C++11
103
94
ccp . CCppPropertiesCppStandard . Cpp11 ,
104
95
forcedIncludes ) ;
105
96
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 } "` ;
97
+ const cmd = os . platform ( ) === "darwin" ? "Cmd" : "Ctrl" ;
98
+ const help = `To manually rebuild your IntelliSense configuration run "${ cmd } +Alt+I"` ;
110
99
const pPath = path . join ( ArduinoWorkspace . rootPath , constants . CPP_CONFIG_FILE ) ;
111
100
const prop = new ccp . CCppProperties ( ) ;
112
101
prop . read ( pPath ) ;
@@ -127,27 +116,6 @@ export function makeCompilerParserContext(dc: DeviceContext): ICoCoPaContext {
127
116
}
128
117
} ;
129
118
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
119
/**
152
120
* Assembles compiler parser engines which then will be used to find the main
153
121
* sketch's compile command and parse the infomation from it required for
@@ -165,55 +133,6 @@ function makeCompilerParserEngines(dc: DeviceContext) {
165
133
return [ gccParserEngine ] ;
166
134
}
167
135
168
- /**
169
- * Search directories recursively for a file.
170
- * @param dir Directory where the search should begin.
171
- * @param what The file we're looking for.
172
- * @returns The path of the directory which contains the file else undefined.
173
- */
174
- async function findDirContaining ( dir : string , what : string ) : Promise < string | undefined > {
175
- const readdir = tp . promisify ( fs . readdir ) ;
176
- const fsstat = tp . promisify ( fs . stat ) ;
177
-
178
- let entries : string [ ] ;
179
- try {
180
- entries = await readdir ( dir ) ;
181
- } catch ( e ) {
182
- return undefined ;
183
- }
184
- for ( const entry of entries ) {
185
- const p = path . join ( dir , entry ) ;
186
- const s = await fsstat ( p ) ;
187
- if ( s . isDirectory ( ) ) {
188
- const result = await findDirContaining ( p , what ) ;
189
- if ( result ) {
190
- return result ;
191
- }
192
- } else if ( entry === what ) {
193
- return dir ;
194
- }
195
- }
196
- return undefined ;
197
- } ;
198
-
199
- /**
200
- * Tries to find the main Arduino header (i.e. Arduino.h) in the given include
201
- * paths.
202
- * @param includes Array containing all include paths in which we should look
203
- * for Arduino.h
204
- * @returns The full path of the main Arduino header.
205
- */
206
- async function locateArduinoHeader ( includes : string [ ] ) {
207
- const header = "Arduino.h" ;
208
- for ( const i of includes ) {
209
- const result = await findDirContaining ( i , header ) ;
210
- if ( result ) {
211
- return path . join ( result , header ) ;
212
- }
213
- }
214
- return undefined ;
215
- }
216
-
217
136
/**
218
137
* Possible states of AnalysisManager's state machine.
219
138
*/
0 commit comments