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

Commit d408686

Browse files
elektronikworkshopadiazulay
authored andcommitted
Removed IS-REMOVE code
* 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 31e530c commit d408686

12 files changed

+15
-321
lines changed

BRANCHNOTES.md

+11-7
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

-257
Original file line numberDiff line numberDiff line change
@@ -420,162 +420,6 @@ export class ArduinoApp {
420420
return success;
421421
}
422422

423-
// IS-REMOVE: to be removed completely when IntelliSense implementation is merged
424-
/*
425-
public tryToUpdateIncludePaths() {
426-
const configFilePath = path.join(ArduinoWorkspace.rootPath, constants.CPP_CONFIG_FILE);
427-
if (!fs.existsSync(configFilePath)) {
428-
return;
429-
}
430-
const cppConfigFile = fs.readFileSync(configFilePath, "utf8");
431-
const cppConfig = JSON.parse(cppConfigFile) as { configurations: Array<{
432-
includePath: string[],
433-
forcedInclude: string[],
434-
defines: string[],
435-
}> };
436-
const libPaths = this.getDefaultPackageLibPaths();
437-
const defaultForcedInclude = this.getDefaultForcedIncludeFiles();
438-
const defines = this.getDefaultDefines();
439-
const configuration = cppConfig.configurations[0];
440-
441-
let cppConfigFileUpdated = false;
442-
// cpp extension changes \\ to \\\\ in paths in JSON string, revert them first
443-
configuration.includePath = configuration.includePath.map((path) => path.replace(/\\\\/g, "\\"));
444-
configuration.forcedInclude = configuration.forcedInclude.map((path) => path.replace(/\\\\/g, "\\"));
445-
configuration.defines = configuration.defines.map((path) => path.replace(/\\\\/g, "\\"));
446-
447-
for (const libPath of libPaths) {
448-
if (configuration.includePath.indexOf(libPath) === -1) {
449-
cppConfigFileUpdated = true;
450-
configuration.includePath.push(libPath);
451-
}
452-
}
453-
for (const forcedIncludePath of defaultForcedInclude) {
454-
if (configuration.forcedInclude.indexOf(forcedIncludePath) === -1) {
455-
cppConfigFileUpdated = true;
456-
configuration.forcedInclude.push(forcedIncludePath);
457-
}
458-
}
459-
460-
for (const define of defines) {
461-
if (configuration.defines.indexOf(define) === -1) {
462-
cppConfigFileUpdated = true;
463-
configuration.defines.push(define);
464-
}
465-
}
466-
*/
467-
// remove all unexisting paths
468-
// concern mistake removal, comment temporary
469-
// for (let pathIndex = 0; pathIndex < configuration.includePath.length; pathIndex++) {
470-
// let libPath = configuration.includePath[pathIndex];
471-
// if (libPath.indexOf("${workspaceFolder}") !== -1) {
472-
// continue;
473-
// }
474-
// if (/\*$/.test(libPath)) {
475-
// libPath = libPath.match(/^[^\*]*/)[0];
476-
// }
477-
// if (!fs.existsSync(libPath)) {
478-
// cppConfigFileUpdated = true;
479-
// configuration.includePath.splice(pathIndex, 1);
480-
// pathIndex--;
481-
// }
482-
// }
483-
// for (let pathIndex = 0; pathIndex < configuration.forcedInclude.length; pathIndex++) {
484-
// const forcedIncludePath = configuration.forcedInclude[pathIndex];
485-
// if (forcedIncludePath.indexOf("${workspaceFolder}") !== -1) {
486-
// continue;
487-
// }
488-
// if (!fs.existsSync(forcedIncludePath)) {
489-
// cppConfigFileUpdated = true;
490-
// configuration.forcedInclude.splice(pathIndex, 1);
491-
// pathIndex--;
492-
// }
493-
// }
494-
/*
495-
if (cppConfigFileUpdated) {
496-
fs.writeFileSync(configFilePath, JSON.stringify(cppConfig, null, 4));
497-
}
498-
}
499-
*/
500-
501-
// IS-REMOVE: to be removed completely when IntelliSense implementation is merged
502-
/*
503-
// Add selected library path to the intellisense search path.
504-
public addLibPath(libraryPath: string) {
505-
let libPaths;
506-
if (libraryPath) {
507-
libPaths = [libraryPath];
508-
} else {
509-
libPaths = this.getDefaultPackageLibPaths();
510-
}
511-
512-
const defaultForcedInclude = this.getDefaultForcedIncludeFiles();
513-
const defaultDefines = this.getDefaultDefines();
514-
515-
if (!ArduinoWorkspace.rootPath) {
516-
return;
517-
}
518-
const configFilePath = path.join(ArduinoWorkspace.rootPath, constants.CPP_CONFIG_FILE);
519-
let deviceContext = null;
520-
if (!util.fileExistsSync(configFilePath)) {
521-
util.mkdirRecursivelySync(path.dirname(configFilePath));
522-
deviceContext = {};
523-
} else {
524-
deviceContext = util.tryParseJSON(fs.readFileSync(configFilePath, "utf8"));
525-
}
526-
if (!deviceContext) {
527-
logger.notifyAndThrowUserError("arduinoFileError", new Error(constants.messages.ARDUINO_FILE_ERROR));
528-
}
529-
530-
deviceContext.configurations = deviceContext.configurations || [];
531-
let configSection = null;
532-
deviceContext.configurations.forEach((section) => {
533-
if (section.name === util.getCppConfigPlatform()) {
534-
configSection = section;
535-
}
536-
});
537-
538-
if (!configSection) {
539-
configSection = {
540-
name: util.getCppConfigPlatform(),
541-
includePath: [],
542-
};
543-
deviceContext.configurations.push(configSection);
544-
}
545-
546-
libPaths.forEach((childLibPath) => {
547-
childLibPath = path.resolve(path.normalize(childLibPath));
548-
if (configSection.includePath && configSection.includePath.length) {
549-
for (const existingPath of configSection.includePath) {
550-
if (childLibPath === path.resolve(path.normalize(existingPath))) {
551-
return;
552-
}
553-
}
554-
} else {
555-
configSection.includePath = [];
556-
}
557-
configSection.includePath.unshift(childLibPath);
558-
});
559-
560-
if (!configSection.forcedInclude) {
561-
configSection.forcedInclude = defaultForcedInclude;
562-
} else {
563-
for (let i = 0; i < configSection.forcedInclude.length; i++) {
564-
if (/arduino\.h$/i.test(configSection.forcedInclude[i])) {
565-
configSection.forcedInclude.splice(i, 1);
566-
i--;
567-
}
568-
}
569-
configSection.forcedInclude = defaultForcedInclude.concat(configSection.forcedInclude);
570-
}
571-
572-
if (!configSection.defines) {
573-
configSection.defines = defaultDefines;
574-
}
575-
576-
fs.writeFileSync(configFilePath, JSON.stringify(deviceContext, null, 4));
577-
}
578-
*/
579423
// Include the *.h header files from selected library to the arduino sketch.
580424
public async includeLibrary(libraryPath: string) {
581425
if (!ArduinoWorkspace.rootPath) {
@@ -719,67 +563,6 @@ export class ArduinoApp {
719563
arduinoChannel.end(`Removed library - ${libName}${os.EOL}`);
720564
}
721565

722-
// IS-REMOVE: to be removed completely when IntelliSense implementation is merged
723-
/*
724-
public getDefaultPackageLibPaths(): string[] {
725-
const result = [];
726-
const boardDescriptor = this._boardManager.currentBoard;
727-
if (!boardDescriptor) {
728-
return result;
729-
}
730-
const toolsPath = boardDescriptor.platform.rootBoardPath;
731-
result.push(path.normalize(path.join(toolsPath, "**")));
732-
const hardwareToolPath = path.join(toolsPath, "..", "..", "tools");
733-
if (fs.existsSync(hardwareToolPath)) {
734-
result.push(path.normalize(path.join(hardwareToolPath, "**")));
735-
}
736-
737-
// Add default libraries to include path
738-
result.push(path.normalize(path.join(this._settings.defaultLibPath, "**")));
739-
740-
const userLibsPath = (path.join(this._settings.sketchbookPath, "libraries", "**"));
741-
result.push(userLibsPath);
742-
// if (util.directoryExistsSync(path.join(toolsPath, "cores"))) {
743-
// const coreLibs = fs.readdirSync(path.join(toolsPath, "cores"));
744-
// if (coreLibs && coreLibs.length > 0) {
745-
// coreLibs.forEach((coreLib) => {
746-
// result.push(path.normalize(path.join(toolsPath, "cores", coreLib)));
747-
// });
748-
// }
749-
// }
750-
// return result;
751-
752-
// <package>/hardware/<platform>/<version> -> <package>/tools
753-
const toolPath = path.join(toolsPath, "..", "..", "..", "tools");
754-
if (fs.existsSync(toolPath)) {
755-
result.push(path.normalize(path.join(toolPath, "**")));
756-
}
757-
return result;
758-
}*/
759-
760-
// IS-REMOVE: to be removed completely when IntelliSense implementation is merged
761-
/*
762-
public getDefaultForcedIncludeFiles(): string[] {
763-
const result = [];
764-
const boardDescriptor = this._boardManager.currentBoard;
765-
if (!boardDescriptor) {
766-
return result;
767-
}
768-
const arduinoHeadFilePath = path.normalize(path.join(boardDescriptor.platform.rootBoardPath, "cores", "arduino", "Arduino.h"));
769-
if (fs.existsSync(arduinoHeadFilePath)) {
770-
result.push(arduinoHeadFilePath);
771-
}
772-
return result;
773-
}
774-
775-
public getDefaultDefines(): string[] {
776-
const result = [];
777-
// USBCON is required in order for Serial to be recognized by intellisense
778-
result.push("USBCON");
779-
return result;
780-
}
781-
*/
782-
783566
public openExample(example) {
784567
function tmpName(name) {
785568
let counter = 0;
@@ -827,46 +610,6 @@ export class ArduinoApp {
827610
const arduinoConfigFilePath = path.join(destExample, constants.ARDUINO_CONFIG_FILE);
828611
util.mkdirRecursivelySync(path.dirname(arduinoConfigFilePath));
829612
fs.writeFileSync(arduinoConfigFilePath, JSON.stringify(arduinoJson, null, 4));
830-
831-
// IS-REMOVE: to be removed completely when IntelliSense implementation is merged
832-
/*
833-
// Generate cpptools intellisense config
834-
const cppConfigFilePath = path.join(destExample, constants.CPP_CONFIG_FILE);
835-
836-
// Current workspace
837-
let includePath = ["${workspaceRoot}"];
838-
// Defaut package for this board
839-
const defaultPackageLibPaths = this.getDefaultPackageLibPaths();
840-
includePath = includePath.concat(defaultPackageLibPaths);
841-
// Arduino built-in package tools
842-
includePath.push(path.join(this._settings.arduinoPath, "hardware", "tools", "**"));
843-
// Arduino built-in libraries
844-
includePath.push(path.join(this._settings.arduinoPath, "libraries", "**"));
845-
// Arduino custom package tools
846-
includePath.push(path.join(this._settings.sketchbookPath, "hardware", "tools", "**"));
847-
// Arduino custom libraries
848-
includePath.push(path.join(this._settings.sketchbookPath, "libraries", "**"));
849-
850-
const forcedInclude = this.getDefaultForcedIncludeFiles();
851-
852-
const defines = [
853-
"ARDUINO=10800",
854-
];
855-
const cppConfig = {
856-
configurations: [{
857-
name: util.getCppConfigPlatform(),
858-
defines,
859-
includePath,
860-
forcedInclude,
861-
intelliSenseMode: "clang-x64",
862-
cStandard: "c11",
863-
cppStandard: "c++17",
864-
}],
865-
version: 3,
866-
};
867-
util.mkdirRecursivelySync(path.dirname(cppConfigFilePath));
868-
fs.writeFileSync(cppConfigFilePath, JSON.stringify(cppConfig, null, 4));
869-
*/
870613
}
871614

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

src/arduino/arduinoContentProvider.ts

-2
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

-3
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[] {

0 commit comments

Comments
 (0)