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

Commit 87dfacc

Browse files
committed
Add trySetOpenedFileAsSketch() method
It allows to set "sketch" value to arduino.json when useActiveSketch value is true.
1 parent 0cc6853 commit 87dfacc

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/deviceContext.ts

+16
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import * as constants from "./common/constants";
88
import * as util from "./common/util";
99
import * as Logger from "./logger/logger";
1010

11+
import { VscodeSettings } from "./arduino/vscodeSettings";
1112
import { ARDUINO_CONFIG_FILE } from "./common/constants";
1213
import { ArduinoWorkspace } from "./common/workspace";
1314

@@ -96,6 +97,8 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable {
9697

9798
private _programmer: string;
9899

100+
private _vscodeSettings = VscodeSettings.getInstance();
101+
99102
/**
100103
* @constructor
101104
*/
@@ -361,4 +364,17 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable {
361364
}
362365
});
363366
}
367+
368+
public trySetOpenedFileAsSketch() {
369+
if (this._vscodeSettings.useActiveSketch) {
370+
const openedFile = vscode.window.activeTextEditor.document.fileName
371+
.slice(vscode.workspace.rootPath.length + 1);
372+
if (/\.((ino)|(cpp)|c)$/.test(openedFile.trim())) {
373+
this._sketch = openedFile;
374+
this.saveContext();
375+
return true;
376+
}
377+
}
378+
return false;
379+
};
364380
}

0 commit comments

Comments
 (0)