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

Commit 5a8d106

Browse files
committed
Quick pick selection of sketch files
- 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
1 parent d6459d0 commit 5a8d106

File tree

4 files changed

+35
-14
lines changed

4 files changed

+35
-14
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"onCommand:arduino.uploadUsingProgrammer",
4040
"onCommand:arduino.selectProgrammer",
4141
"onCommand:arduino.selectSerialPort",
42+
"onCommand:arduino.selectSketch",
4243
"onCommand:arduino.changeBaudRate",
4344
"onCommand:arduino.addLibPath",
4445
"onCommand:arduino.openSerialMonitor",
@@ -109,6 +110,10 @@
109110
"command": "arduino.selectProgrammer",
110111
"title": "Arduino: Select Programmer"
111112
},
113+
{
114+
"command": "arduino.selectSketch",
115+
"title": "Arduino: Select Sketch"
116+
},
112117
{
113118
"command": "arduino.selectSerialPort",
114119
"title": "Arduino: Select Serial Port"

src/deviceContext.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable {
110110
this._watcher.onDidDelete(() => this.loadContext());
111111
this._vscodeWatcher.onDidDelete(() => this.loadContext());
112112
this._sketchStatusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, constants.statusBarPriority.SKETCH);
113-
this._sketchStatusBar.command = "arduino.setSketchFile";
113+
this._sketchStatusBar.command = "arduino.selectSketch";
114114
this._sketchStatusBar.tooltip = "Sketch File";
115115
}
116116
}

src/extension.ts

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -172,24 +172,40 @@ export async function activate(context: vscode.ExtensionContext) {
172172
return { board: arduinoContextModule.default.boardManager.currentBoard.name };
173173
});
174174

175-
registerArduinoCommand("arduino.setSketchFile", async () => {
175+
registerArduinoCommand("arduino.selectSketch", async () => {
176176
const sketchFileName = deviceContext.sketch;
177-
const newSketchFileName = await vscode.window.showInputBox({
178-
placeHolder: sketchFileName,
179-
validateInput: (value) => {
180-
if (value && /\.((ino)|(cpp)|c)$/.test(value.trim())) {
181-
return null;
182-
} else {
183-
return "Invalid sketch file name. Should be *.ino/*.cpp/*.c";
184-
}
185-
},
186-
});
177+
178+
// Include any ino, cpp, or c files under the workspace folder
179+
const includePattern = "**/*.{ino,cpp,c}";
180+
181+
// The sketchbook folder may contain hardware & library folders, any sketches under these paths
182+
// should be excluded
183+
const sketchbookPath = arduinoContextModule.default.arduinoApp.settings.sketchbookPath;
184+
const excludePatterns = [
185+
path.relative(ArduinoWorkspace.rootPath, sketchbookPath + "/hardware/**"),
186+
path.relative(ArduinoWorkspace.rootPath, sketchbookPath + "/libraries/**")];
187+
188+
// If an output path is specified, it should be excluded as well
189+
if (deviceContext.output) {
190+
const outputPath = path.relative(ArduinoWorkspace.rootPath,
191+
path.resolve(ArduinoWorkspace.rootPath, deviceContext.output));
192+
excludePatterns.push(`${outputPath}/**`);
193+
}
194+
const excludePattern = `{${excludePatterns.join(",")}}`.replace("\\", "/");
195+
196+
const fileUris = await vscode.workspace.findFiles(includePattern, excludePattern);
197+
const newSketchFileName = await vscode.window.showQuickPick(fileUris.map((fileUri) =>
198+
({
199+
label: path.relative(ArduinoWorkspace.rootPath, fileUri.fsPath),
200+
description: fileUri.fsPath,
201+
})),
202+
{ placeHolder: sketchFileName });
187203

188204
if (!newSketchFileName) {
189205
return;
190206
}
191207

192-
deviceContext.sketch = newSketchFileName;
208+
deviceContext.sketch = newSketchFileName.label;
193209
deviceContext.showStatusBar();
194210
});
195211

test/extension.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ suite("Arduino: Extension Tests", () => {
5454
"arduino.showExampleExplorer",
5555
"arduino.loadPackages",
5656
"arduino.installBoard",
57-
"arduino.setSketchFile",
57+
"arduino.selectSketch",
5858
"arduino.cliUpload",
5959
"arduino.cliUploadUsingProgrammer",
6060
];

0 commit comments

Comments
 (0)