Skip to content

Commit 6c5de45

Browse files
Moved some methods to cocopa and got rid of the typed-promisify dependency
1 parent 0ba7b16 commit 6c5de45

File tree

2 files changed

+9
-83
lines changed

2 files changed

+9
-83
lines changed

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,6 @@
594594
"iconv-lite": "^0.4.18",
595595
"impor": "^0.1.1",
596596
"properties": "^1.2.1",
597-
"typed-promisify": "^0.4.0",
598597
"uuid": "^3.0.1",
599598
"vscode-extension-telemetry": "0.0.18",
600599
"winreg": "^1.2.3",

src/arduino/intellisense.ts

+9-82
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";
@@ -79,22 +77,23 @@ export function makeCompilerParserContext(dc: DeviceContext): ICoCoPaContext {
7977

8078
// Normalize compiler and include paths (resolve ".." and ".")
8179
runner.result.normalize();
82-
83-
runner.result.includes = await removeInvalidDirs(runner.result.includes);
80+
// Remove invalid paths
81+
await runner.result.cleanup();
8482

8583
// Search for Arduino.h in the include paths - we need it for a
8684
// forced include - users expect Arduino symbols to be available
8785
// 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
9189
: undefined;
92-
if (!ardHeader) {
90+
if (!forcedIncludes) {
9391
arduinoChannel.warning("Unable to locate \"Arduino.h\" within IntelliSense include paths.");
9492
}
9593

9694
// TODO: check what kind of result we've got: gcc or other architecture:
9795
// and instantiate content accordingly (to be implemented within cocopa)
96+
// -> move result to the parser engine itself
9897
const content = new ccp.CCppPropertiesContentResult(runner.result,
9998
constants.C_CPP_PROPERTIES_CONFIG_NAME,
10099
ccp.CCppPropertiesISMode.Gcc_X64,
@@ -103,10 +102,8 @@ export function makeCompilerParserContext(dc: DeviceContext): ICoCoPaContext {
103102
ccp.CCppPropertiesCppStandard.Cpp11,
104103
forcedIncludes);
105104
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"`;
110107
const pPath = path.join(ArduinoWorkspace.rootPath, constants.CPP_CONFIG_FILE);
111108
const prop = new ccp.CCppProperties();
112109
prop.read(pPath);
@@ -127,27 +124,6 @@ export function makeCompilerParserContext(dc: DeviceContext): ICoCoPaContext {
127124
}
128125
};
129126

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-
151127
/**
152128
* Assembles compiler parser engines which then will be used to find the main
153129
* sketch's compile command and parse the infomation from it required for
@@ -166,55 +142,6 @@ function makeCompilerParserEngines(dc: DeviceContext) {
166142
return [gccParserEngine];
167143
}
168144

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-
218145
/**
219146
* Possible states of AnalysisManager's state machine.
220147
*/

0 commit comments

Comments
 (0)