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

Commit edb6752

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 a0add3e commit edb6752

File tree

4 files changed

+35
-14
lines changed

4 files changed

+35
-14
lines changed

package.json

+5
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",
@@ -101,6 +102,10 @@
101102
"command": "arduino.selectProgrammer",
102103
"title": "Arduino: Select Programmer"
103104
},
105+
{
106+
"command": "arduino.selectSketch",
107+
"title": "Arduino: Select Sketch"
108+
},
104109
{
105110
"command": "arduino.selectSerialPort",
106111
"title": "Arduino: Select Serial Port"

src/deviceContext.ts

+1-1
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

+28-12
Original file line numberDiff line numberDiff line change
@@ -152,24 +152,40 @@ export async function activate(context: vscode.ExtensionContext) {
152152
return { board: arduinoContextModule.default.boardManager.currentBoard.name };
153153
});
154154

155-
registerArduinoCommand("arduino.setSketchFile", async () => {
155+
registerArduinoCommand("arduino.selectSketch", async () => {
156156
const sketchFileName = deviceContext.sketch;
157-
const newSketchFileName = await vscode.window.showInputBox({
158-
placeHolder: sketchFileName,
159-
validateInput: (value) => {
160-
if (value && /\.((ino)|(cpp)|c)$/.test(value.trim())) {
161-
return null;
162-
} else {
163-
return "Invalid sketch file name. Should be *.ino/*.cpp/*.c";
164-
}
165-
},
166-
});
157+
158+
// Include any ino, cpp, or c files under the workspace folder
159+
const includePattern = "**/*.{ino,cpp,c}";
160+
161+
// The sketchbook folder may contain hardware & library folders, any sketches under these paths
162+
// should be excluded
163+
const sketchbookPath = arduinoContextModule.default.arduinoApp.settings.sketchbookPath;
164+
const excludePatterns = [
165+
path.relative(ArduinoWorkspace.rootPath, sketchbookPath + "/hardware/**"),
166+
path.relative(ArduinoWorkspace.rootPath, sketchbookPath + "/libraries/**")];
167+
168+
// If an output path is specified, it should be excluded as well
169+
if (deviceContext.output) {
170+
const outputPath = path.relative(ArduinoWorkspace.rootPath,
171+
path.resolve(ArduinoWorkspace.rootPath, deviceContext.output));
172+
excludePatterns.push(`${outputPath}/**`);
173+
}
174+
const excludePattern = `{${excludePatterns.join(",")}}`.replace("\\", "/");
175+
176+
const fileUris = await vscode.workspace.findFiles(includePattern, excludePattern);
177+
const newSketchFileName = await vscode.window.showQuickPick(fileUris.map((fileUri) =>
178+
({
179+
label: path.relative(ArduinoWorkspace.rootPath, fileUri.fsPath),
180+
description: fileUri.fsPath,
181+
})),
182+
{ placeHolder: sketchFileName });
167183

168184
if (!newSketchFileName) {
169185
return;
170186
}
171187

172-
deviceContext.sketch = newSketchFileName;
188+
deviceContext.sketch = newSketchFileName.label;
173189
deviceContext.showStatusBar();
174190
});
175191

test/extension.test.ts

+1-1
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
];
5959

6060
const foundArduinoCommands = commands.filter((value) => {

0 commit comments

Comments
 (0)