@@ -156,24 +156,40 @@ export async function activate(context: vscode.ExtensionContext) {
156
156
return { board : arduinoContextModule . default . boardManager . currentBoard . name } ;
157
157
} ) ;
158
158
159
- registerArduinoCommand ( "arduino.setSketchFile " , async ( ) => {
159
+ registerArduinoCommand ( "arduino.selectSketch " , async ( ) => {
160
160
const sketchFileName = deviceContext . sketch ;
161
- const newSketchFileName = await vscode . window . showInputBox ( {
162
- placeHolder : sketchFileName ,
163
- validateInput : ( value ) => {
164
- if ( value && / \. ( ( i n o ) | ( c p p ) | 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 . join ( "," ) } }` . replace ( "\\" , "/" ) ;
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 } ) ;
171
187
172
188
if ( ! newSketchFileName ) {
173
189
return ;
174
190
}
175
191
176
- deviceContext . sketch = newSketchFileName ;
192
+ deviceContext . sketch = newSketchFileName . label ;
177
193
deviceContext . showStatusBar ( ) ;
178
194
} ) ;
179
195
0 commit comments