From 298ddaaf7d1ff237a45c15b7517bfff9ba3ac7c5 Mon Sep 17 00:00:00 2001 From: "Mr.Santiaga" Date: Sat, 8 Feb 2020 12:34:10 +0300 Subject: [PATCH 1/4] Introduce new 'arduino.useActiveSketch' property into package.json This property will provide possibility to verify or compile sketch opened in active tab. --- package.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/package.json b/package.json index 8c3b9587..96d17577 100644 --- a/package.json +++ b/package.json @@ -440,6 +440,11 @@ "type": "object", "title": "Arduino configuration", "properties": { + "arduino.useActiveSketch": { + "type": "boolean", + "default": false, + "description": "Allows to verify or compile sketch opened in active tab." + }, "arduino.path": { "type": "string", "default": "", From 0cc685360bc98f69893fd19bc104b29b84946fb7 Mon Sep 17 00:00:00 2001 From: "Mr.Santiaga" Date: Sat, 8 Feb 2020 12:34:19 +0300 Subject: [PATCH 2/4] Use introduced property in IVscodeSettings and VscodeSettings --- src/arduino/vscodeSettings.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/arduino/vscodeSettings.ts b/src/arduino/vscodeSettings.ts index f66e268b..c0fc2f98 100644 --- a/src/arduino/vscodeSettings.ts +++ b/src/arduino/vscodeSettings.ts @@ -4,6 +4,7 @@ import * as vscode from "vscode"; const configKeys = { + USE_ACTIVE_SKETCH: "arduino.useActiveSketch", ARDUINO_PATH: "arduino.path", ARDUINO_COMMAND_PATH: "arduino.commandPath", ADDITIONAL_URLS: "arduino.additionalUrls", @@ -18,6 +19,7 @@ const configKeys = { }; export interface IVscodeSettings { + useActiveSketch: boolean; arduinoPath: string; commandPath: string; additionalUrls: string | string[]; @@ -43,6 +45,10 @@ export class VscodeSettings implements IVscodeSettings { private constructor() { } + public get useActiveSketch(): boolean { + return this.getConfigValue(configKeys.USE_ACTIVE_SKETCH); + } + public get arduinoPath(): string { return this.getConfigValue(configKeys.ARDUINO_PATH); } From 87dfacc01a16dd60db3897f6396a650f5b9d4254 Mon Sep 17 00:00:00 2001 From: "Mr.Santiaga" Date: Sat, 8 Feb 2020 13:48:59 +0300 Subject: [PATCH 3/4] Add trySetOpenedFileAsSketch() method It allows to set "sketch" value to arduino.json when useActiveSketch value is true. --- src/deviceContext.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/deviceContext.ts b/src/deviceContext.ts index 2e7f18e3..a64e2772 100644 --- a/src/deviceContext.ts +++ b/src/deviceContext.ts @@ -8,6 +8,7 @@ import * as constants from "./common/constants"; import * as util from "./common/util"; import * as Logger from "./logger/logger"; +import { VscodeSettings } from "./arduino/vscodeSettings"; import { ARDUINO_CONFIG_FILE } from "./common/constants"; import { ArduinoWorkspace } from "./common/workspace"; @@ -96,6 +97,8 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable { private _programmer: string; + private _vscodeSettings = VscodeSettings.getInstance(); + /** * @constructor */ @@ -361,4 +364,17 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable { } }); } + + public trySetOpenedFileAsSketch() { + if (this._vscodeSettings.useActiveSketch) { + const openedFile = vscode.window.activeTextEditor.document.fileName + .slice(vscode.workspace.rootPath.length + 1); + if (/\.((ino)|(cpp)|c)$/.test(openedFile.trim())) { + this._sketch = openedFile; + this.saveContext(); + return true; + } + } + return false; + }; } From 7c91379e8a0a999ec4df939a0b09273509e27d93 Mon Sep 17 00:00:00 2001 From: "Mr.Santiaga" Date: Sat, 8 Feb 2020 13:50:27 +0300 Subject: [PATCH 4/4] Use trySetOpenedFileAsSketch() method Here is 2 changes: - Subscrube to event onDidChangeActiveTextEditor to set "sketch" value into arduino.json when useActiveSketch option is true - Don't show sketch name in Status Bar when "sketch" value is atomatically setted in arduino.json --- src/deviceContext.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/deviceContext.ts b/src/deviceContext.ts index a64e2772..9ff4616e 100644 --- a/src/deviceContext.ts +++ b/src/deviceContext.ts @@ -115,6 +115,9 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable { this._sketchStatusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, constants.statusBarPriority.SKETCH); this._sketchStatusBar.command = "arduino.setSketchFile"; this._sketchStatusBar.tooltip = "Sketch File"; + vscode.window.onDidChangeActiveTextEditor(() => { + this.trySetOpenedFileAsSketch(); + }) } } @@ -194,6 +197,10 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable { } public showStatusBar() { + if (this.trySetOpenedFileAsSketch()) { + return; + } + if (!this._sketch) { return false; }