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

Commit b8745ac

Browse files
committed
Add getChildArduinoSources() method
It allows to get list of all arduino (*.ino, *.cpp, *.c) sources from workspace path.
1 parent 19c276f commit b8745ac

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/extension.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,32 @@ export async function activate(context: vscode.ExtensionContext) {
152152
return { board: arduinoContextModule.default.boardManager.currentBoard.name };
153153
});
154154

155+
const getChildArduinoSources = (directory: string) => {
156+
if (!directory) {
157+
directory = vscode.workspace.rootPath;
158+
}
159+
160+
let sourcesArray = [];
161+
const list = fs.readdirSync(directory);
162+
163+
list.forEach(function(file) {
164+
if(file.startsWith('.')){
165+
return;
166+
}
167+
file = `${directory}\\${file}`;
168+
const stat = fs.statSync(file);
169+
if (stat && stat.isDirectory()) {
170+
sourcesArray = sourcesArray.concat(getChildArduinoSources(file));
171+
} else {
172+
if (/\.((ino)|(cpp)|c)$/.test(file.trim())) {
173+
sourcesArray.push(file.slice(vscode.workspace.rootPath.length + 1));
174+
}
175+
}
176+
});
177+
178+
return sourcesArray;
179+
}
180+
155181
registerArduinoCommand("arduino.setSketchFile", async () => {
156182
const sketchFileName = deviceContext.sketch;
157183
const newSketchFileName = await vscode.window.showInputBox({

0 commit comments

Comments
 (0)