Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(vscode): implemented nearestChildDartFrogProjects #1015

Merged
merged 12 commits into from
Sep 11, 2023
Merged
6 changes: 4 additions & 2 deletions extensions/vscode/src/code-lens/on-request-code-lens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
TextDocument,
workspace,
} from "vscode";
import { nearestDartFrogProject } from "../utils";
import { nearestParentDartFrogProject } from "../utils";
import path = require("path");

abstract class ConfigurableCodeLensProvider implements CodeLensProvider {
Expand Down Expand Up @@ -82,7 +82,9 @@ abstract class OnRequestCodeLensProvider extends RegularExpressionCodeLensProvid
return undefined;
}

const dartFrogProjectPath = nearestDartFrogProject(document.uri.fsPath);
const dartFrogProjectPath = nearestParentDartFrogProject(
document.uri.fsPath
);
if (!dartFrogProjectPath) {
return undefined;
}
Expand Down
4 changes: 2 additions & 2 deletions extensions/vscode/src/commands/new-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from "vscode";
import {
isDartFrogCLIInstalled,
nearestDartFrogProject,
nearestParentDartFrogProject,
normalizeRoutePath,
resolveDartFrogProjectPathFromWorkspace,
suggestInstallingDartFrogCLI,
Expand Down Expand Up @@ -57,7 +57,7 @@ export const newMiddleware = async (uri: Uri | undefined): Promise<void> => {
selectedPath = uri.fsPath;
}

const dartFrogProjectPath = nearestDartFrogProject(selectedPath);
const dartFrogProjectPath = nearestParentDartFrogProject(selectedPath);
if (dartFrogProjectPath === undefined) {
window.showErrorMessage(
"No Dart Frog project found in the selected directory"
Expand Down
4 changes: 2 additions & 2 deletions extensions/vscode/src/commands/new-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from "vscode";
import {
isDartFrogCLIInstalled,
nearestDartFrogProject,
nearestParentDartFrogProject,
normalizeRoutePath,
resolveDartFrogProjectPathFromWorkspace,
suggestInstallingDartFrogCLI,
Expand Down Expand Up @@ -57,7 +57,7 @@ export const newRoute = async (uri: Uri | undefined): Promise<void> => {
selectedPath = uri.fsPath;
}

const dartFrogProjectPath = nearestDartFrogProject(selectedPath);
const dartFrogProjectPath = nearestParentDartFrogProject(selectedPath);
if (dartFrogProjectPath === undefined) {
window.showErrorMessage(
"No Dart Frog project found in the selected directory"
Expand Down
4 changes: 2 additions & 2 deletions extensions/vscode/src/commands/start-daemon.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
isDartFrogCLIInstalled,
nearestDartFrogProject,
nearestParentDartFrogProject,
resolveDartFrogProjectPathFromWorkspace,
suggestInstallingDartFrogCLI,
} from "../utils";
Expand Down Expand Up @@ -35,7 +35,7 @@ export const startDaemon = async (): Promise<void> => {

const dartFrogProjectPath = resolveDartFrogProjectPathFromWorkspace();
const rootDartFrogProjectPath = dartFrogProjectPath
? nearestDartFrogProject(dartFrogProjectPath)
? nearestParentDartFrogProject(dartFrogProjectPath)
: undefined;
if (!rootDartFrogProjectPath) {
window.showErrorMessage(
Expand Down
4 changes: 2 additions & 2 deletions extensions/vscode/src/commands/start-dev-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import { Uri, commands, window } from "vscode";
import {
isDartFrogCLIInstalled,
nearestDartFrogProject,
nearestParentDartFrogProject,
resolveDartFrogProjectPathFromWorkspace,
suggestInstallingDartFrogCLI,
} from "../utils";
Expand Down Expand Up @@ -58,7 +58,7 @@ export const startDevServer = async (): Promise<

const workingPath = resolveDartFrogProjectPathFromWorkspace();
const workingDirectory = workingPath
? nearestDartFrogProject(workingPath)
? nearestParentDartFrogProject(workingPath)
: undefined;
if (!workingDirectory) {
await window.showErrorMessage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ suite("RunOnRequestCodeLensProvider", () => {
getConfiguration.withArgs("enableCodeLens", true).returns(true);

utilsStub = {
nearestDartFrogProject: sinon.stub(),
nearestParentDartFrogProject: sinon.stub(),
};
utilsStub.nearestDartFrogProject.returns("/home/dart_frog");
utilsStub.nearestParentDartFrogProject.returns("/home/dart_frog");

RunOnRequestCodeLensProvider = proxyquire(
"../../../code-lens/on-request-code-lens",
Expand Down Expand Up @@ -137,7 +137,7 @@ suite("RunOnRequestCodeLensProvider", () => {
});

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

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

utilsStub = {
nearestDartFrogProject: sinon.stub(),
nearestParentDartFrogProject: sinon.stub(),
};
utilsStub.nearestDartFrogProject.returns("/home/dart_frog");
utilsStub.nearestParentDartFrogProject.returns("/home/dart_frog");

DebugOnRequestCodeLensProvider = proxyquire(
"../../../code-lens/on-request-code-lens",
Expand Down Expand Up @@ -338,7 +338,7 @@ suite("DebugOnRequestCodeLensProvider", () => {
});

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

const provider = new DebugOnRequestCodeLensProvider();
const result = provider.provideCodeLenses(document);
Expand Down
34 changes: 21 additions & 13 deletions extensions/vscode/src/test/suite/commands/new-middleware.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ suite("new-middleware command", () => {
exec: sinon.stub(),
};
utilsStub = {
nearestDartFrogProject: sinon.stub(),
nearestParentDartFrogProject: sinon.stub(),
normalizeRoutePath: sinon.stub(),
resolveDartFrogProjectPathFromWorkspace: sinon.stub(),
isDartFrogCLIInstalled: sinon.stub(),
suggestInstallingDartFrogCLI: sinon.stub(),
};
utilsStub.isDartFrogCLIInstalled.returns(true);

utilsStub.nearestDartFrogProject
utilsStub.nearestParentDartFrogProject
.withArgs(invalidUri.fsPath)
.returns(undefined);
utilsStub.nearestDartFrogProject
utilsStub.nearestParentDartFrogProject
.withArgs(validUri.fsPath)
.returns(validUri.fsPath);

Expand Down Expand Up @@ -92,7 +92,7 @@ suite("new-middleware command", () => {
utilsStub.resolveDartFrogProjectPathFromWorkspace.returns(
"/home/dart_frog/routes"
);
utilsStub.nearestDartFrogProject.returns("/home/dart_frog/");
utilsStub.nearestParentDartFrogProject.returns("/home/dart_frog/");
utilsStub.normalizeRoutePath.returns("/");

await command.newMiddleware();
Expand Down Expand Up @@ -164,7 +164,9 @@ suite("new-middleware command", () => {
utilsStub.resolveDartFrogProjectPathFromWorkspace.returns(
"home/routes/animals/frog"
);
utilsStub.nearestDartFrogProject.returns("home/routes/animals/frog");
utilsStub.nearestParentDartFrogProject.returns(
"home/routes/animals/frog"
);
utilsStub.normalizeRoutePath.returns("/animals/frog");

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

test("is not shown when Uri is defined and selected file is valid", async () => {
utilsStub.nearestDartFrogProject.returns("home/routes/animals/frog");
utilsStub.nearestParentDartFrogProject.returns(
"home/routes/animals/frog"
);
utilsStub.normalizeRoutePath.returns("/animals/frog");

await command.newMiddleware(validUri);
Expand All @@ -198,7 +202,9 @@ suite("new-middleware command", () => {
utilsStub.resolveDartFrogProjectPathFromWorkspace.returns(
"home/routes/animals/frog"
);
utilsStub.nearestDartFrogProject.returns("home/routes/animals/frog");
utilsStub.nearestParentDartFrogProject.returns(
"home/routes/animals/frog"
);
utilsStub.normalizeRoutePath.returns("/animals/frog");
});

Expand Down Expand Up @@ -232,7 +238,7 @@ suite("new-middleware command", () => {
const selectedUri = {
fsPath: `${validUri.fsPath}${routePath}`,
};
utilsStub.nearestDartFrogProject.returns(selectedUri);
utilsStub.nearestParentDartFrogProject.returns(selectedUri);
utilsStub.normalizeRoutePath.returns(routePath);

await command.newMiddleware(validUri);
Expand Down Expand Up @@ -262,7 +268,7 @@ suite("new-middleware command", () => {
const selectedUri = {
fsPath: `${validUri.fsPath}/food/pizza.dart`,
};
utilsStub.nearestDartFrogProject.returns(selectedUri);
utilsStub.nearestParentDartFrogProject.returns(selectedUri);
utilsStub.normalizeRoutePath.returns(`food/pizza`);

await command.newMiddleware(selectedUri);
Expand All @@ -280,7 +286,7 @@ suite("new-middleware command", () => {
const selectedUri = {
fsPath: `${validUri.fsPath}/index.dart`,
};
utilsStub.nearestDartFrogProject.returns(selectedUri);
utilsStub.nearestParentDartFrogProject.returns(selectedUri);
utilsStub.normalizeRoutePath.returns("/");

await command.newMiddleware(validUri);
Expand All @@ -298,7 +304,7 @@ suite("new-middleware command", () => {
const selectedUri = {
fsPath: `${validUri.fsPath}/food/italian/index.dart`,
};
utilsStub.nearestDartFrogProject.returns(selectedUri);
utilsStub.nearestParentDartFrogProject.returns(selectedUri);
utilsStub.normalizeRoutePath.returns("food/italian");

await command.newMiddleware(selectedUri);
Expand All @@ -316,7 +322,9 @@ suite("new-middleware command", () => {
utilsStub.resolveDartFrogProjectPathFromWorkspace.returns(
"home/routes/animals/frog"
);
utilsStub.nearestDartFrogProject.returns("home/routes/animals/frog");
utilsStub.nearestParentDartFrogProject.returns(
"home/routes/animals/frog"
);
utilsStub.normalizeRoutePath.returns("/animals/frog");
vscodeStub.window.showInputBox.returns("animals/lion");

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

utilsStub.nearestDartFrogProject.returns(validUri);
utilsStub.nearestParentDartFrogProject.returns(validUri);
utilsStub.normalizeRoutePath.returns("/");

await command.newMiddleware(validUri);
Expand Down
6 changes: 3 additions & 3 deletions extensions/vscode/src/test/suite/commands/new-route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ suite("new-route command", () => {
};

utilsStub = {
nearestDartFrogProject: sinon.stub(),
nearestParentDartFrogProject: sinon.stub(),
normalizeRoutePath: sinon.stub(),
resolveDartFrogProjectPathFromWorkspace: sinon.stub(),
isDartFrogCLIInstalled: sinon.stub(),
suggestInstallingDartFrogCLI: sinon.stub(),
};

utilsStub.nearestDartFrogProject
utilsStub.nearestParentDartFrogProject
.withArgs(invalidUri.fsPath)
.returns(undefined);
utilsStub.nearestDartFrogProject
utilsStub.nearestParentDartFrogProject
.withArgs(validUri.fsPath)
.returns(validUri.fsPath);
utilsStub.isDartFrogCLIInstalled.returns(true);
Expand Down
10 changes: 5 additions & 5 deletions extensions/vscode/src/test/suite/commands/start-daemon.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ suite("start-daemon command", () => {
isDartFrogCLIInstalled: sinon.stub(),
suggestInstallingDartFrogCLI: sinon.stub(),
resolveDartFrogProjectPathFromWorkspace: sinon.stub(),
nearestDartFrogProject: sinon.stub(),
nearestParentDartFrogProject: sinon.stub(),
};
utilsStub.isDartFrogCLIInstalled.returns(true);

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

await command.startDaemon();

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

await command.startDaemon();

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

await command.startDaemon();

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

await command.startDaemon();

Expand Down