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

Commit

Permalink
Moved intellisense function to a separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
elektronikworkshop authored and adiazulay committed Jan 19, 2021
1 parent 4f6565c commit 6a42d3f
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 151 deletions.
3 changes: 3 additions & 0 deletions BRANCHNOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Provide a configuration flag which allows the user to turn this feature off - th
| | :white_check_mark: Document features in [README.md](README.md) (partially done) |
| | :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) |
| | :white_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. |
| | :white_check_mark: Finally: go through my code and look for TODOs |

`*` not committed to branch yet
Expand Down Expand Up @@ -79,6 +80,7 @@ I will list every supporter here, thanks!
2020-02-07 Elektronik Workshop: 48 :beers: (12h coding)
2020-02-08 Elektronik Workshop: 52 :beers: (13h coding)
2020-02-09 Elektronik Workshop: 40 :beers: (10h coding)
2020-02-10 Elektronik Workshop: 32 :beers: (8h coding)

<!-- https://github.com/StylishThemes/GitHub-Dark/wiki/Emoji -->

Expand All @@ -88,6 +90,7 @@ I will list every supporter here, thanks!
* [Interactive regex debugger](https://regex101.com/)
* [Git branch management](https://blog.scottlowe.org/2015/01/27/using-fork-branch-git-workflow/)
* [Collapsible Markdown](https://gist.githubusercontent.com/joyrexus/16041f2426450e73f5df9391f7f7ae5f/raw/f774f242feff6bae4a5be7d6c71aa5df2e3fcb0e/README.md)
* [Arduino CLI manpage](https://github.com/arduino/Arduino/blob/master/build/shared/manpage.adoc)

## Issues Concerning this Project
* https://github.com/Microsoft/vscode-cpptools/issues/1750
Expand Down
118 changes: 69 additions & 49 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -564,10 +564,11 @@
"devDependencies": {
"@types/compare-versions": "^3.0.0",
"@types/mocha": "^5.2.7",
"@types/node": "^6.0.40",
"@types/node": "^6.14.9",
"@types/vscode": "^1.43.0",
"@types/winreg": "^1.2.30",
"acorn": "^7.4.0",
"ajv": "^5.0.0",
"del": "^2.2.2",
"eslint": "^6.8.0",
"eslint-config-standard": "^10.2.1",
Expand All @@ -594,12 +595,10 @@
},
"dependencies": {
"body-parser": "^1.16.1",
"child_process": "^1.0.2",
"cocopa": "0.0.6",
"cocopa": "^0.0.7",
"compare-versions": "^3.4.0",
"eventemitter2": "^4.1.0",
"express": "^4.14.1",
"fs": "0.0.1-security",
"glob": "^7.1.1",
"iconv-lite": "^0.4.18",
"impor": "^0.1.1",
Expand Down
90 changes: 2 additions & 88 deletions src/arduino/arduino.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

import * as ccp from "cocopa";
import * as fs from "fs";
import * as glob from "glob";
import * as os from "os";
Expand All @@ -23,6 +22,7 @@ import { arduinoChannel } from "../common/outputChannel";
import { ArduinoWorkspace } from "../common/workspace";
import { SerialMonitor } from "../serialmonitor/serialMonitor";
import { UsbDetector } from "../serialmonitor/usbDetector";
import { makeCompilerParserContext } from "./intellisense";
import { ProgrammerManager } from "./programmerManager";

/**
Expand Down Expand Up @@ -257,7 +257,7 @@ export class ArduinoApp {
arduinoChannel.show();

let verifyResult: boolean;
const compilerParserContext = this.makeCompilerParserContext(dc);
const compilerParserContext = makeCompilerParserContext(dc);

try {
await util.spawn(this._settings.commandPath,
Expand Down Expand Up @@ -796,92 +796,6 @@ export class ArduinoApp {
// return VscodeSettings.getInstance().useArduinoCli;
}

/**
* Creates a context which is used for compiler command parsing
* during building (verify, upload, ...).
*
* This context makes sure that it can be used in those sections
* without having to check whether this feature is en- or disabled
* and keeps the calling context more readable.
*
* @param dc The device context of the caller.
*/
private makeCompilerParserContext(dc: DeviceContext)
: { callback: (s: string) => void; conclude: () => void; } {

const globalDisable = VscodeSettings.getInstance().disableIntelliSenseAutoGen;
const project = dc.disableIntelliSenseAutoGen;

if (project !== "disable" && !globalDisable ||
project === "enable") {

const engines = this.makeCompilerParserEngines(dc);
const runner = new ccp.Runner(engines);

// set up the function to be called after parsing
const _conclude = () => {
if (!runner.result) {
arduinoChannel.warning("Failed to generate IntelliSense configuration.");
return;
}
const pPath = path.join(ArduinoWorkspace.rootPath, constants.CPP_CONFIG_FILE);
// TODO: check what kind of result we've got: gcc or other architecture:
// and instantiate content accordingly (to be implemented within cocopa)
const content = new ccp.CCppPropertiesContentResult(runner.result,
"Arduino",
ccp.CCppPropertiesISMode.Gcc_X64,
ccp.CCppPropertiesCStandard.C11,
// as of 1.8.11 arduino is on C++11
ccp.CCppPropertiesCppStandard.Cpp11);
const prop = new ccp.CCppProperties();
prop.read(pPath);
prop.merge(content, ccp.CCppPropertiesMergeMode.ReplaceSameNames);
if (prop.write(pPath)) {
arduinoChannel.info("IntelliSense configuration updated.");
} else {
arduinoChannel.info("IntelliSense configuration already up to date.");
}
};
return {
callback: runner.callback(),
conclude: _conclude,
};
}
return {
callback: undefined,
conclude: undefined,
}
};

/**
*
* @param dc
*/
private makeCompilerParserEngines(dc: DeviceContext) {

let sketch = path.basename(dc.sketch);
const dotcpp = sketch.endsWith(".ino") ? ".cpp" : "";
sketch = `-o\\s+\\S*${ccp.regExEscape(sketch)}${dotcpp}\\.o`;

const matchPattern = [
// make sure we're running g++
/(?:^|-)g\+\+\s+/,
// make sure we're compiling
/\s+-c\s+/,
// trigger parser when compiling the main sketch
RegExp(sketch),
];

const dontMatchPattern = [
// make sure Arduino's not testing libraries
/-o\s+\/dev\/null/,
];

// setup the parser with its engines
const gccParserEngine = new ccp.ParserGcc(matchPattern, dontMatchPattern);
return [gccParserEngine];
}

private getProgrammerString(): string {
const selectProgrammer = this.programmerManager.currentProgrammer;
if (!selectProgrammer) {
Expand Down
Loading

0 comments on commit 6a42d3f

Please sign in to comment.