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

Commit 3da2f76

Browse files
elektronikworkshopadiazulay
authored andcommitted
IntelliSense on/off configuration and compiler parser injection preparation
* Added a global configuration switch which allows the IntelliSense auto-configuration to be turned off * Prepared the compiler parser code to be injected into "upload" and "upload using programmer" without overhead * Updated branch documentation
1 parent bc2b292 commit 3da2f76

File tree

5 files changed

+83
-32
lines changed

5 files changed

+83
-32
lines changed

BRANCHNOTES.md

+19-16
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,17 @@ src/arduino/arduino.ts
4040
| | :heavy_check_mark: Basic file output |
4141
| | :white_check_mark: Merging of parsing result and existing file content |
4242
| | :white_check_mark: Handling inexistent files and folders |
43-
| **Configuration flags** | :white_check_mark: |
43+
| **Configuration flags** | :heavy_check_mark: Disable flag for IntelliSense auto-config |
44+
| | :white_check_mark: Perhaps a general IntelliSense flag `{off/manual, auto, oldstyle}` whereas the old can be removed at some point |
45+
| | :white_check_mark: Fine grained IntelliSense control: Global en-/disable and project override. This is probably more useful since the most boards will hopefully work and for the very special cases the user can disable the feature for this single project but still can enjoy it within his regular projects. |
4446
| **Unit tests** | :white_check_mark: Basic parser (known boards, match/no match)|
4547
| | :white_check_mark: Querying of compiler built-in includes |
4648
| | :white_check_mark: Throwing arbitrary data at parser engines |
4749
| | :white_check_mark: JSON input |
4850
| | :white_check_mark: JSON output |
4951
| | :white_check_mark: Configuration merging |
5052
| **General** | :white_check_mark: Review and remove previous attempts messing with `c_cpp_properties.json` |
51-
| | :white_check_mark: Auto-run verify after setting a board to generate a valid `c_cpp_properties.json`, identify other occasions where this applies |
53+
| | :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*? |
5254

5355
`*` not committed to branch yet
5456

@@ -139,30 +141,31 @@ As one can see with the ESP32-gcc not all include directories are named `include
139141

140142

141143
### Settings
142-
Global user settings, on linux under `~/.config/Code/User/settings.json`, for instance:
144+
#### Global Settings
145+
Under linux at `~/.config/Code/User/settings.json`, for instance:
143146
```json
144147
{
145148
"arduino.additionalUrls": "",
146149
"arduino.logLevel": "verbose",
147-
"C_Cpp.default.cppStandard": "c++11",
148-
"C_Cpp.default.cStandard": "c11",
149150
"arduino.disableTestingOpen": true,
150151
"workbench.editor.enablePreview": false
151152
}
152153
```
153-
Project settings in `.vscode/arduino.json`
154+
Code: [src/arduino/arduinoSettings.ts](src/arduino/arduinoSettings.ts)
155+
Code: [src/arduino/vscodeSettings.ts](src/arduino/vscodeSettings.ts)
156+
Validator: [package.json](package.json)
157+
158+
#### Project Settings
159+
Path in project `.vscode/arduino.json`
154160
```json
155161
{
156-
"board": "arduino:avr:nano",
157-
"configuration": "cpu=atmega328old",
158-
"sketch": "examples/lcdpong-butenc/lcdpong-butenc.ino",
159-
"port": "/dev/ttyUSB0"
160-
}
161-
```
162-
The global settings are [here](src/arduino/vscodeSettings.ts)
163-
```ts
164-
if (VscodeSettings.getInstance().logLevel === "verbose") {
165-
args.push("--verbose");
162+
"board": "arduino:avr:nano",
163+
"configuration": "cpu=atmega328old",
164+
"sketch": "examples/lcdpong-butenc/lcdpong-butenc.ino",
165+
"port": "/dev/ttyUSB0"
166166
}
167167
```
168+
Code: [src/deviceContext.ts](src/deviceContext.ts)
169+
Validator: [misc/arduinoValidator.json](misc/arduinoValidator.json)
170+
168171
### Global Tasks in vscode-arduino

package.json

+5
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,11 @@
504504
"arduino.defaultBaudRate": {
505505
"type": "number",
506506
"default": 115200
507+
},
508+
"arduino.disableIntelliSenseAutoGen": {
509+
"type": "boolean",
510+
"default": false,
511+
"description": "When disabled vscode-arduino will not auto-generate an IntelliSense configuration (i.e. c_cpp_properties.json) by analyzing the compiler output."
507512
}
508513
}
509514
},

src/arduino/arduino.ts

+43-15
Original file line numberDiff line numberDiff line change
@@ -255,29 +255,19 @@ export class ArduinoApp {
255255
}
256256

257257
arduinoChannel.show();
258-
// we need to return the result of verify
258+
259259
try {
260-
const gccParserEngine = new CompilerCmdParserEngineGcc(dc.sketch);
261-
const compilerParser = new CompilerCmdParser([gccParserEngine]);
260+
const compilerParserContext = this.makeCompilerParserContext(dc);
262261

263262
await util.spawn(this._settings.commandPath,
264263
arduinoChannel.channel,
265264
args,
266265
undefined,
267-
compilerParser.callback);
266+
compilerParserContext.callback);
268267

269-
// Write compiler command parser result to IntelliSense
270-
// configuration file in case parsing was successful.
271-
if (compilerParser.result) {
272-
const cppPropsPath = path.join(ArduinoWorkspace.rootPath, constants.CPP_CONFIG_FILE);
273-
const cppProps = new CCppProperties(cppPropsPath);
274-
cppProps.merge(compilerParser.result);
275-
cppProps.write();
276-
arduinoChannel.info("IntelliSense configuration generated successfully.");
277-
} else {
278-
arduinoChannel.warning("Failed to generate IntelliSense configuration.");
268+
if (compilerParserContext.conclude) {
269+
compilerParserContext.conclude();
279270
}
280-
281271
arduinoChannel.end(`Finished verify sketch - ${dc.sketch}${os.EOL}`);
282272
return true;
283273
} catch (reason) {
@@ -803,6 +793,44 @@ export class ArduinoApp {
803793
// return VscodeSettings.getInstance().useArduinoCli;
804794
}
805795

796+
/**
797+
* Creates a context which is used for compiler command parsing
798+
* during building (verify, upload, ...).
799+
*
800+
* This context makes sure that it can be used in those sections
801+
* without having to check whether this feature is en- or disabled
802+
* and keeps the calling context more readable.
803+
*
804+
* @param dc The device context of the caller.
805+
*/
806+
private makeCompilerParserContext(dc: DeviceContext)
807+
: { callback: (s: string) => void; conclude: () => void; } {
808+
if (!VscodeSettings.getInstance().disableIntelliSenseAutoGen) {
809+
810+
// setup the parser with its engines
811+
const gccParserEngine = new CompilerCmdParserEngineGcc(dc.sketch);
812+
const compilerParser = new CompilerCmdParser([gccParserEngine]);
813+
814+
// set up the function to be called after parsing
815+
const _conclude = () => {
816+
const cppPropsPath = path.join(ArduinoWorkspace.rootPath, constants.CPP_CONFIG_FILE);
817+
if (compilerParser.processResult(cppPropsPath)) {
818+
arduinoChannel.info("IntelliSense configuration generated successfully.");
819+
} else {
820+
arduinoChannel.warning("Failed to generate IntelliSense configuration.");
821+
}
822+
};
823+
return {
824+
callback: compilerParser.callback,
825+
conclude: _conclude,
826+
};
827+
}
828+
return {
829+
callback: undefined,
830+
conclude: undefined,
831+
}
832+
};
833+
806834
private getProgrammerString(): string {
807835
const selectProgrammer = this.programmerManager.currentProgrammer;
808836
if (!selectProgrammer) {

src/arduino/intellisense.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class CompilerCmdParserResult {
2626
public defines: Array<string> = [];
2727
public options: Array<string> = [];
2828
public compiler: string = "";
29-
/** Dropped arguments like -c -Ox */
29+
/** Dropped arguments like -c -Ox -o, the input and output file. */
3030
public trash: Array<string> = [];
3131
};
3232

@@ -276,6 +276,15 @@ export class CompilerCmdParser {
276276
}
277277
}
278278
}
279+
public processResult(configPath: string): boolean {
280+
if (this._result) {
281+
const cppProps = new CCppProperties(configPath);
282+
cppProps.merge(this._result);
283+
cppProps.write();
284+
return true;
285+
}
286+
return false;
287+
}
279288
}
280289

281290
/**

src/arduino/vscodeSettings.ts

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const configKeys = {
1616
SKIP_HEADER_PROVIDER: "arduino.skipHeaderProvider",
1717
DEFAULT_BAUD_RATE: "arduino.defaultBaudRate",
1818
USE_ARDUINO_CLI: "arduino.useArduinoCli",
19+
DISABLE_INTELLISENSE_AUTO_GEN: "arduino.disableIntelliSenseAutoGen",
1920
};
2021

2122
export interface IVscodeSettings {
@@ -30,6 +31,7 @@ export interface IVscodeSettings {
3031
skipHeaderProvider: boolean;
3132
defaultBaudRate: number;
3233
useArduinoCli: boolean;
34+
disableIntelliSenseAutoGen: boolean;
3335
updateAdditionalUrls(urls: string | string[]): void;
3436
}
3537

@@ -93,6 +95,10 @@ export class VscodeSettings implements IVscodeSettings {
9395
return this.getConfigValue<boolean>(configKeys.SKIP_HEADER_PROVIDER);
9496
}
9597

98+
public get disableIntelliSenseAutoGen(): boolean {
99+
return this.getConfigValue<boolean>(configKeys.DISABLE_INTELLISENSE_AUTO_GEN);
100+
}
101+
96102
public async updateAdditionalUrls(value) {
97103
await this.setConfigValue(configKeys.ADDITIONAL_URLS, value, true);
98104
}

0 commit comments

Comments
 (0)