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

Commit

Permalink
Removed IS-REMOVE code
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
elektronikworkshop authored and adiazulay committed Jan 19, 2021
1 parent 31e530c commit d408686
Show file tree
Hide file tree
Showing 12 changed files with 15 additions and 321 deletions.
18 changes: 11 additions & 7 deletions BRANCHNOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ During merging I found some bugs within those functions - mainly due to the abov
**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)
**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`.
**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.
**2020 02 26** Preparing for pull request: Removed all code marked `IS-REMOVE` and dead code which I was able to identify.

## Status
| | Tasks |
Expand All @@ -115,23 +116,23 @@ During merging I found some bugs within those functions - mainly due to the abov
| **Unit tests** | :heavy_check_mark: Basic parser (known boards, match/no match)|
| | :heavy_check_mark: All unit tests in cocopa |
| | :heavy_check_mark: Test with cpp sketches |
| **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) `*` |
| **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) |
| | :heavy_check_mark: *Auto-run verify when* |
| |     :heavy_check_mark: a) setting a board `*` |
| |     :heavy_check_mark: b) changing the board's configuration `*` |
| |     :heavy_check_mark: c) selecting another sketch `*` |
| |     :heavy_check_mark: a) setting a board |
| |     :heavy_check_mark: b) changing the board's configuration |
| |     :heavy_check_mark: c) selecting another sketch |
| |     :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 |
| |     :white_check_mark: e) Identify other occasions where this applies (usually when adding new libraries) -- any suggestions? |
| | :heavy_check_mark: Hint the user to run *Arduino: Rebuild IntelliSense Configuration* -> printing message after each build (verify, upload, ...) |
| | :heavy_check_mark: Better build management such that regular builds and analyze builds do not interfere (done, 2020-02-19) `*` |
| | :heavy_check_mark: Analyze task queue which fits in the latter (done, 2020-02-19) `*` |
| | :heavy_check_mark: Better build management such that regular builds and analyze builds do not interfere (done, 2020-02-19) |
| | :heavy_check_mark: Analyze task queue which fits in the latter (done, 2020-02-19) |
| | :heavy_check_mark: Document configuration settings in [README.md](README.md) |
| | :heavy_check_mark: Document features in [README.md](README.md) |
| | :heavy_check_mark: Try to auto-generate even if verify (i.e. compilation) fails |
| | :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) |
| | :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) |
| | :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 |
| | :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 `*`|
| | :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 |
| | :white_check_mark: Finally: go through my code and look for TODOs |

`*` not committed to branch yet
Expand Down Expand Up @@ -217,6 +218,9 @@ I will list every supporter here, thanks!
* When having adding a library folder to the workspace IntelliSense should use the same configuration for it to enable library navigation and code completion.
* Optimization: Abort analysis build as soon as compiler statement has been found
* Non-IDE unit testing - to eliminate dependency injection use ts-mock-imports for instance
* Remove dead code
* Identify bad code and rework it
* 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.)
* Hardcoded and scattered constants:
* 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`)
* Line splitting and other regexes
Expand Down
257 changes: 0 additions & 257 deletions src/arduino/arduino.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,162 +420,6 @@ export class ArduinoApp {
return success;
}

// IS-REMOVE: to be removed completely when IntelliSense implementation is merged
/*
public tryToUpdateIncludePaths() {
const configFilePath = path.join(ArduinoWorkspace.rootPath, constants.CPP_CONFIG_FILE);
if (!fs.existsSync(configFilePath)) {
return;
}
const cppConfigFile = fs.readFileSync(configFilePath, "utf8");
const cppConfig = JSON.parse(cppConfigFile) as { configurations: Array<{
includePath: string[],
forcedInclude: string[],
defines: string[],
}> };
const libPaths = this.getDefaultPackageLibPaths();
const defaultForcedInclude = this.getDefaultForcedIncludeFiles();
const defines = this.getDefaultDefines();
const configuration = cppConfig.configurations[0];
let cppConfigFileUpdated = false;
// cpp extension changes \\ to \\\\ in paths in JSON string, revert them first
configuration.includePath = configuration.includePath.map((path) => path.replace(/\\\\/g, "\\"));
configuration.forcedInclude = configuration.forcedInclude.map((path) => path.replace(/\\\\/g, "\\"));
configuration.defines = configuration.defines.map((path) => path.replace(/\\\\/g, "\\"));
for (const libPath of libPaths) {
if (configuration.includePath.indexOf(libPath) === -1) {
cppConfigFileUpdated = true;
configuration.includePath.push(libPath);
}
}
for (const forcedIncludePath of defaultForcedInclude) {
if (configuration.forcedInclude.indexOf(forcedIncludePath) === -1) {
cppConfigFileUpdated = true;
configuration.forcedInclude.push(forcedIncludePath);
}
}
for (const define of defines) {
if (configuration.defines.indexOf(define) === -1) {
cppConfigFileUpdated = true;
configuration.defines.push(define);
}
}
*/
// remove all unexisting paths
// concern mistake removal, comment temporary
// for (let pathIndex = 0; pathIndex < configuration.includePath.length; pathIndex++) {
// let libPath = configuration.includePath[pathIndex];
// if (libPath.indexOf("${workspaceFolder}") !== -1) {
// continue;
// }
// if (/\*$/.test(libPath)) {
// libPath = libPath.match(/^[^\*]*/)[0];
// }
// if (!fs.existsSync(libPath)) {
// cppConfigFileUpdated = true;
// configuration.includePath.splice(pathIndex, 1);
// pathIndex--;
// }
// }
// for (let pathIndex = 0; pathIndex < configuration.forcedInclude.length; pathIndex++) {
// const forcedIncludePath = configuration.forcedInclude[pathIndex];
// if (forcedIncludePath.indexOf("${workspaceFolder}") !== -1) {
// continue;
// }
// if (!fs.existsSync(forcedIncludePath)) {
// cppConfigFileUpdated = true;
// configuration.forcedInclude.splice(pathIndex, 1);
// pathIndex--;
// }
// }
/*
if (cppConfigFileUpdated) {
fs.writeFileSync(configFilePath, JSON.stringify(cppConfig, null, 4));
}
}
*/

// IS-REMOVE: to be removed completely when IntelliSense implementation is merged
/*
// Add selected library path to the intellisense search path.
public addLibPath(libraryPath: string) {
let libPaths;
if (libraryPath) {
libPaths = [libraryPath];
} else {
libPaths = this.getDefaultPackageLibPaths();
}
const defaultForcedInclude = this.getDefaultForcedIncludeFiles();
const defaultDefines = this.getDefaultDefines();
if (!ArduinoWorkspace.rootPath) {
return;
}
const configFilePath = path.join(ArduinoWorkspace.rootPath, constants.CPP_CONFIG_FILE);
let deviceContext = null;
if (!util.fileExistsSync(configFilePath)) {
util.mkdirRecursivelySync(path.dirname(configFilePath));
deviceContext = {};
} else {
deviceContext = util.tryParseJSON(fs.readFileSync(configFilePath, "utf8"));
}
if (!deviceContext) {
logger.notifyAndThrowUserError("arduinoFileError", new Error(constants.messages.ARDUINO_FILE_ERROR));
}
deviceContext.configurations = deviceContext.configurations || [];
let configSection = null;
deviceContext.configurations.forEach((section) => {
if (section.name === util.getCppConfigPlatform()) {
configSection = section;
}
});
if (!configSection) {
configSection = {
name: util.getCppConfigPlatform(),
includePath: [],
};
deviceContext.configurations.push(configSection);
}
libPaths.forEach((childLibPath) => {
childLibPath = path.resolve(path.normalize(childLibPath));
if (configSection.includePath && configSection.includePath.length) {
for (const existingPath of configSection.includePath) {
if (childLibPath === path.resolve(path.normalize(existingPath))) {
return;
}
}
} else {
configSection.includePath = [];
}
configSection.includePath.unshift(childLibPath);
});
if (!configSection.forcedInclude) {
configSection.forcedInclude = defaultForcedInclude;
} else {
for (let i = 0; i < configSection.forcedInclude.length; i++) {
if (/arduino\.h$/i.test(configSection.forcedInclude[i])) {
configSection.forcedInclude.splice(i, 1);
i--;
}
}
configSection.forcedInclude = defaultForcedInclude.concat(configSection.forcedInclude);
}
if (!configSection.defines) {
configSection.defines = defaultDefines;
}
fs.writeFileSync(configFilePath, JSON.stringify(deviceContext, null, 4));
}
*/
// Include the *.h header files from selected library to the arduino sketch.
public async includeLibrary(libraryPath: string) {
if (!ArduinoWorkspace.rootPath) {
Expand Down Expand Up @@ -719,67 +563,6 @@ export class ArduinoApp {
arduinoChannel.end(`Removed library - ${libName}${os.EOL}`);
}

// IS-REMOVE: to be removed completely when IntelliSense implementation is merged
/*
public getDefaultPackageLibPaths(): string[] {
const result = [];
const boardDescriptor = this._boardManager.currentBoard;
if (!boardDescriptor) {
return result;
}
const toolsPath = boardDescriptor.platform.rootBoardPath;
result.push(path.normalize(path.join(toolsPath, "**")));
const hardwareToolPath = path.join(toolsPath, "..", "..", "tools");
if (fs.existsSync(hardwareToolPath)) {
result.push(path.normalize(path.join(hardwareToolPath, "**")));
}
// Add default libraries to include path
result.push(path.normalize(path.join(this._settings.defaultLibPath, "**")));
const userLibsPath = (path.join(this._settings.sketchbookPath, "libraries", "**"));
result.push(userLibsPath);
// if (util.directoryExistsSync(path.join(toolsPath, "cores"))) {
// const coreLibs = fs.readdirSync(path.join(toolsPath, "cores"));
// if (coreLibs && coreLibs.length > 0) {
// coreLibs.forEach((coreLib) => {
// result.push(path.normalize(path.join(toolsPath, "cores", coreLib)));
// });
// }
// }
// return result;
// <package>/hardware/<platform>/<version> -> <package>/tools
const toolPath = path.join(toolsPath, "..", "..", "..", "tools");
if (fs.existsSync(toolPath)) {
result.push(path.normalize(path.join(toolPath, "**")));
}
return result;
}*/

// IS-REMOVE: to be removed completely when IntelliSense implementation is merged
/*
public getDefaultForcedIncludeFiles(): string[] {
const result = [];
const boardDescriptor = this._boardManager.currentBoard;
if (!boardDescriptor) {
return result;
}
const arduinoHeadFilePath = path.normalize(path.join(boardDescriptor.platform.rootBoardPath, "cores", "arduino", "Arduino.h"));
if (fs.existsSync(arduinoHeadFilePath)) {
result.push(arduinoHeadFilePath);
}
return result;
}
public getDefaultDefines(): string[] {
const result = [];
// USBCON is required in order for Serial to be recognized by intellisense
result.push("USBCON");
return result;
}
*/

public openExample(example) {
function tmpName(name) {
let counter = 0;
Expand Down Expand Up @@ -827,46 +610,6 @@ export class ArduinoApp {
const arduinoConfigFilePath = path.join(destExample, constants.ARDUINO_CONFIG_FILE);
util.mkdirRecursivelySync(path.dirname(arduinoConfigFilePath));
fs.writeFileSync(arduinoConfigFilePath, JSON.stringify(arduinoJson, null, 4));

// IS-REMOVE: to be removed completely when IntelliSense implementation is merged
/*
// Generate cpptools intellisense config
const cppConfigFilePath = path.join(destExample, constants.CPP_CONFIG_FILE);
// Current workspace
let includePath = ["${workspaceRoot}"];
// Defaut package for this board
const defaultPackageLibPaths = this.getDefaultPackageLibPaths();
includePath = includePath.concat(defaultPackageLibPaths);
// Arduino built-in package tools
includePath.push(path.join(this._settings.arduinoPath, "hardware", "tools", "**"));
// Arduino built-in libraries
includePath.push(path.join(this._settings.arduinoPath, "libraries", "**"));
// Arduino custom package tools
includePath.push(path.join(this._settings.sketchbookPath, "hardware", "tools", "**"));
// Arduino custom libraries
includePath.push(path.join(this._settings.sketchbookPath, "libraries", "**"));
const forcedInclude = this.getDefaultForcedIncludeFiles();
const defines = [
"ARDUINO=10800",
];
const cppConfig = {
configurations: [{
name: util.getCppConfigPlatform(),
defines,
includePath,
forcedInclude,
intelliSenseMode: "clang-x64",
cStandard: "c11",
cppStandard: "c++17",
}],
version: 3,
};
util.mkdirRecursivelySync(path.dirname(cppConfigFilePath));
fs.writeFileSync(cppConfigFilePath, JSON.stringify(cppConfig, null, 4));
*/
}

// Step 3: Open the arduino project at a new vscode window.
Expand Down
2 changes: 0 additions & 2 deletions src/arduino/arduinoContentProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,6 @@ export class ArduinoContentProvider implements vscode.TextDocumentContentProvide
return res.status(400).send("BAD Request! Missing { libraryPath } parameters!");
} else {
try {
// IS-REMOVE: to be removed completely when IntelliSense implementation is merged
// await ArduinoContext.arduinoApp.addLibPath(req.body.libraryPath);
await ArduinoContext.arduinoApp.includeLibrary(req.body.libraryPath);
return res.json({
status: "OK",
Expand Down
3 changes: 0 additions & 3 deletions src/arduino/boardManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,6 @@ export class BoardManager {
// correct board and configuration. We know that it will trigger - we
// made sure above that the boards actually differ
dc.board = targetBoard.key;

// IS-REMOVE: to be removed completely when IntelliSense implementation is merged
// this._arduinoApp.addLibPath(null);
}

public get packages(): IPackage[] {
Expand Down
Loading

0 comments on commit d408686

Please sign in to comment.