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

Quick pick selection of sketch files #1128

Merged
merged 3 commits into from
Apr 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"onCommand:arduino.rebuildIntelliSenseConfig",
"onCommand:arduino.selectProgrammer",
"onCommand:arduino.selectSerialPort",
"onCommand:arduino.selectSketch",
"onCommand:arduino.changeBaudRate",
"onCommand:arduino.openSerialMonitor",
"onCommand:arduino.sendMessageToSerialPort",
Expand Down Expand Up @@ -115,6 +116,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 @@ -112,7 +112,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 @@ -156,24 +156,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.map((p) => p.replace("\\", "/")).join(",")}}`;

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, matchOnDescription: true });

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