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

Commit ced9e56

Browse files
* Removed code marked with IS-REMOVE previously
* Added constant for the `c_cpp_properties.json`-configuration managed by vscode-arduino * Removed code rendered dead by the previous removal
1 parent 363d325 commit ced9e56

File tree

12 files changed

+15
-286
lines changed

12 files changed

+15
-286
lines changed

BRANCHNOTES.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ During merging I found some bugs within those functions - mainly due to the abov
9494
**2020 02 22** Worked on cocopa unit tests: restored broken tests and added platform test for built-in parser. Added path normalizing for include paths for both cocopa and vscode-arduino. Verified correct behaviour on Windows with latest release (alpha tester claimed it not to be working)
9595
**2020 02 23** Several tests, fixes and improvements within cocopa. `Arduino.h` now added to forced includes. Fixed code which wasn't linted up to now. Added hint to end of build how to rebuild the IntelliSense configuration. Added missing version field to `c_cpp_properties.json`.
9696
**2020 02 25** Implemented and tested support for `.cpp`-sketches. Done implementing the most relevant unit tests in cocopa. Two independent alpha testers confirm proper working of the previous alpha releases. Updated to the latest revision of cocopa.
97+
**2020 02 26** Preparing for pull request: Removed all code marked `IS-REMOVE` and dead code which I was able to identify.
9798

9899
## Status
99100
| | Tasks |
@@ -115,23 +116,23 @@ During merging I found some bugs within those functions - mainly due to the abov
115116
| **Unit tests** | :heavy_check_mark: Basic parser (known boards, match/no match)|
116117
| | :heavy_check_mark: All unit tests in cocopa |
117118
| | :heavy_check_mark: Test with cpp sketches |
118-
| **General** | :heavy_check_mark: Review and remove previous attempts messing with `c_cpp_properties.json` or IntelliSense (documented in the [General Tasks](#General-Tasks) section) `*` |
119+
| **General** | :heavy_check_mark: Review and remove previous attempts messing with `c_cpp_properties.json` or IntelliSense (documented in the [General Tasks](#General-Tasks) section) |
119120
| | :heavy_check_mark: *Auto-run verify when* |
120-
| |     :heavy_check_mark: a) setting a board `*` |
121-
| |     :heavy_check_mark: b) changing the board's configuration `*` |
122-
| |     :heavy_check_mark: c) selecting another sketch `*` |
121+
| |     :heavy_check_mark: a) setting a board |
122+
| |     :heavy_check_mark: b) changing the board's configuration |
123+
| |     :heavy_check_mark: c) selecting another sketch |
123124
| |     :heavy_check_mark: d) ~~workbench initialized and no `c_cpp_properties.json` found~~ obsolete: when board and board configuration is loaded on start up the analysis is triggered anyways |
124125
| |     :white_check_mark: e) Identify other occasions where this applies (usually when adding new libraries) -- any suggestions? |
125126
| | :heavy_check_mark: Hint the user to run *Arduino: Rebuild IntelliSense Configuration* -> printing message after each build (verify, upload, ...) |
126-
| | :heavy_check_mark: Better build management such that regular builds and analyze builds do not interfere (done, 2020-02-19) `*` |
127-
| | :heavy_check_mark: Analyze task queue which fits in the latter (done, 2020-02-19) `*` |
127+
| | :heavy_check_mark: Better build management such that regular builds and analyze builds do not interfere (done, 2020-02-19) |
128+
| | :heavy_check_mark: Analyze task queue which fits in the latter (done, 2020-02-19) |
128129
| | :heavy_check_mark: Document configuration settings in [README.md](README.md) |
129130
| | :heavy_check_mark: Document features in [README.md](README.md) |
130131
| | :heavy_check_mark: Try to auto-generate even if verify (i.e. compilation) fails |
131132
| | :heavy_check_mark: Extract compiler command parser from vscode-arduino and [publish](https://itnext.io/step-by-step-building-and-publishing-an-npm-typescript-package-44fe7164964c) it as a separate package which will allow reusage and easy testing without heavy vscode-arduino rucksack -- done, see [cocopa](https://www.npmjs.com/package/cocopa) |
132133
| | :heavy_check_mark: Parser only works when arduino is set to `verbose`, since this is the only way we get the compiler invocation command - this has to be fixed (done, see next item) |
133134
| | :heavy_check_mark: Implement a *Rebuild IntelliSense Configuration* command which runs verify verbosely internally and therefore allows us to find and parse the compiler command |
134-
| | :heavy_check_mark: Implement proper event generation for `DeviceContext`. a) Events should be issued only when something actually changes, b) Events should be issued for each setting separately `*`|
135+
| | :heavy_check_mark: Implement proper event generation for `DeviceContext`. a) Events should be issued only when something actually changes, b) Events should be issued for each setting separately |
135136
| | :white_check_mark: Finally: go through my code and look for TODOs |
136137

137138
`*` not committed to branch yet
@@ -217,6 +218,9 @@ I will list every supporter here, thanks!
217218
* When having adding a library folder to the workspace IntelliSense should use the same configuration for it to enable library navigation and code completion.
218219
* Optimization: Abort analysis build as soon as compiler statement has been found
219220
* Non-IDE unit testing - to eliminate dependency injection use ts-mock-imports for instance
221+
* Remove dead code
222+
* Identify bad code and rework it
223+
* all those auxiliary functions in `src/common/util.ts` should be reviewed as they violate every guideline of good coding (try-catch clauses without error handling etc.)
220224
* Hardcoded and scattered constants:
221225
* Load package.json and use values from therein instead of hard coding redundant values like shortcuts (like I did for the IntelliSense message in `arduino.ts`)
222226
* Line splitting and other regexes

src/arduino/arduino.ts

Lines changed: 0 additions & 222 deletions
Original file line numberDiff line numberDiff line change
@@ -188,144 +188,6 @@ export class ArduinoApp {
188188
});
189189
}
190190

191-
// IS-REMOVE: to be removed completely when IntelliSense implementation is merged
192-
/*
193-
public tryToUpdateIncludePaths() {
194-
const configFilePath = path.join(ArduinoWorkspace.rootPath, constants.CPP_CONFIG_FILE);
195-
if (!fs.existsSync(configFilePath)) {
196-
return;
197-
}
198-
const cppConfigFile = fs.readFileSync(configFilePath, "utf8");
199-
const cppConfig = JSON.parse(cppConfigFile) as { configurations: Array<{ includePath: string[], forcedInclude: string[] }> };
200-
const libPaths = this.getDefaultPackageLibPaths();
201-
const defaultForcedInclude = this.getDefaultForcedIncludeFiles();
202-
const configuration = cppConfig.configurations[0];
203-
204-
let cppConfigFileUpdated = false;
205-
// cpp exntension changes \\ to \\\\ in paths in JSON string, revert them first
206-
configuration.includePath = configuration.includePath.map((path) => path.replace(/\\\\/g, "\\"));
207-
configuration.forcedInclude = configuration.forcedInclude.map((path) => path.replace(/\\\\/g, "\\"));
208-
209-
for (const libPath of libPaths) {
210-
if (configuration.includePath.indexOf(libPath) === -1) {
211-
cppConfigFileUpdated = true;
212-
configuration.includePath.push(libPath);
213-
}
214-
}
215-
for (const forcedIncludePath of defaultForcedInclude) {
216-
if (configuration.forcedInclude.indexOf(forcedIncludePath) === -1) {
217-
cppConfigFileUpdated = true;
218-
configuration.forcedInclude.push(forcedIncludePath);
219-
}
220-
}
221-
*/
222-
// remove all unexisting paths
223-
// concern mistake removal, comment temporary
224-
// for (let pathIndex = 0; pathIndex < configuration.includePath.length; pathIndex++) {
225-
// let libPath = configuration.includePath[pathIndex];
226-
// if (libPath.indexOf("${workspaceFolder}") !== -1) {
227-
// continue;
228-
// }
229-
// if (/\*$/.test(libPath)) {
230-
// libPath = libPath.match(/^[^\*]*/)[0];
231-
// }
232-
// if (!fs.existsSync(libPath)) {
233-
// cppConfigFileUpdated = true;
234-
// configuration.includePath.splice(pathIndex, 1);
235-
// pathIndex--;
236-
// }
237-
// }
238-
// for (let pathIndex = 0; pathIndex < configuration.forcedInclude.length; pathIndex++) {
239-
// const forcedIncludePath = configuration.forcedInclude[pathIndex];
240-
// if (forcedIncludePath.indexOf("${workspaceFolder}") !== -1) {
241-
// continue;
242-
// }
243-
// if (!fs.existsSync(forcedIncludePath)) {
244-
// cppConfigFileUpdated = true;
245-
// configuration.forcedInclude.splice(pathIndex, 1);
246-
// pathIndex--;
247-
// }
248-
// }
249-
/*
250-
if (cppConfigFileUpdated) {
251-
fs.writeFileSync(configFilePath, JSON.stringify(cppConfig, null, 4));
252-
}
253-
}
254-
*/
255-
256-
// IS-REMOVE: to be removed completely when IntelliSense implementation is merged
257-
/*
258-
// Add selected library path to the intellisense search path.
259-
public addLibPath(libraryPath: string) {
260-
let libPaths;
261-
if (libraryPath) {
262-
libPaths = [libraryPath];
263-
} else {
264-
libPaths = this.getDefaultPackageLibPaths();
265-
}
266-
267-
const defaultForcedInclude = this.getDefaultForcedIncludeFiles();
268-
269-
if (!ArduinoWorkspace.rootPath) {
270-
return;
271-
}
272-
const configFilePath = path.join(ArduinoWorkspace.rootPath, constants.CPP_CONFIG_FILE);
273-
let deviceContext = null;
274-
if (!util.fileExistsSync(configFilePath)) {
275-
util.mkdirRecursivelySync(path.dirname(configFilePath));
276-
deviceContext = {};
277-
} else {
278-
deviceContext = util.tryParseJSON(fs.readFileSync(configFilePath, "utf8"));
279-
}
280-
if (!deviceContext) {
281-
logger.notifyAndThrowUserError("arduinoFileError", new Error(constants.messages.ARDUINO_FILE_ERROR));
282-
}
283-
284-
deviceContext.configurations = deviceContext.configurations || [];
285-
let configSection = null;
286-
deviceContext.configurations.forEach((section) => {
287-
if (section.name === util.getCppConfigPlatform()) {
288-
configSection = section;
289-
}
290-
});
291-
292-
if (!configSection) {
293-
configSection = {
294-
name: util.getCppConfigPlatform(),
295-
includePath: [],
296-
};
297-
deviceContext.configurations.push(configSection);
298-
}
299-
300-
libPaths.forEach((childLibPath) => {
301-
childLibPath = path.resolve(path.normalize(childLibPath));
302-
if (configSection.includePath && configSection.includePath.length) {
303-
for (const existingPath of configSection.includePath) {
304-
if (childLibPath === path.resolve(path.normalize(existingPath))) {
305-
return;
306-
}
307-
}
308-
} else {
309-
configSection.includePath = [];
310-
}
311-
configSection.includePath.unshift(childLibPath);
312-
});
313-
314-
if (!configSection.forcedInclude) {
315-
configSection.forcedInclude = defaultForcedInclude;
316-
} else {
317-
for (let i = 0; i < configSection.forcedInclude.length; i++) {
318-
if (/arduino\.h$/i.test(configSection.forcedInclude[i])) {
319-
configSection.forcedInclude.splice(i, 1);
320-
i--;
321-
}
322-
}
323-
configSection.forcedInclude = defaultForcedInclude.concat(configSection.forcedInclude);
324-
}
325-
326-
fs.writeFileSync(configFilePath, JSON.stringify(deviceContext, null, 4));
327-
}
328-
*/
329191
// Include the *.h header files from selected library to the arduino sketch.
330192
public async includeLibrary(libraryPath: string) {
331193
if (!ArduinoWorkspace.rootPath) {
@@ -448,50 +310,6 @@ Please make sure the folder is not occupied by other procedures .`);
448310
arduinoChannel.end(`Removed library - ${libName}${os.EOL}`);
449311
}
450312

451-
// IS-REMOVE: to be removed completely when IntelliSense implementation is merged
452-
/*
453-
public getDefaultPackageLibPaths(): string[] {
454-
const result = [];
455-
const boardDescriptor = this._boardManager.currentBoard;
456-
if (!boardDescriptor) {
457-
return result;
458-
}
459-
const toolsPath = boardDescriptor.platform.rootBoardPath;
460-
result.push(path.normalize(path.join(toolsPath, "**")));
461-
// if (util.directoryExistsSync(path.join(toolsPath, "cores"))) {
462-
// const coreLibs = fs.readdirSync(path.join(toolsPath, "cores"));
463-
// if (coreLibs && coreLibs.length > 0) {
464-
// coreLibs.forEach((coreLib) => {
465-
// result.push(path.normalize(path.join(toolsPath, "cores", coreLib)));
466-
// });
467-
// }
468-
// }
469-
// return result;
470-
471-
// <package>/hardware/<platform>/<version> -> <package>/tools
472-
const toolPath = path.join(toolsPath, "..", "..", "..", "tools");
473-
if (fs.existsSync(toolPath)) {
474-
result.push(path.normalize(path.join(toolPath, "**")));
475-
}
476-
return result;
477-
}*/
478-
479-
// IS-REMOVE: to be removed completely when IntelliSense implementation is merged
480-
/*
481-
public getDefaultForcedIncludeFiles(): string[] {
482-
const result = [];
483-
const boardDescriptor = this._boardManager.currentBoard;
484-
if (!boardDescriptor) {
485-
return result;
486-
}
487-
const arduinoHeadFilePath = path.normalize(path.join(boardDescriptor.platform.rootBoardPath, "cores", "arduino", "Arduino.h"));
488-
if (fs.existsSync(arduinoHeadFilePath)) {
489-
result.push(arduinoHeadFilePath);
490-
}
491-
return result;
492-
}
493-
*/
494-
495313
public openExample(example) {
496314
function tmpName(name) {
497315
let counter = 0;
@@ -539,46 +357,6 @@ Please make sure the folder is not occupied by other procedures .`);
539357
const arduinoConfigFilePath = path.join(destExample, constants.ARDUINO_CONFIG_FILE);
540358
util.mkdirRecursivelySync(path.dirname(arduinoConfigFilePath));
541359
fs.writeFileSync(arduinoConfigFilePath, JSON.stringify(arduinoJson, null, 4));
542-
543-
// IS-REMOVE: to be removed completely when IntelliSense implementation is merged
544-
/*
545-
// Generate cpptools intellisense config
546-
const cppConfigFilePath = path.join(destExample, constants.CPP_CONFIG_FILE);
547-
548-
// Current workspace
549-
let includePath = ["${workspaceRoot}"];
550-
// Defaut package for this board
551-
const defaultPackageLibPaths = this.getDefaultPackageLibPaths();
552-
includePath = includePath.concat(defaultPackageLibPaths);
553-
// Arduino built-in package tools
554-
includePath.push(path.join(this._settings.arduinoPath, "hardware", "tools", "**"));
555-
// Arduino built-in libraries
556-
includePath.push(path.join(this._settings.arduinoPath, "libraries", "**"));
557-
// Arduino custom package tools
558-
includePath.push(path.join(this._settings.sketchbookPath, "hardware", "tools", "**"));
559-
// Arduino custom libraries
560-
includePath.push(path.join(this._settings.sketchbookPath, "libraries", "**"));
561-
562-
const forcedInclude = this.getDefaultForcedIncludeFiles();
563-
564-
const defines = [
565-
"ARDUINO=10800",
566-
];
567-
const cppConfig = {
568-
configurations: [{
569-
name: util.getCppConfigPlatform(),
570-
defines,
571-
includePath,
572-
forcedInclude,
573-
intelliSenseMode: "clang-x64",
574-
cStandard: "c11",
575-
cppStandard: "c++17",
576-
}],
577-
version: 3,
578-
};
579-
util.mkdirRecursivelySync(path.dirname(cppConfigFilePath));
580-
fs.writeFileSync(cppConfigFilePath, JSON.stringify(cppConfig, null, 4));
581-
*/
582360
}
583361

584362
// Step 3: Open the arduino project at a new vscode window.

src/arduino/arduinoContentProvider.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,6 @@ export class ArduinoContentProvider implements vscode.TextDocumentContentProvide
207207
return res.status(400).send("BAD Request! Missing { libraryPath } parameters!");
208208
} else {
209209
try {
210-
// IS-REMOVE: to be removed completely when IntelliSense implementation is merged
211-
// await ArduinoContext.arduinoApp.addLibPath(req.body.libraryPath);
212210
await ArduinoContext.arduinoApp.includeLibrary(req.body.libraryPath);
213211
return res.json({
214212
status: "OK",

src/arduino/boardManager.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,6 @@ export class BoardManager {
136136
// correct board and configuration. We know that it will trigger - we
137137
// made sure above that the boards actually differ
138138
dc.board = targetBoard.key;
139-
140-
// IS-REMOVE: to be removed completely when IntelliSense implementation is merged
141-
// this._arduinoApp.addLibPath(null);
142139
}
143140

144141
public get packages(): IPackage[] {

src/arduino/intellisense.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export function makeCompilerParserContext(dc: DeviceContext): ICoCoPaContext {
8383
// TODO: check what kind of result we've got: gcc or other architecture:
8484
// and instantiate content accordingly (to be implemented within cocopa)
8585
const content = new ccp.CCppPropertiesContentResult(runner.result,
86-
"Arduino",
86+
constants.C_CPP_PROPERTIES_CONFIG_NAME,
8787
ccp.CCppPropertiesISMode.Gcc_X64,
8888
ccp.CCppPropertiesCStandard.C11,
8989
// as of 1.8.11 arduino is on C++11

src/common/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import * as vscode from "vscode";
77
export const ARDUINO_CONFIG_FILE = path.join(".vscode", "arduino.json");
88

99
export const CPP_CONFIG_FILE = path.join(".vscode", "c_cpp_properties.json");
10+
/** The name of the intellisense configuration managed by vscode-arduino. */
11+
export const C_CPP_PROPERTIES_CONFIG_NAME = "Arduino";
1012

1113
export const ARDUINO_MODE: vscode.DocumentSelector = [
1214
{ language: "cpp", scheme: "file" },

0 commit comments

Comments
 (0)