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

Commit

Permalink
Quick pick selection of sketch files
Browse files Browse the repository at this point in the history
- Replace arduino.setSketchFile command with new arduino.selectSketch command which presents the user with a quick select containing all of the sketch files in the workspace.
- Add "Arduino: Select Sketch" to the command palette
- When picking sketches, filter out hardware, library, and build folders that may be under the workspace
  • Loading branch information
maddogjt committed Dec 12, 2020
1 parent d6459d0 commit 5a8d106
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 14 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"onCommand:arduino.uploadUsingProgrammer",
"onCommand:arduino.selectProgrammer",
"onCommand:arduino.selectSerialPort",
"onCommand:arduino.selectSketch",
"onCommand:arduino.changeBaudRate",
"onCommand:arduino.addLibPath",
"onCommand:arduino.openSerialMonitor",
Expand Down Expand Up @@ -109,6 +110,10 @@
"command": "arduino.selectProgrammer",
"title": "Arduino: Select Programmer"
},
{
"command": "arduino.selectSketch",
"title": "Arduino: Select Sketch"
},
{
"command": "arduino.selectSerialPort",
"title": "Arduino: Select Serial Port"
Expand Down
2 changes: 1 addition & 1 deletion src/deviceContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable {
this._watcher.onDidDelete(() => this.loadContext());
this._vscodeWatcher.onDidDelete(() => this.loadContext());
this._sketchStatusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, constants.statusBarPriority.SKETCH);
this._sketchStatusBar.command = "arduino.setSketchFile";
this._sketchStatusBar.command = "arduino.selectSketch";
this._sketchStatusBar.tooltip = "Sketch File";
}
}
Expand Down
40 changes: 28 additions & 12 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,24 +172,40 @@ export async function activate(context: vscode.ExtensionContext) {
return { board: arduinoContextModule.default.boardManager.currentBoard.name };
});

registerArduinoCommand("arduino.setSketchFile", async () => {
registerArduinoCommand("arduino.selectSketch", async () => {
const sketchFileName = deviceContext.sketch;
const newSketchFileName = await vscode.window.showInputBox({
placeHolder: sketchFileName,
validateInput: (value) => {
if (value && /\.((ino)|(cpp)|c)$/.test(value.trim())) {
return null;
} else {
return "Invalid sketch file name. Should be *.ino/*.cpp/*.c";
}
},
});

// Include any ino, cpp, or c files under the workspace folder
const includePattern = "**/*.{ino,cpp,c}";

// The sketchbook folder may contain hardware & library folders, any sketches under these paths
// should be excluded
const sketchbookPath = arduinoContextModule.default.arduinoApp.settings.sketchbookPath;
const excludePatterns = [
path.relative(ArduinoWorkspace.rootPath, sketchbookPath + "/hardware/**"),
path.relative(ArduinoWorkspace.rootPath, sketchbookPath + "/libraries/**")];

// If an output path is specified, it should be excluded as well
if (deviceContext.output) {
const outputPath = path.relative(ArduinoWorkspace.rootPath,
path.resolve(ArduinoWorkspace.rootPath, deviceContext.output));
excludePatterns.push(`${outputPath}/**`);
}
const excludePattern = `{${excludePatterns.join(",")}}`.replace("\\", "/");

const fileUris = await vscode.workspace.findFiles(includePattern, excludePattern);
const newSketchFileName = await vscode.window.showQuickPick(fileUris.map((fileUri) =>
({
label: path.relative(ArduinoWorkspace.rootPath, fileUri.fsPath),
description: fileUri.fsPath,
})),
{ placeHolder: sketchFileName });

if (!newSketchFileName) {
return;
}

deviceContext.sketch = newSketchFileName;
deviceContext.sketch = newSketchFileName.label;
deviceContext.showStatusBar();
});

Expand Down
2 changes: 1 addition & 1 deletion test/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ suite("Arduino: Extension Tests", () => {
"arduino.showExampleExplorer",
"arduino.loadPackages",
"arduino.installBoard",
"arduino.setSketchFile",
"arduino.selectSketch",
"arduino.cliUpload",
"arduino.cliUploadUsingProgrammer",
];
Expand Down

0 comments on commit 5a8d106

Please sign in to comment.