Skip to content

Commit 1d46af2

Browse files
committed
Add a "Flutter clean" command
Fixes #1679.
1 parent 09155eb commit 1d46af2

2 files changed

Lines changed: 29 additions & 7 deletions

File tree

‎package.json‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,11 @@
225225
"dark": "./media/commands/pull-inverse.svg"
226226
}
227227
},
228+
{
229+
"command": "flutter.clean",
230+
"title": "Clean Project",
231+
"category": "Flutter"
232+
},
228233
{
229234
"command": "flutter.doctor",
230235
"title": "Run Flutter Doctor",
@@ -482,6 +487,10 @@
482487
"command": "flutter.packages.upgrade",
483488
"when": "dart-code:anyFlutterProjectLoaded"
484489
},
490+
{
491+
"command": "flutter.clean",
492+
"when": "dart-code:flutterMobileProjectLoaded"
493+
},
485494
{
486495
"command": "flutter.doctor"
487496
},

‎src/commands/sdk.ts‎

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,16 @@ export class SdkCommands {
105105
DartHoverProvider.clearPackageMapCaches();
106106
}
107107
}));
108+
context.subscriptions.push(vs.commands.registerCommand("flutter.clean", async (selection): Promise<number | undefined> => {
109+
if (!selection) {
110+
const path = await this.getFolderToRunCommandIn(`Select the folder to run "flutter clean" in`, selection, true);
111+
if (!path)
112+
return;
113+
selection = vs.Uri.file(path);
114+
}
115+
116+
return this.runFlutter(["clean"], selection);
117+
}));
108118
context.subscriptions.push(vs.commands.registerCommand("_flutter.screenshot.touchBar", (args: any) => vs.commands.executeCommand("flutter.screenshot", args)));
109119
context.subscriptions.push(vs.commands.registerCommand("flutter.screenshot", async () => {
110120
let shouldNotify = false;
@@ -304,7 +314,7 @@ export class SdkCommands {
304314
return handler(folderToRunCommandIn, args, shortPath);
305315
}
306316

307-
private async getFolderToRunCommandIn(placeHolder: string, selection?: vs.Uri): Promise<string | undefined> {
317+
private async getFolderToRunCommandIn(placeHolder: string, selection?: vs.Uri, flutterOnly = false): Promise<string | undefined> {
308318
// Attempt to find a project based on the supplied folder of active file.
309319
let file = selection && fsPath(selection);
310320
file = file || (vs.window.activeTextEditor && fsPath(vs.window.activeTextEditor.document.uri));
@@ -316,17 +326,20 @@ export class SdkCommands {
316326
// Otherwise look for what projects we have.
317327
const rootFolders = util.getDartWorkspaceFolders().map((wf) => fsPath(wf.uri));
318328
const nestedProjectFolders = flatMap(rootFolders, getChildFolders);
319-
const selectableFolders = rootFolders.concat(nestedProjectFolders).filter(hasPubspec);
329+
const selectableFolders = rootFolders.concat(nestedProjectFolders)
330+
.filter(hasPubspec)
331+
.filter(flutterOnly ? util.isFlutterProjectFolder : () => true);
332+
333+
if (!selectableFolders || !selectableFolders.length) {
334+
const projectTypes = flutterOnly ? "Flutter" : "Dart/Flutter";
335+
vs.window.showWarningMessage(`No ${projectTypes} projects were found.`);
336+
return undefined;
337+
}
320338

321339
return this.showFolderPicker(selectableFolders, placeHolder); // TODO: What if the user didn't pick anything?
322340
}
323341

324342
private async showFolderPicker(folders: string[], placeHolder: string): Promise<string | undefined> {
325-
if (!folders || !folders.length) {
326-
vs.window.showWarningMessage("No Dart/Flutter projects were found.");
327-
return undefined;
328-
}
329-
330343
// No point asking the user if there's only one.
331344
if (folders.length === 1) {
332345
return folders[0];

0 commit comments

Comments
 (0)