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

Commit 453fdb3

Browse files
committed
Set default build directory and better sketch name
1 parent c957432 commit 453fdb3

File tree

1 file changed

+5
-18
lines changed

1 file changed

+5
-18
lines changed

src/deviceContext.ts

+5-18
Original file line numberDiff line numberDiff line change
@@ -312,29 +312,14 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable {
312312
.then(async (fileUris) => {
313313
if (fileUris.length === 0) {
314314
let newSketchFileName = await vscode.window.showInputBox({
315-
value: "my-sketch.ino",
315+
value: "sketch.ino",
316316
prompt: "No sketch (*.ino) found in workspace, please provide a name",
317317
placeHolder: "Sketch file name (*.ino or *.cpp)",
318318
validateInput: (value) => {
319-
/* TODO (EW, 2020-02-18):
320-
* is 'c' actually allowed? Also found on within other files.
321-
* And the regular expression doesn't need the internal groups.
322-
* The outer group can be an anonymous group.
323-
* And \w doesn't match dashes - so any sketch containing dashes
324-
* will not be found.
325-
* The correct expression therefore would be something like this:
326-
*
327-
* /^[\w\-]+\.(?:ino|cpp)$/
328-
*
329-
* I'd recommend to define such regular expressions (including)
330-
* line splitting etc.) at the global constants file.
331-
* This is true for any hard coded paths (like the snippets below)
332-
* as well.
333-
*/
334-
if (value && /^\w+\.((ino)|(cpp)|c)$/.test(value.trim())) {
319+
if (value && /^[\w-]+\.(?:ino|cpp)$/.test(value.trim())) {
335320
return null;
336321
} else {
337-
return "Invalid sketch file name. Should be *.ino/*.cpp/*.c";
322+
return "Invalid sketch file name. Should be *.ino/*.cpp";
338323
}
339324
},
340325
});
@@ -343,6 +328,8 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable {
343328
const snippets = fs.readFileSync(path.join(this.extensionPath, "snippets", "sample.ino"));
344329
fs.writeFileSync(path.join(ArduinoWorkspace.rootPath, newSketchFileName), snippets);
345330
this.sketch = newSketchFileName;
331+
// Set a build directory in new configurations to avoid warnings about slow builds.
332+
this.output = "build";
346333
// Open the new sketch file.
347334
const textDocument = await vscode.workspace.openTextDocument(path.join(ArduinoWorkspace.rootPath, newSketchFileName));
348335
vscode.window.showTextDocument(textDocument, vscode.ViewColumn.One, true);

0 commit comments

Comments
 (0)