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

Add analyzeOnOpen and analyzeOnSettingChange #1480

Merged
merged 2 commits into from
Mar 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ This extension provides several commands in the Command Palette (<kbd>F1</kbd> o
| `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 |
| `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). |
| `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. |
| `arduino.analyzeOnOpen` | When true, automatically run analysis when the project is opened. Only works when `arduino.analyzeOnSettingChange` is true. |
| `arduino.analyzeOnSettingChange` | When true, automatically run analysis when board, configuration, or sketch settings are changed. |

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.

Expand Down
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,16 @@
"type": "string",
"default": "",
"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)."
},
"arduino.analyzeOnOpen": {
"type": "boolean",
"default": true,
"markdownDescription": "When true, automatically run analysis when the project is opened. Only works when `arduino.analyzeOnSettingChange` is true."
},
"arduino.analyzeOnSettingChange": {
"type": "boolean",
"default": true,
"markdownDescription": "When true, automatically run analysis when board, configuration, or sketch settings are changed."
}
}
},
Expand Down
22 changes: 12 additions & 10 deletions src/arduino/arduino.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,18 @@ export class ArduinoApp {
}
}

// set up event handling for IntelliSense analysis
const requestAnalysis = async () => {
if (isCompilerParserEnabled()) {
await this._analysisManager.requestAnalysis();
}
};
const dc = DeviceContext.getInstance();
dc.onChangeBoard(requestAnalysis);
dc.onChangeConfiguration(requestAnalysis);
dc.onChangeSketch(requestAnalysis);
if (this._settings.analyzeOnSettingChange) {
// set up event handling for IntelliSense analysis
const requestAnalysis = async () => {
if (isCompilerParserEnabled()) {
await this._analysisManager.requestAnalysis();
}
};
const dc = DeviceContext.getInstance();
dc.onChangeBoard(requestAnalysis);
dc.onChangeConfiguration(requestAnalysis);
dc.onChangeSketch(requestAnalysis);
}
}

/**
Expand Down
5 changes: 5 additions & 0 deletions src/arduino/arduinoSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface IArduinoSettings {
preferences: Map<string, string>;
useArduinoCli: boolean;
defaultTimestampFormat: string;
analyzeOnSettingChange: boolean;
reloadPreferences(): void;
}

Expand Down Expand Up @@ -169,6 +170,10 @@ export class ArduinoSettings implements IArduinoSettings {
return this._defaultTimestampFormat;
}

public get analyzeOnSettingChange(): boolean {
return VscodeSettings.getInstance().analyzeOnSettingChange;
}

public reloadPreferences() {
this._preferences = util.parseConfigFile(this.preferencePath);
if (this.preferences.get("sketchbook.path")) {
Expand Down
12 changes: 12 additions & 0 deletions src/arduino/vscodeSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const configKeys = {
USE_ARDUINO_CLI: "arduino.useArduinoCli",
DISABLE_INTELLISENSE_AUTO_GEN: "arduino.disableIntelliSenseAutoGen",
DEFAULT_TIMESTAMP_FORMAT: "arduino.defaultTimestampFormat",
ANALYZE_ON_OPEN: "arduino.analyzeOnOpen",
ANALYZE_ON_SETTING_CHANGE: "arduino.analyzeOnSettingChange",
};

export interface IVscodeSettings {
Expand All @@ -37,6 +39,8 @@ export interface IVscodeSettings {
useArduinoCli: boolean;
disableIntelliSenseAutoGen: boolean;
defaultTimestampFormat: string;
analyzeOnOpen: boolean;
analyzeOnSettingChange: boolean;
updateAdditionalUrls(urls: string[]): void;
}

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

public get analyzeOnOpen(): boolean {
return this.getConfigValue<boolean>(configKeys.ANALYZE_ON_OPEN);
}

public get analyzeOnSettingChange(): boolean {
return this.getConfigValue<boolean>(configKeys.ANALYZE_ON_SETTING_CHANGE);
}

public async updateAdditionalUrls(value) {
await this.setConfigValue(configKeys.ADDITIONAL_URLS, value, true);
}
Expand Down
14 changes: 13 additions & 1 deletion src/arduinoActivator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ExampleManager } from "./arduino/exampleManager";
import { ExampleProvider } from "./arduino/exampleProvider";
import { LibraryManager } from "./arduino/libraryManager";
import { ProgrammerManager } from "./arduino/programmerManager";
import { VscodeSettings } from "./arduino/vscodeSettings";
import ArduinoContext from "./arduinoContext";
import { DeviceContext } from "./deviceContext";

Expand All @@ -25,11 +26,22 @@ class ArduinoActivator {
const arduinoSettings = new ArduinoSettings();
await arduinoSettings.initialize();
const arduinoApp = new ArduinoApp(arduinoSettings);
await arduinoApp.initialize();

// Initializing the app before the device context will cause a
// setting changed event that triggers analysis.
const analyzeOnOpen = VscodeSettings.getInstance().analyzeOnOpen;
if (analyzeOnOpen) {
await arduinoApp.initialize();
}

// TODO: After use the device.json config, should remove the dependency on the ArduinoApp object.
const deviceContext = DeviceContext.getInstance();
await deviceContext.loadContext();

if (!analyzeOnOpen) {
await arduinoApp.initialize();
}

// Show sketch status bar, and allow user to change sketch in config file
deviceContext.showStatusBar();
// Arduino board manager & library manager
Expand Down