Skip to content

Commit dc31a0b

Browse files
authored
feat(vscode): show progress indicator on new commands (#784)
1 parent fb5a4d6 commit dc31a0b

File tree

4 files changed

+71
-4
lines changed

4 files changed

+71
-4
lines changed

extensions/vscode/src/commands/new-middleware.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const cp = require("child_process");
22

3-
import { Uri, window, OpenDialogOptions } from "vscode";
3+
import { Uri, window, OpenDialogOptions, ProgressOptions } from "vscode";
44
import { nearestDartFrogProject, normalizeRoutePath } from "../utils";
55

66
/**
@@ -45,7 +45,13 @@ export const newMiddleware = async (uri: Uri | undefined): Promise<void> => {
4545

4646
const routePath = normalizeRoutePath(selectedUri, dartFrogProjectPath);
4747

48-
executeDartFrogNewMiddlewareCommand(routePath, dartFrogProjectPath);
48+
const options: ProgressOptions = {
49+
location: 15,
50+
title: `Creating '${routePath}' middleware...`,
51+
};
52+
window.withProgress(options, async function () {
53+
executeDartFrogNewMiddlewareCommand(routePath, dartFrogProjectPath);
54+
});
4955
};
5056

5157
/**

extensions/vscode/src/commands/new-route.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
const cp = require("child_process");
22

3-
import { InputBoxOptions, Uri, window, OpenDialogOptions } from "vscode";
3+
import {
4+
InputBoxOptions,
5+
Uri,
6+
window,
7+
OpenDialogOptions,
8+
ProgressOptions,
9+
} from "vscode";
410
import { nearestDartFrogProject, normalizeRoutePath } from "../utils";
511

612
/**
@@ -55,7 +61,13 @@ export const newRoute = async (uri: Uri | undefined): Promise<void> => {
5561
return;
5662
}
5763

58-
executeDartFrogNewRouteCommand(routePath, dartFrogProjectPath);
64+
const options: ProgressOptions = {
65+
location: 15,
66+
title: `Creating '${routePath}' route...`,
67+
};
68+
window.withProgress(options, async function () {
69+
executeDartFrogNewRouteCommand(routePath, dartFrogProjectPath);
70+
});
5971
};
6072

6173
/**

extensions/vscode/src/test/suite/commands/new-middleware.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ suite("new-middleware command", () => {
1818
window: {
1919
showErrorMessage: sinon.stub(),
2020
showOpenDialog: sinon.stub(),
21+
withProgress: sinon.stub(),
2122
},
2223
};
2324
childProcessStub = {
@@ -120,6 +121,22 @@ suite("new-middleware command", () => {
120121
}
121122
);
122123

124+
test("shows progess on middleware creation", async () => {
125+
const routePath = "food/pizza";
126+
const selectedUri = {
127+
fsPath: `${validUri.fsPath}${routePath}`,
128+
};
129+
utilsStub.nearestDartFrogProject.returns(selectedUri);
130+
utilsStub.normalizeRoutePath.returns(routePath);
131+
132+
await command.newMiddleware(validUri);
133+
134+
sinon.assert.calledOnceWithMatch(vscodeStub.window.withProgress, {
135+
location: 15,
136+
title: `Creating '${routePath}' middleware...`,
137+
});
138+
});
139+
123140
suite("runs `dart_frog new middleware` command with route", () => {
124141
test("successfully with non-index route name", async () => {
125142
const selectedUri = {
@@ -128,6 +145,9 @@ suite("new-middleware command", () => {
128145
utilsStub.normalizeRoutePath.returns("food");
129146

130147
await command.newMiddleware(validUri);
148+
const progressFunction =
149+
vscodeStub.window.withProgress.getCall(0).args[1];
150+
await progressFunction();
131151

132152
sinon.assert.calledWith(
133153
childProcessStub.exec,
@@ -143,6 +163,9 @@ suite("new-middleware command", () => {
143163
utilsStub.normalizeRoutePath.returns(`food/pizza`);
144164

145165
await command.newMiddleware(selectedUri);
166+
const progressFunction =
167+
vscodeStub.window.withProgress.getCall(0).args[1];
168+
await progressFunction();
146169

147170
sinon.assert.calledWith(
148171
childProcessStub.exec,
@@ -158,6 +181,9 @@ suite("new-middleware command", () => {
158181
utilsStub.normalizeRoutePath.returns("/");
159182

160183
await command.newMiddleware(validUri);
184+
const progressFunction =
185+
vscodeStub.window.withProgress.getCall(0).args[1];
186+
await progressFunction();
161187

162188
sinon.assert.calledWith(
163189
childProcessStub.exec,
@@ -173,6 +199,9 @@ suite("new-middleware command", () => {
173199
utilsStub.normalizeRoutePath.returns("food/italian");
174200

175201
await command.newMiddleware(selectedUri);
202+
const progressFunction =
203+
vscodeStub.window.withProgress.getCall(0).args[1];
204+
await progressFunction();
176205

177206
sinon.assert.calledWith(
178207
childProcessStub.exec,
@@ -189,6 +218,8 @@ suite("new-middleware command", () => {
189218
utilsStub.normalizeRoutePath.returns("/");
190219

191220
await command.newMiddleware(validUri);
221+
const progressFunction = vscodeStub.window.withProgress.getCall(0).args[1];
222+
await progressFunction();
192223

193224
sinon.assert.calledWith(vscodeStub.window.showErrorMessage, error.message);
194225
});

extensions/vscode/src/test/suite/commands/new-route.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ suite("new-route command", () => {
2020
showErrorMessage: sinon.stub(),
2121
showInputBox: sinon.stub(),
2222
showOpenDialog: sinon.stub(),
23+
withProgress: sinon.stub(),
2324
},
2425
};
2526
childProcessStub = {
@@ -201,12 +202,27 @@ suite("new-route command", () => {
201202
}
202203
);
203204

205+
test("shows progess on route creation", async () => {
206+
utilsStub.normalizeRoutePath.returns("/");
207+
const routePath = "pizza";
208+
vscodeStub.window.showInputBox.returns(routePath);
209+
210+
await command.newRoute(validUri);
211+
212+
sinon.assert.calledOnceWithMatch(vscodeStub.window.withProgress, {
213+
location: 15,
214+
title: `Creating '${routePath}' route...`,
215+
});
216+
});
217+
204218
test("runs `dart_frog new route` command with prompted route successfully", async () => {
205219
utilsStub.normalizeRoutePath.returns("/");
206220
const routePath = "pizza";
207221
vscodeStub.window.showInputBox.returns(routePath);
208222

209223
await command.newRoute(validUri);
224+
const progressFunction = vscodeStub.window.withProgress.getCall(0).args[1];
225+
await progressFunction();
210226

211227
sinon.assert.calledWith(
212228
childProcessStub.exec,
@@ -223,6 +239,8 @@ suite("new-route command", () => {
223239
childProcessStub.exec.yields(error);
224240

225241
await command.newRoute(validUri);
242+
const progressFunction = vscodeStub.window.withProgress.getCall(0).args[1];
243+
await progressFunction();
226244

227245
sinon.assert.calledWith(vscodeStub.window.showErrorMessage, error.message);
228246
});

0 commit comments

Comments
 (0)