Skip to content

Commit 4a79284

Browse files
authored
refactor(vscode): rename nearestDartFrogProject to nearestParentDartFrogProject (#1014)
1 parent fa78463 commit 4a79284

13 files changed

+99
-77
lines changed

extensions/vscode/src/code-lens/on-request-code-lens.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
TextDocument,
99
workspace,
1010
} from "vscode";
11-
import { nearestDartFrogProject } from "../utils";
11+
import { nearestParentDartFrogProject } from "../utils";
1212
import path = require("path");
1313

1414
abstract class ConfigurableCodeLensProvider implements CodeLensProvider {
@@ -82,7 +82,9 @@ abstract class OnRequestCodeLensProvider extends RegularExpressionCodeLensProvid
8282
return undefined;
8383
}
8484

85-
const dartFrogProjectPath = nearestDartFrogProject(document.uri.fsPath);
85+
const dartFrogProjectPath = nearestParentDartFrogProject(
86+
document.uri.fsPath
87+
);
8688
if (!dartFrogProjectPath) {
8789
return undefined;
8890
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
} from "vscode";
1010
import {
1111
isDartFrogCLIInstalled,
12-
nearestDartFrogProject,
12+
nearestParentDartFrogProject,
1313
normalizeRoutePath,
1414
resolveDartFrogProjectPathFromWorkspace,
1515
suggestInstallingDartFrogCLI,
@@ -57,7 +57,7 @@ export const newMiddleware = async (uri: Uri | undefined): Promise<void> => {
5757
selectedPath = uri.fsPath;
5858
}
5959

60-
const dartFrogProjectPath = nearestDartFrogProject(selectedPath);
60+
const dartFrogProjectPath = nearestParentDartFrogProject(selectedPath);
6161
if (dartFrogProjectPath === undefined) {
6262
window.showErrorMessage(
6363
"No Dart Frog project found in the selected directory"

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
} from "vscode";
1010
import {
1111
isDartFrogCLIInstalled,
12-
nearestDartFrogProject,
12+
nearestParentDartFrogProject,
1313
normalizeRoutePath,
1414
resolveDartFrogProjectPathFromWorkspace,
1515
suggestInstallingDartFrogCLI,
@@ -57,7 +57,7 @@ export const newRoute = async (uri: Uri | undefined): Promise<void> => {
5757
selectedPath = uri.fsPath;
5858
}
5959

60-
const dartFrogProjectPath = nearestDartFrogProject(selectedPath);
60+
const dartFrogProjectPath = nearestParentDartFrogProject(selectedPath);
6161
if (dartFrogProjectPath === undefined) {
6262
window.showErrorMessage(
6363
"No Dart Frog project found in the selected directory"

extensions/vscode/src/commands/start-daemon.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {
22
isDartFrogCLIInstalled,
3-
nearestDartFrogProject,
3+
nearestParentDartFrogProject,
44
resolveDartFrogProjectPathFromWorkspace,
55
suggestInstallingDartFrogCLI,
66
} from "../utils";
@@ -35,7 +35,7 @@ export const startDaemon = async (): Promise<void> => {
3535

3636
const dartFrogProjectPath = resolveDartFrogProjectPathFromWorkspace();
3737
const rootDartFrogProjectPath = dartFrogProjectPath
38-
? nearestDartFrogProject(dartFrogProjectPath)
38+
? nearestParentDartFrogProject(dartFrogProjectPath)
3939
: undefined;
4040
if (!rootDartFrogProjectPath) {
4141
window.showErrorMessage(

extensions/vscode/src/commands/start-dev-server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
import { Uri, commands, window } from "vscode";
99
import {
1010
isDartFrogCLIInstalled,
11-
nearestDartFrogProject,
11+
nearestParentDartFrogProject,
1212
resolveDartFrogProjectPathFromWorkspace,
1313
suggestInstallingDartFrogCLI,
1414
} from "../utils";
@@ -58,7 +58,7 @@ export const startDevServer = async (): Promise<
5858

5959
const workingPath = resolveDartFrogProjectPathFromWorkspace();
6060
const workingDirectory = workingPath
61-
? nearestDartFrogProject(workingPath)
61+
? nearestParentDartFrogProject(workingPath)
6262
: undefined;
6363
if (!workingDirectory) {
6464
await window.showErrorMessage(

extensions/vscode/src/test/suite/code-lens/on-request-code-lens.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ suite("RunOnRequestCodeLensProvider", () => {
6262
getConfiguration.withArgs("enableCodeLens", true).returns(true);
6363

6464
utilsStub = {
65-
nearestDartFrogProject: sinon.stub(),
65+
nearestParentDartFrogProject: sinon.stub(),
6666
};
67-
utilsStub.nearestDartFrogProject.returns("/home/dart_frog");
67+
utilsStub.nearestParentDartFrogProject.returns("/home/dart_frog");
6868

6969
RunOnRequestCodeLensProvider = proxyquire(
7070
"../../../code-lens/on-request-code-lens",
@@ -137,7 +137,7 @@ suite("RunOnRequestCodeLensProvider", () => {
137137
});
138138

139139
test("in a Dart Frog project", () => {
140-
utilsStub.nearestDartFrogProject.returns(undefined);
140+
utilsStub.nearestParentDartFrogProject.returns(undefined);
141141

142142
const provider = new RunOnRequestCodeLensProvider();
143143
const result = provider.provideCodeLenses(document);
@@ -263,9 +263,9 @@ suite("DebugOnRequestCodeLensProvider", () => {
263263
getConfiguration.withArgs("enableCodeLens", true).returns(true);
264264

265265
utilsStub = {
266-
nearestDartFrogProject: sinon.stub(),
266+
nearestParentDartFrogProject: sinon.stub(),
267267
};
268-
utilsStub.nearestDartFrogProject.returns("/home/dart_frog");
268+
utilsStub.nearestParentDartFrogProject.returns("/home/dart_frog");
269269

270270
DebugOnRequestCodeLensProvider = proxyquire(
271271
"../../../code-lens/on-request-code-lens",
@@ -338,7 +338,7 @@ suite("DebugOnRequestCodeLensProvider", () => {
338338
});
339339

340340
test("in a Dart Frog project", () => {
341-
utilsStub.nearestDartFrogProject.returns(undefined);
341+
utilsStub.nearestParentDartFrogProject.returns(undefined);
342342

343343
const provider = new DebugOnRequestCodeLensProvider();
344344
const result = provider.provideCodeLenses(document);

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

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@ suite("new-middleware command", () => {
2626
exec: sinon.stub(),
2727
};
2828
utilsStub = {
29-
nearestDartFrogProject: sinon.stub(),
29+
nearestParentDartFrogProject: sinon.stub(),
3030
normalizeRoutePath: sinon.stub(),
3131
resolveDartFrogProjectPathFromWorkspace: sinon.stub(),
3232
isDartFrogCLIInstalled: sinon.stub(),
3333
suggestInstallingDartFrogCLI: sinon.stub(),
3434
};
3535
utilsStub.isDartFrogCLIInstalled.returns(true);
3636

37-
utilsStub.nearestDartFrogProject
37+
utilsStub.nearestParentDartFrogProject
3838
.withArgs(invalidUri.fsPath)
3939
.returns(undefined);
40-
utilsStub.nearestDartFrogProject
40+
utilsStub.nearestParentDartFrogProject
4141
.withArgs(validUri.fsPath)
4242
.returns(validUri.fsPath);
4343

@@ -92,7 +92,7 @@ suite("new-middleware command", () => {
9292
utilsStub.resolveDartFrogProjectPathFromWorkspace.returns(
9393
"/home/dart_frog/routes"
9494
);
95-
utilsStub.nearestDartFrogProject.returns("/home/dart_frog/");
95+
utilsStub.nearestParentDartFrogProject.returns("/home/dart_frog/");
9696
utilsStub.normalizeRoutePath.returns("/");
9797

9898
await command.newMiddleware();
@@ -164,7 +164,9 @@ suite("new-middleware command", () => {
164164
utilsStub.resolveDartFrogProjectPathFromWorkspace.returns(
165165
"home/routes/animals/frog"
166166
);
167-
utilsStub.nearestDartFrogProject.returns("home/routes/animals/frog");
167+
utilsStub.nearestParentDartFrogProject.returns(
168+
"home/routes/animals/frog"
169+
);
168170
utilsStub.normalizeRoutePath.returns("/animals/frog");
169171

170172
await command.newMiddleware();
@@ -177,7 +179,9 @@ suite("new-middleware command", () => {
177179
});
178180

179181
test("is not shown when Uri is defined and selected file is valid", async () => {
180-
utilsStub.nearestDartFrogProject.returns("home/routes/animals/frog");
182+
utilsStub.nearestParentDartFrogProject.returns(
183+
"home/routes/animals/frog"
184+
);
181185
utilsStub.normalizeRoutePath.returns("/animals/frog");
182186

183187
await command.newMiddleware(validUri);
@@ -198,7 +202,9 @@ suite("new-middleware command", () => {
198202
utilsStub.resolveDartFrogProjectPathFromWorkspace.returns(
199203
"home/routes/animals/frog"
200204
);
201-
utilsStub.nearestDartFrogProject.returns("home/routes/animals/frog");
205+
utilsStub.nearestParentDartFrogProject.returns(
206+
"home/routes/animals/frog"
207+
);
202208
utilsStub.normalizeRoutePath.returns("/animals/frog");
203209
});
204210

@@ -232,7 +238,7 @@ suite("new-middleware command", () => {
232238
const selectedUri = {
233239
fsPath: `${validUri.fsPath}${routePath}`,
234240
};
235-
utilsStub.nearestDartFrogProject.returns(selectedUri);
241+
utilsStub.nearestParentDartFrogProject.returns(selectedUri);
236242
utilsStub.normalizeRoutePath.returns(routePath);
237243

238244
await command.newMiddleware(validUri);
@@ -262,7 +268,7 @@ suite("new-middleware command", () => {
262268
const selectedUri = {
263269
fsPath: `${validUri.fsPath}/food/pizza.dart`,
264270
};
265-
utilsStub.nearestDartFrogProject.returns(selectedUri);
271+
utilsStub.nearestParentDartFrogProject.returns(selectedUri);
266272
utilsStub.normalizeRoutePath.returns(`food/pizza`);
267273

268274
await command.newMiddleware(selectedUri);
@@ -280,7 +286,7 @@ suite("new-middleware command", () => {
280286
const selectedUri = {
281287
fsPath: `${validUri.fsPath}/index.dart`,
282288
};
283-
utilsStub.nearestDartFrogProject.returns(selectedUri);
289+
utilsStub.nearestParentDartFrogProject.returns(selectedUri);
284290
utilsStub.normalizeRoutePath.returns("/");
285291

286292
await command.newMiddleware(validUri);
@@ -298,7 +304,7 @@ suite("new-middleware command", () => {
298304
const selectedUri = {
299305
fsPath: `${validUri.fsPath}/food/italian/index.dart`,
300306
};
301-
utilsStub.nearestDartFrogProject.returns(selectedUri);
307+
utilsStub.nearestParentDartFrogProject.returns(selectedUri);
302308
utilsStub.normalizeRoutePath.returns("food/italian");
303309

304310
await command.newMiddleware(selectedUri);
@@ -316,7 +322,9 @@ suite("new-middleware command", () => {
316322
utilsStub.resolveDartFrogProjectPathFromWorkspace.returns(
317323
"home/routes/animals/frog"
318324
);
319-
utilsStub.nearestDartFrogProject.returns("home/routes/animals/frog");
325+
utilsStub.nearestParentDartFrogProject.returns(
326+
"home/routes/animals/frog"
327+
);
320328
utilsStub.normalizeRoutePath.returns("/animals/frog");
321329
vscodeStub.window.showInputBox.returns("animals/lion");
322330

@@ -336,7 +344,7 @@ suite("new-middleware command", () => {
336344
const error = Error("Failed to run `dart_frog new middleware`");
337345
childProcessStub.exec.yields(error);
338346

339-
utilsStub.nearestDartFrogProject.returns(validUri);
347+
utilsStub.nearestParentDartFrogProject.returns(validUri);
340348
utilsStub.normalizeRoutePath.returns("/");
341349

342350
await command.newMiddleware(validUri);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ suite("new-route command", () => {
2828
};
2929

3030
utilsStub = {
31-
nearestDartFrogProject: sinon.stub(),
31+
nearestParentDartFrogProject: sinon.stub(),
3232
normalizeRoutePath: sinon.stub(),
3333
resolveDartFrogProjectPathFromWorkspace: sinon.stub(),
3434
isDartFrogCLIInstalled: sinon.stub(),
3535
suggestInstallingDartFrogCLI: sinon.stub(),
3636
};
3737

38-
utilsStub.nearestDartFrogProject
38+
utilsStub.nearestParentDartFrogProject
3939
.withArgs(invalidUri.fsPath)
4040
.returns(undefined);
41-
utilsStub.nearestDartFrogProject
41+
utilsStub.nearestParentDartFrogProject
4242
.withArgs(validUri.fsPath)
4343
.returns(validUri.fsPath);
4444
utilsStub.isDartFrogCLIInstalled.returns(true);

extensions/vscode/src/test/suite/commands/start-daemon.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ suite("start-daemon command", () => {
2222
isDartFrogCLIInstalled: sinon.stub(),
2323
suggestInstallingDartFrogCLI: sinon.stub(),
2424
resolveDartFrogProjectPathFromWorkspace: sinon.stub(),
25-
nearestDartFrogProject: sinon.stub(),
25+
nearestParentDartFrogProject: sinon.stub(),
2626
};
2727
utilsStub.isDartFrogCLIInstalled.returns(true);
2828

@@ -98,7 +98,7 @@ suite("start-daemon command", () => {
9898
utilsStub.isDartFrogCLIInstalled.returns(true);
9999
dartFrogDaemon.DartFrogDaemon.instance.isReady = false;
100100
utilsStub.resolveDartFrogProjectPathFromWorkspace.returns("path");
101-
utilsStub.nearestDartFrogProject.returns(undefined);
101+
utilsStub.nearestParentDartFrogProject.returns(undefined);
102102

103103
await command.startDaemon();
104104

@@ -113,7 +113,7 @@ suite("start-daemon command", () => {
113113
dartFrogDaemon.DartFrogDaemon.instance.isReady = false;
114114
dartFrogDaemon.DartFrogDaemon.instance.invoke = sinon.stub();
115115
utilsStub.resolveDartFrogProjectPathFromWorkspace.returns("path");
116-
utilsStub.nearestDartFrogProject.returns("path");
116+
utilsStub.nearestParentDartFrogProject.returns("path");
117117

118118
await command.startDaemon();
119119

@@ -133,7 +133,7 @@ suite("start-daemon command", () => {
133133
dartFrogDaemon.DartFrogDaemon.instance.isReady = false;
134134
dartFrogDaemon.DartFrogDaemon.instance.invoke = sinon.stub();
135135
utilsStub.resolveDartFrogProjectPathFromWorkspace.returns("path");
136-
utilsStub.nearestDartFrogProject.returns("path");
136+
utilsStub.nearestParentDartFrogProject.returns("path");
137137

138138
await command.startDaemon();
139139

@@ -178,7 +178,7 @@ suite("start-daemon command", () => {
178178
dartFrogDaemon.DartFrogDaemon.instance.isReady = false;
179179
dartFrogDaemon.DartFrogDaemon.instance.invoke = sinon.stub();
180180
utilsStub.resolveDartFrogProjectPathFromWorkspace.returns("path");
181-
utilsStub.nearestDartFrogProject.returns(undefined);
181+
utilsStub.nearestParentDartFrogProject.returns(undefined);
182182

183183
await command.startDaemon();
184184

0 commit comments

Comments
 (0)