in src/deviceContext.ts [308:354]
public async resolveMainSketch() {
// TODO (EW, 2020-02-18): Here you look for *.ino files but below you allow
// *.cpp/*.c files to be set as sketch
await vscode.workspace.findFiles("**/*.ino", null)
.then(async (fileUris) => {
if (fileUris.length === 0) {
let newSketchFileName = await vscode.window.showInputBox({
value: "sketch.ino",
prompt: "No sketch (*.ino) found in workspace, please provide a name",
placeHolder: "Sketch file name (*.ino or *.cpp)",
validateInput: (value) => {
if (value && /^[\w-]+\.(?:ino|cpp)$/.test(value.trim())) {
return null;
} else {
return "Invalid sketch file name. Should be *.ino/*.cpp";
}
},
});
newSketchFileName = (newSketchFileName && newSketchFileName.trim()) || "";
if (newSketchFileName) {
const snippets = fs.readFileSync(path.join(this.extensionPath, "snippets", "sample.ino"));
fs.writeFileSync(path.join(ArduinoWorkspace.rootPath, newSketchFileName), snippets);
this.sketch = newSketchFileName;
// Set a build directory in new configurations to avoid warnings about slow builds.
this.output = "build";
// Open the new sketch file.
const textDocument = await vscode.workspace.openTextDocument(path.join(ArduinoWorkspace.rootPath, newSketchFileName));
vscode.window.showTextDocument(textDocument, vscode.ViewColumn.One, true);
} else {
this.sketch = undefined;
}
} else if (fileUris.length === 1) {
this.sketch = path.relative(ArduinoWorkspace.rootPath, fileUris[0].fsPath);
} else if (fileUris.length > 1) {
const chosen = await vscode.window.showQuickPick(<vscode.QuickPickItem[]>fileUris.map((fileUri): vscode.QuickPickItem => {
return <vscode.QuickPickItem>{
label: path.relative(ArduinoWorkspace.rootPath, fileUri.fsPath),
description: fileUri.fsPath,
};
}), { placeHolder: "Select the main sketch file" });
if (chosen && chosen.label) {
this.sketch = chosen.label;
}
}
});
return this.sketch;
}