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

Commit 22eec09

Browse files
authored
Merge pull request #1480 from microsoft/dev/bemcmorr/add-analyzeonopen
Add analyzeOnOpen and analyzeOnSettingChange
2 parents 1d8c33f + 6b1a1d6 commit 22eec09

File tree

6 files changed

+54
-11
lines changed

6 files changed

+54
-11
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ This extension provides several commands in the Command Palette (<kbd>F1</kbd> o
8282
| `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 |
8383
| `arduino.defaultTimestampFormat` | Format of timestamp printed before each line of Serial Monitor output. You can find list of all available placeholders [here](https://github.com/samsonjs/strftime#supported-specifiers). |
8484
| `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. |
85+
| `arduino.analyzeOnOpen` | When true, automatically run analysis when the project is opened. Only works when `arduino.analyzeOnSettingChange` is true. |
86+
| `arduino.analyzeOnSettingChange` | When true, automatically run analysis when board, configuration, or sketch settings are changed. |
8587

8688
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* <kbd>Cmd</kbd> + <kbd>,</kbd> or workspace settings (`.vscode/settings.json`). The latter overrides the former.
8789

package.json

+10
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,16 @@
541541
"type": "string",
542542
"default": "",
543543
"markdownDescription": "Format of timestamp printed before each line of Serial Monitor output. You can find list of all available placeholders [here](https://github.com/samsonjs/strftime#supported-specifiers)."
544+
},
545+
"arduino.analyzeOnOpen": {
546+
"type": "boolean",
547+
"default": true,
548+
"markdownDescription": "When true, automatically run analysis when the project is opened. Only works when `arduino.analyzeOnSettingChange` is true."
549+
},
550+
"arduino.analyzeOnSettingChange": {
551+
"type": "boolean",
552+
"default": true,
553+
"markdownDescription": "When true, automatically run analysis when board, configuration, or sketch settings are changed."
544554
}
545555
}
546556
},

src/arduino/arduino.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,18 @@ export class ArduinoApp {
101101
}
102102
}
103103

104-
// set up event handling for IntelliSense analysis
105-
const requestAnalysis = async () => {
106-
if (isCompilerParserEnabled()) {
107-
await this._analysisManager.requestAnalysis();
108-
}
109-
};
110-
const dc = DeviceContext.getInstance();
111-
dc.onChangeBoard(requestAnalysis);
112-
dc.onChangeConfiguration(requestAnalysis);
113-
dc.onChangeSketch(requestAnalysis);
104+
if (this._settings.analyzeOnSettingChange) {
105+
// set up event handling for IntelliSense analysis
106+
const requestAnalysis = async () => {
107+
if (isCompilerParserEnabled()) {
108+
await this._analysisManager.requestAnalysis();
109+
}
110+
};
111+
const dc = DeviceContext.getInstance();
112+
dc.onChangeBoard(requestAnalysis);
113+
dc.onChangeConfiguration(requestAnalysis);
114+
dc.onChangeSketch(requestAnalysis);
115+
}
114116
}
115117

116118
/**

src/arduino/arduinoSettings.ts

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export interface IArduinoSettings {
2323
preferences: Map<string, string>;
2424
useArduinoCli: boolean;
2525
defaultTimestampFormat: string;
26+
analyzeOnSettingChange: boolean;
2627
reloadPreferences(): void;
2728
}
2829

@@ -169,6 +170,10 @@ export class ArduinoSettings implements IArduinoSettings {
169170
return this._defaultTimestampFormat;
170171
}
171172

173+
public get analyzeOnSettingChange(): boolean {
174+
return VscodeSettings.getInstance().analyzeOnSettingChange;
175+
}
176+
172177
public reloadPreferences() {
173178
this._preferences = util.parseConfigFile(this.preferencePath);
174179
if (this.preferences.get("sketchbook.path")) {

src/arduino/vscodeSettings.ts

+12
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ const configKeys = {
2020
USE_ARDUINO_CLI: "arduino.useArduinoCli",
2121
DISABLE_INTELLISENSE_AUTO_GEN: "arduino.disableIntelliSenseAutoGen",
2222
DEFAULT_TIMESTAMP_FORMAT: "arduino.defaultTimestampFormat",
23+
ANALYZE_ON_OPEN: "arduino.analyzeOnOpen",
24+
ANALYZE_ON_SETTING_CHANGE: "arduino.analyzeOnSettingChange",
2325
};
2426

2527
export interface IVscodeSettings {
@@ -37,6 +39,8 @@ export interface IVscodeSettings {
3739
useArduinoCli: boolean;
3840
disableIntelliSenseAutoGen: boolean;
3941
defaultTimestampFormat: string;
42+
analyzeOnOpen: boolean;
43+
analyzeOnSettingChange: boolean;
4044
updateAdditionalUrls(urls: string[]): void;
4145
}
4246

@@ -124,6 +128,14 @@ export class VscodeSettings implements IVscodeSettings {
124128
return this.getConfigValue<string>(configKeys.DEFAULT_TIMESTAMP_FORMAT);
125129
}
126130

131+
public get analyzeOnOpen(): boolean {
132+
return this.getConfigValue<boolean>(configKeys.ANALYZE_ON_OPEN);
133+
}
134+
135+
public get analyzeOnSettingChange(): boolean {
136+
return this.getConfigValue<boolean>(configKeys.ANALYZE_ON_SETTING_CHANGE);
137+
}
138+
127139
public async updateAdditionalUrls(value) {
128140
await this.setConfigValue(configKeys.ADDITIONAL_URLS, value, true);
129141
}

src/arduinoActivator.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { ExampleManager } from "./arduino/exampleManager";
1010
import { ExampleProvider } from "./arduino/exampleProvider";
1111
import { LibraryManager } from "./arduino/libraryManager";
1212
import { ProgrammerManager } from "./arduino/programmerManager";
13+
import { VscodeSettings } from "./arduino/vscodeSettings";
1314
import ArduinoContext from "./arduinoContext";
1415
import { DeviceContext } from "./deviceContext";
1516

@@ -25,11 +26,22 @@ class ArduinoActivator {
2526
const arduinoSettings = new ArduinoSettings();
2627
await arduinoSettings.initialize();
2728
const arduinoApp = new ArduinoApp(arduinoSettings);
28-
await arduinoApp.initialize();
29+
30+
// Initializing the app before the device context will cause a
31+
// setting changed event that triggers analysis.
32+
const analyzeOnOpen = VscodeSettings.getInstance().analyzeOnOpen;
33+
if (analyzeOnOpen) {
34+
await arduinoApp.initialize();
35+
}
2936

3037
// TODO: After use the device.json config, should remove the dependency on the ArduinoApp object.
3138
const deviceContext = DeviceContext.getInstance();
3239
await deviceContext.loadContext();
40+
41+
if (!analyzeOnOpen) {
42+
await arduinoApp.initialize();
43+
}
44+
3345
// Show sketch status bar, and allow user to change sketch in config file
3446
deviceContext.showStatusBar();
3547
// Arduino board manager & library manager

0 commit comments

Comments
 (0)