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

Commit 5bf4291

Browse files
committed
Add trySetOpenedFileAsSketch() method
It allows to set "sketch" value to arduino.json when useActiveSketch value is true.
1 parent e599510 commit 5bf4291

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/deviceContext.ts

+17
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import * as Logger from "./logger/logger";
1010

1111
import { ARDUINO_CONFIG_FILE } from "./common/constants";
1212
import { ArduinoWorkspace } from "./common/workspace";
13+
import { VscodeSettings } from "./arduino/vscodeSettings";
1314

1415
/**
1516
* Interface that represents the arduino context information.
@@ -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,18 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable {
361364
}
362365
});
363366
}
367+
368+
public trySetOpenedFileAsSketch(){
369+
if(this._vscodeSettings.useActiveSketch)
370+
{
371+
let openedFile = vscode.window.activeTextEditor.document.fileName
372+
.slice(vscode.workspace.rootPath.length + 1);
373+
if(/\.((ino)|(cpp)|c)$/.test(openedFile.trim())){
374+
this._sketch = openedFile;
375+
this.saveContext();
376+
return true;
377+
}
378+
}
379+
return false;
380+
};
364381
}

0 commit comments

Comments
 (0)