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

Commit 6a42d3f

Browse files
elektronikworkshopadiazulay
authored andcommitted
Moved intellisense function to a separate file
1 parent 4f6565c commit 6a42d3f

File tree

6 files changed

+175
-151
lines changed

6 files changed

+175
-151
lines changed

BRANCHNOTES.md

+3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Provide a configuration flag which allows the user to turn this feature off - th
4949
| | :white_check_mark: Document features in [README.md](README.md) (partially done) |
5050
| | :heavy_check_mark: Try to auto-generate even if verify (i.e. compilation) fails |
5151
| | :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) |
52+
| | :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. |
5253
| | :white_check_mark: Finally: go through my code and look for TODOs |
5354

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

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

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

9295
## Issues Concerning this Project
9396
* https://github.com/Microsoft/vscode-cpptools/issues/1750

package-lock.json

+69-49
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-4
Original file line numberDiff line numberDiff line change
@@ -564,10 +564,11 @@
564564
"devDependencies": {
565565
"@types/compare-versions": "^3.0.0",
566566
"@types/mocha": "^5.2.7",
567-
"@types/node": "^6.0.40",
567+
"@types/node": "^6.14.9",
568568
"@types/vscode": "^1.43.0",
569569
"@types/winreg": "^1.2.30",
570570
"acorn": "^7.4.0",
571+
"ajv": "^5.0.0",
571572
"del": "^2.2.2",
572573
"eslint": "^6.8.0",
573574
"eslint-config-standard": "^10.2.1",
@@ -594,12 +595,10 @@
594595
},
595596
"dependencies": {
596597
"body-parser": "^1.16.1",
597-
"child_process": "^1.0.2",
598-
"cocopa": "0.0.6",
598+
"cocopa": "^0.0.7",
599599
"compare-versions": "^3.4.0",
600600
"eventemitter2": "^4.1.0",
601601
"express": "^4.14.1",
602-
"fs": "0.0.1-security",
603602
"glob": "^7.1.1",
604603
"iconv-lite": "^0.4.18",
605604
"impor": "^0.1.1",

src/arduino/arduino.ts

+2-88
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

4-
import * as ccp from "cocopa";
54
import * as fs from "fs";
65
import * as glob from "glob";
76
import * as os from "os";
@@ -23,6 +22,7 @@ import { arduinoChannel } from "../common/outputChannel";
2322
import { ArduinoWorkspace } from "../common/workspace";
2423
import { SerialMonitor } from "../serialmonitor/serialMonitor";
2524
import { UsbDetector } from "../serialmonitor/usbDetector";
25+
import { makeCompilerParserContext } from "./intellisense";
2626
import { ProgrammerManager } from "./programmerManager";
2727

2828
/**
@@ -257,7 +257,7 @@ export class ArduinoApp {
257257
arduinoChannel.show();
258258

259259
let verifyResult: boolean;
260-
const compilerParserContext = this.makeCompilerParserContext(dc);
260+
const compilerParserContext = makeCompilerParserContext(dc);
261261

262262
try {
263263
await util.spawn(this._settings.commandPath,
@@ -796,92 +796,6 @@ export class ArduinoApp {
796796
// return VscodeSettings.getInstance().useArduinoCli;
797797
}
798798

799-
/**
800-
* Creates a context which is used for compiler command parsing
801-
* during building (verify, upload, ...).
802-
*
803-
* This context makes sure that it can be used in those sections
804-
* without having to check whether this feature is en- or disabled
805-
* and keeps the calling context more readable.
806-
*
807-
* @param dc The device context of the caller.
808-
*/
809-
private makeCompilerParserContext(dc: DeviceContext)
810-
: { callback: (s: string) => void; conclude: () => void; } {
811-
812-
const globalDisable = VscodeSettings.getInstance().disableIntelliSenseAutoGen;
813-
const project = dc.disableIntelliSenseAutoGen;
814-
815-
if (project !== "disable" && !globalDisable ||
816-
project === "enable") {
817-
818-
const engines = this.makeCompilerParserEngines(dc);
819-
const runner = new ccp.Runner(engines);
820-
821-
// set up the function to be called after parsing
822-
const _conclude = () => {
823-
if (!runner.result) {
824-
arduinoChannel.warning("Failed to generate IntelliSense configuration.");
825-
return;
826-
}
827-
const pPath = path.join(ArduinoWorkspace.rootPath, constants.CPP_CONFIG_FILE);
828-
// TODO: check what kind of result we've got: gcc or other architecture:
829-
// and instantiate content accordingly (to be implemented within cocopa)
830-
const content = new ccp.CCppPropertiesContentResult(runner.result,
831-
"Arduino",
832-
ccp.CCppPropertiesISMode.Gcc_X64,
833-
ccp.CCppPropertiesCStandard.C11,
834-
// as of 1.8.11 arduino is on C++11
835-
ccp.CCppPropertiesCppStandard.Cpp11);
836-
const prop = new ccp.CCppProperties();
837-
prop.read(pPath);
838-
prop.merge(content, ccp.CCppPropertiesMergeMode.ReplaceSameNames);
839-
if (prop.write(pPath)) {
840-
arduinoChannel.info("IntelliSense configuration updated.");
841-
} else {
842-
arduinoChannel.info("IntelliSense configuration already up to date.");
843-
}
844-
};
845-
return {
846-
callback: runner.callback(),
847-
conclude: _conclude,
848-
};
849-
}
850-
return {
851-
callback: undefined,
852-
conclude: undefined,
853-
}
854-
};
855-
856-
/**
857-
*
858-
* @param dc
859-
*/
860-
private makeCompilerParserEngines(dc: DeviceContext) {
861-
862-
let sketch = path.basename(dc.sketch);
863-
const dotcpp = sketch.endsWith(".ino") ? ".cpp" : "";
864-
sketch = `-o\\s+\\S*${ccp.regExEscape(sketch)}${dotcpp}\\.o`;
865-
866-
const matchPattern = [
867-
// make sure we're running g++
868-
/(?:^|-)g\+\+\s+/,
869-
// make sure we're compiling
870-
/\s+-c\s+/,
871-
// trigger parser when compiling the main sketch
872-
RegExp(sketch),
873-
];
874-
875-
const dontMatchPattern = [
876-
// make sure Arduino's not testing libraries
877-
/-o\s+\/dev\/null/,
878-
];
879-
880-
// setup the parser with its engines
881-
const gccParserEngine = new ccp.ParserGcc(matchPattern, dontMatchPattern);
882-
return [gccParserEngine];
883-
}
884-
885799
private getProgrammerString(): string {
886800
const selectProgrammer = this.programmerManager.currentProgrammer;
887801
if (!selectProgrammer) {

0 commit comments

Comments
 (0)