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

Commit cb7d040

Browse files
maddogjtadiazulay
andauthored
Quick pick selection of sketch files (#1128)
* 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 * Fix incorrect slash on library exclude pattern Co-authored-by: Adi Azulay <[email protected]>
1 parent 5bf5472 commit cb7d040

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
@@ -42,6 +42,7 @@
4242
"onCommand:arduino.rebuildIntelliSenseConfig",
4343
"onCommand:arduino.selectProgrammer",
4444
"onCommand:arduino.selectSerialPort",
45+
"onCommand:arduino.selectSketch",
4546
"onCommand:arduino.changeBaudRate",
4647
"onCommand:arduino.openSerialMonitor",
4748
"onCommand:arduino.sendMessageToSerialPort",
@@ -115,6 +116,10 @@
115116
"command": "arduino.selectProgrammer",
116117
"title": "Arduino: Select Programmer"
117118
},
119+
{
120+
"command": "arduino.selectSketch",
121+
"title": "Arduino: Select Sketch"
122+
},
118123
{
119124
"command": "arduino.selectSerialPort",
120125
"title": "Arduino: Select Serial Port"

src/deviceContext.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable {
112112
this._watcher.onDidDelete(() => this.loadContext());
113113
this._vscodeWatcher.onDidDelete(() => this.loadContext());
114114
this._sketchStatusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, constants.statusBarPriority.SKETCH);
115-
this._sketchStatusBar.command = "arduino.setSketchFile";
115+
this._sketchStatusBar.command = "arduino.selectSketch";
116116
this._sketchStatusBar.tooltip = "Sketch File";
117117
}
118118
}

src/extension.ts

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

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

172188
if (!newSketchFileName) {
173189
return;
174190
}
175191

176-
deviceContext.sketch = newSketchFileName;
192+
deviceContext.sketch = newSketchFileName.label;
177193
deviceContext.showStatusBar();
178194
});
179195

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
"arduino.cliUpload",
5959
"arduino.cliUploadUsingProgrammer",
6060
];

0 commit comments

Comments
 (0)