Compare commits

...
Author SHA1 Message Date
l0ng-ai 49443fea13 fix(run): run a Flutter app's Dart files with flutter run
Current File (and Run on a Dart file) ran `dart run <file>` even inside a
Flutter app, which can't start a Flutter program. In a folder with a
detected Flutter configuration the file now runs and debugs as the app,
`flutter run -t <file>` from the app's folder, on the toolbar's device.
Dart files outside a Flutter app keep `dart run`.
2026-11-19 11:00:54 +08:00
2 changed files with 36 additions and 1 deletions

No files matched your search

+20
View File
@@ -776,6 +776,26 @@ describe("project producers", () => {
expect(produceContext({ path: `${ROOT}/a.tscn`, root: ROOT, configs: [] }, OPTIMISTIC)).toBeNull();
});
it("Dart files of a Flutter app run as the app (flutter run -t) in the app's folder", () => {
const flutter = [
cfg({ id: "flutter:run", kind: "flutter", command: "flutter", args: ["run", "-t", "lib/main.dart"], cwd: "app" }),
];
const p = produceContext({ path: `${ROOT}/app/lib/demo.dart`, root: ROOT, configs: flutter }, ALL)!;
expect(p).toMatchObject({ name: "demo.dart", scope: "file" });
expect(p.config).toMatchObject({
kind: "flutter",
command: "flutter",
args: ["run", "-t", "lib/demo.dart"],
cwd: "app",
debugAdapter: "dart",
});
// Outside the app (a Dart package next to it): `dart run`.
expect(run({ path: `${ROOT}/tool/gen.dart`, root: ROOT, configs: flutter })).toMatchObject({
command: "/bin/dart",
args: ["run", "tool/gen.dart"],
});
});
it("keeps package.json test files on the project's runner", () => {
const p = produceContext(
{ path: `${ROOT}/src/a.test.ts`, root: ROOT, configs, content: "test('x', () => {})" },
+16 -1
View File
@@ -438,6 +438,7 @@ function site(input: ContextInput): FileSite {
ruby: ["ruby", "rake", "rspec"],
php: ["php", "phpunit", "composer"],
zig: ["zig", "zig-application"],
dart: ["flutter"],
};
const owner =
inside && language
@@ -992,8 +993,22 @@ export function produceFile(input: ContextInput, env: ToolEnv): Produced | null
return simple(lang, s, env, lang, () => [s.arg]);
case "r":
return simple(lang, s, env, "r", () => [s.arg]);
case "dart":
case "dart": {
// A file of a Flutter app runs as the app (`flutter run -t`), on the toolbar's device.
const app = s.inProject
? allClosest(
input.configs.filter((c) => c.kind === "flutter"),
s.idPath,
)[0]
: undefined;
if (app)
return {
name: s.file,
scope: "file",
config: fileConfig(s, "flutter", app.command, ["run", "-t", s.arg], "dart"),
};
return simple(lang, s, env, "dart", () => ["run", s.arg], "dart");
}
case "scala":
return simple(lang, s, env, "scala-cli", () => ["run", s.arg]);
case "kotlin":