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

Commit 819d2f1

Browse files
elektronikworkshopadiazulay
authored andcommitted
Added IntelliSense setup auto-generation project (sketch-context) configuration flag which can override the global flag
1 parent f28dd7e commit 819d2f1

File tree

5 files changed

+60
-8
lines changed

5 files changed

+60
-8
lines changed

BRANCHNOTES.md

+12-5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Provide a configuration flag which allows the user to turn this feature off - th
1818
### Status
1919
**2020-02-05** Currently I'm able to generate error free IntelliSense setups for AVR and ESP32 using the preliminary implementation. For ESP32 I just had to add the intrinsic compiler paths manually. A solution has to be found for these ... which there is, see [here](https://stackoverflow.com/a/6666338)
2020
**2020-02-06** Got it fully working (with built-in include directories) for AVR, ESP32, ESP8266. Rewrote the backend to facilitate writing of further parser engines in the future.
21+
**2020-02-07** Wrote compiler command parser npm package [cocopa](https://www.npmjs.com/package/cocopa) and began writing a test framework for it. Added a global configuration switch which allows the IntelliSense configuration generation to be turned off.
22+
**2020-02-08** Integrated `cocopa` into vscode-arduino. Added project configuration flag which can override the global flag in both ways (forced off, forced on). Made code tslint compliant. Began some documentation in [README.md](README.md)
2123

2224
| | Tasks |
2325
|-----:|:--------|
@@ -35,17 +37,17 @@ Provide a configuration flag which allows the user to turn this feature off - th
3537
| | :white_check_mark: Write configuration on change only |
3638
| | :white_check_mark: Option to backup old configurations? |
3739
| **Configuration flags** | :heavy_check_mark: Provide global disable flag for IntelliSense auto-config |
38-
| | :white_check_mark: Provide project specific override for the global flag - most users will likely use the default setup and disable auto-generation for very specific projects |
40+
| | :heavy_check_mark: Provide project specific override for the global flag - most users will likely use the default setup and disable auto-generation for very specific projects |
3941
| **Unit tests** | :heavy_check_mark: Basic parser (known boards, match/no match)|
4042
| | :heavy_check_mark: Querying of compiler built-in includes (Note: to be changed to generic compiler such that Arduino is not necessary for unit testing) |
4143
| | :white_check_mark: Throwing arbitrary data at parser engines |
4244
| | :white_check_mark: JSON input |
4345
| | :white_check_mark: JSON output |
4446
| | :white_check_mark: Configuration merging |
4547
| **General** | :white_check_mark: Review and remove previous attempts messing with `c_cpp_properties.json` or IntelliSense. (Partially done - documented in the [General Tasks](#General-Tasks) section |
46-
| | :white_check_mark: Auto-run verify after setting a board to generate a valid `c_cpp_properties.json`, identify other occasions where this applies (usually when adding new libraries), hint the user to run *verify*? -> Good moment would be after the workbench initialization -> message in arduino channel |
47-
| | :white_check_mark: Document configuration settings in [README.md](README.md) |
48-
| | :white_check_mark: Document features in [README.md](README.md) |
48+
| | :white_check_mark: Auto-run verify after a) *setting a board* b) *changing the sketch*. We have to generate a valid `c_cpp_properties.json` to keep IntelliSense working in such situations. Identify other occasions where this applies (usually when adding new libraries), hint the user to run *verify*? -> Good moment would be after the workbench initialization -> message in arduino channel |
49+
| | :heavy_check_mark: Document configuration settings in [README.md](README.md) |
50+
| | :white_check_mark: Document features in [README.md](README.md) (partially done) |
4951
| | :white_check_mark: How to handle compilation failure? Only set if more comprehensive |
5052
| | :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) |
5153
| | :white_check_mark: Finally: go through my code and look for TODOs |
@@ -67,7 +69,7 @@ I will list every supporter here, thanks!
6769

6870
### Supporters
6971
5$ -> 1 :beer:
70-
1h coding -> 20$ -> 4 :beers:
72+
1h coding -> 20$ -> 4 :beers: (very moderate wage though)
7173
2020-02-04 Elektronik Workshop: 32 :beers: (8h coding)
7274
2020-02-05 Elektronik Workshop: 40 :beers: (10h coding)
7375
2020-02-06 Elektronik Workshop: 36 :beers: (9h coding)
@@ -194,3 +196,8 @@ Remove these as they are helpless attempts to get IntelliSense working:
194196
```
195197
Remove this as this messes in an unpredictable and helpless way with Intellisense
196198
[src/langService/completionProvider.ts](src/langService/completionProvider.ts)
199+
200+
Remove this folder as this is not necessary when Intellisense works properly:
201+
```
202+
syntaxes/
203+
```

README.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ This extension provides several commands in the Command Palette (<kbd>F1</kbd> o
6767
| `arduino.disableTestingOpen` | Enable/disable automatic sending of a test message to the serial port for checking the open status. The default value is `false` (a test message will be sent). |
6868
| `arduino.skipHeaderProvider` | Enable/disable the extension providing completion items for headers. This functionality is included in newer versions of the C++ extension. The default value is `false`.|
6969
| `arduino.defaultBaudRate` | Default baud rate for the serial port monitor. The default value is 115200. Supported values are 300, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 74880, 115200, 230400 and 250000 |
70+
| `arduino.disableIntelliSenseAutoGen` | When `true` vscode-arduino will not auto-generate an IntelliSense configuration (i.e. `.vscode/c_cpp_properties.json`) by analyzing Arduino's compiler output. |
7071

7172
The following Visual Studio Code settings are available for the Arduino extension. These can be set in global user preferences <kbd>Ctrl</kbd> + <kbd>,</kbd> or workspace settings (`.vscode/settings.json`). The latter overrides the former.
7273

@@ -98,7 +99,8 @@ The following settings are as per sketch settings of the Arduino extension. You
9899
"board": "adafruit:samd:adafruit_feather_m0",
99100
"output": "../build",
100101
"debugger": "jlink",
101-
"prebuild": "bash prebuild.sh"
102+
"prebuild": "bash prebuild.sh",
103+
"disableIntelliSenseAutoGen": "global"
102104
}
103105
```
104106
- `sketch` - The main sketch file name of Arduino.
@@ -107,6 +109,14 @@ The following settings are as per sketch settings of the Arduino extension. You
107109
- `output` - Arduino build output path. If not set, Arduino will create a new temporary output folder each time, which means it cannot reuse the intermediate result of the previous build leading to long verify/upload time, so it is recommended to set the field. Arduino requires that the output path should not be the workspace itself or in a subfolder of the workspace, otherwise, it may not work correctly. By default, this option is not set. It's worth noting that the contents of this file could be deleted during the build process, so pick (or create) a directory that will not store files you want to keep.
108110
- `debugger` - The short name of the debugger that will be used when the board itself does not have a debugger and there is more than one debugger available. You can find the list of debuggers [here](https://github.com/Microsoft/vscode-arduino/blob/master/misc/debuggerUsbMapping.json). By default, this option is not set.
109111
- `prebuild` - External command before building the sketch file. You should only set one `prebuild` command. `command1 && command2` does not work. If you need to run multiple commands before the build, then create a script.
112+
- `disableIntelliSenseAutoGen` - Override the global auto-generation of the IntelliSense configuration (i.e. `.vscode/c_cpp_properties.json`). Three options are available:
113+
- `"global"`: Use the global settings (default)
114+
- `"disable"`: Disable the auto-generation even if globally enabled
115+
- `"enable"`: Enable the auto-generation even if globally disabled
116+
117+
## IntelliSense
118+
vscode-arduino auto-configures IntelliSense by default. vscode-arduino analyzes Arduino's compiler output during verify and generates the corresponding configuration file at `.vscode/c_cpp_properties.json` and tries as hard as possible to keep things up to date, e.g. running verify when switching the board or the sketch.
119+
It doesn't makes sense though to run verify repeatedly. Therefore if the workspace reports problems (for instance after adding new includes to a new library) run *verify* such that IntelliSense knows of the new include directories (since the Arduino-backend performs the library resolution externally).
110120

111121
## Debugging Arduino Code <sup>preview</sup>
112122
Before you start to debug your Arduino code, please read [this document](https://code.visualstudio.com/docs/editor/debugging) to learn about the basic mechanisms of debugging in Visual Studio Code. Also see [debugging for C++ in VSCode](https://code.visualstudio.com/docs/languages/cpp#_debugging) for further reference.

misc/arduinoValidator.json

+11-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@
3232
"description": "Arduino Debugger Settings",
3333
"type": "string",
3434
"minLength": 1
35+
},
36+
"disableIntelliSenseAutoGen": {
37+
"description": "Disable/enable the automatic generation of the IntelliSense configuration file (c_cpp_properties.json) for this project (overrides the global setting). When set to \"global\" the global extension settings will be used.",
38+
"type": "string",
39+
"default": "global",
40+
"enum": [
41+
"global",
42+
"disable",
43+
"enable"
44+
]
3545
}
3646
}
37-
}
47+
}

src/arduino/arduino.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,12 @@ export class ArduinoApp {
805805
*/
806806
private makeCompilerParserContext(dc: DeviceContext)
807807
: { callback: (s: string) => void; conclude: () => void; } {
808-
if (!VscodeSettings.getInstance().disableIntelliSenseAutoGen) {
808+
809+
const globalDisable = VscodeSettings.getInstance().disableIntelliSenseAutoGen;
810+
const project = dc.disableIntelliSenseAutoGen;
811+
812+
if (project !== "disable" && !globalDisable ||
813+
project === "enable") {
809814

810815
// setup the parser with its engines
811816
const gccParserEngine = new ccp.ParserGcc(dc.sketch);

src/deviceContext.ts

+20
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ export interface IDeviceContext {
5757
*/
5858
configuration: string;
5959

60+
/**
61+
* IntelliSense configuration auto-generation project override.
62+
*/
63+
disableIntelliSenseAutoGen: string;
64+
6065
onDidChange: vscode.Event<void>;
6166

6267
initialize(): void;
@@ -82,6 +87,8 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable {
8287

8388
private _debugger: string;
8489

90+
private _disableIntelliSenseAutoGen: string;
91+
8592
private _configuration: string;
8693

8794
private _extensionPath: string;
@@ -151,6 +158,7 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable {
151158
this._configuration = deviceConfigJson.configuration;
152159
this._output = deviceConfigJson.output;
153160
this._debugger = deviceConfigJson["debugger"];
161+
this._disableIntelliSenseAutoGen = deviceConfigJson.disableIntelliSenseAutoGen;
154162
this._prebuild = deviceConfigJson.prebuild;
155163
this._programmer = deviceConfigJson.programmer;
156164
this._onDidChange.fire();
@@ -164,6 +172,7 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable {
164172
this._configuration = null;
165173
this._output = null;
166174
this._debugger = null;
175+
this._disableIntelliSenseAutoGen = null;
167176
this._prebuild = null;
168177
this._programmer = null;
169178
this._onDidChange.fire();
@@ -182,6 +191,7 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable {
182191
this._configuration = null;
183192
this._output = null;
184193
this._debugger = null;
194+
this._disableIntelliSenseAutoGen = null;
185195
this._prebuild = null;
186196
this._programmer = null;
187197
this._onDidChange.fire();
@@ -217,6 +227,7 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable {
217227
deviceConfigJson.board = this.board;
218228
deviceConfigJson.output = this.output;
219229
deviceConfigJson["debugger"] = this.debugger_;
230+
deviceConfigJson.disableIntelliSenseAutoGen = this.disableIntelliSenseAutoGen;
220231
deviceConfigJson.configuration = this.configuration;
221232
deviceConfigJson.programmer = this.programmer;
222233

@@ -282,6 +293,15 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable {
282293
this.saveContext();
283294
}
284295

296+
public get disableIntelliSenseAutoGen() {
297+
return this._disableIntelliSenseAutoGen;
298+
}
299+
300+
public set disableIntelliSenseAutoGen(value: string) {
301+
this._disableIntelliSenseAutoGen = value;
302+
this.saveContext();
303+
}
304+
285305
public get configuration() {
286306
return this._configuration;
287307
}

0 commit comments

Comments
 (0)