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

Commit 2b84aa8

Browse files
elektronikworkshopadiazulay
authored andcommitted
C++ standard is now parsed from compiler arguments
Plus: Moved some methods to cocopa and got rid of the typed-promisify dependency
1 parent f6c3b2c commit 2b84aa8

File tree

3 files changed

+13
-100
lines changed

3 files changed

+13
-100
lines changed

package-lock.json

+3-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@
604604
},
605605
"dependencies": {
606606
"body-parser": "^1.16.1",
607-
"cocopa": "0.0.12",
607+
"cocopa": "0.0.13",
608608
"compare-versions": "^3.4.0",
609609
"eventemitter2": "^4.1.0",
610610
"express": "^4.14.1",
@@ -613,7 +613,6 @@
613613
"impor": "^0.1.1",
614614
"node-usb-native": "^0.0.18",
615615
"properties": "^1.2.1",
616-
"typed-promisify": "^0.4.0",
617616
"uuid": "^3.0.1",
618617
"vscode-extension-telemetry": "0.1.6",
619618
"winreg": "^1.2.3",

src/arduino/intellisense.ts

+9-90
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
// Licensed under the MIT license.
33

44
import * as ccp from "cocopa";
5-
import * as fs from "fs";
65
import * as os from "os";
76
import * as path from "path";
8-
import * as tp from "typed-promisify";
97

108
import * as constants from "../common/constants";
119
import { arduinoChannel } from "../common/outputChannel";
@@ -45,11 +43,6 @@ export function isCompilerParserEnabled(dc?: DeviceContext) {
4543
*
4644
* Possible enhancements:
4745
*
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-
*
5346
* * Order of includes: Perhaps insert the internal includes at the front
5447
* as at least for the forcedIncludes IntelliSense seems to take the
5548
* order into account.
@@ -79,34 +72,30 @@ export function makeCompilerParserContext(dc: DeviceContext): ICoCoPaContext {
7972

8073
// Normalize compiler and include paths (resolve ".." and ".")
8174
runner.result.normalize();
82-
83-
runner.result.includes = await removeInvalidDirs(runner.result.includes);
75+
// Remove invalid paths
76+
await runner.result.cleanup();
8477

8578
// Search for Arduino.h in the include paths - we need it for a
8679
// forced include - users expect Arduino symbols to be available
8780
// 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
9184
: undefined;
92-
if (!ardHeader) {
85+
if (!forcedIncludes) {
9386
arduinoChannel.warning("Unable to locate \"Arduino.h\" within IntelliSense include paths.");
9487
}
9588

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.
9890
const content = new ccp.CCppPropertiesContentResult(runner.result,
9991
constants.C_CPP_PROPERTIES_CONFIG_NAME,
10092
ccp.CCppPropertiesISMode.Gcc_X64,
10193
ccp.CCppPropertiesCStandard.C11,
102-
// as of 1.8.11 arduino is on C++11
10394
ccp.CCppPropertiesCppStandard.Cpp11,
10495
forcedIncludes);
10596
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"`;
11099
const pPath = path.join(ArduinoWorkspace.rootPath, constants.CPP_CONFIG_FILE);
111100
const prop = new ccp.CCppProperties();
112101
prop.read(pPath);
@@ -127,27 +116,6 @@ export function makeCompilerParserContext(dc: DeviceContext): ICoCoPaContext {
127116
}
128117
};
129118

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-
151119
/**
152120
* Assembles compiler parser engines which then will be used to find the main
153121
* sketch's compile command and parse the infomation from it required for
@@ -165,55 +133,6 @@ function makeCompilerParserEngines(dc: DeviceContext) {
165133
return [gccParserEngine];
166134
}
167135

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-
217136
/**
218137
* Possible states of AnalysisManager's state machine.
219138
*/

0 commit comments

Comments
 (0)