дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-05 09:41:34 +02:00
fix(xcode): select the root scheme and the backend's default simulator in Xcode projects (#7366)
An Xcode project with an npm package in a subfolder opened with that package's dev script selected, and the simulator chooser showed an iPad when nothing was booted. - defaultSelection scored a root Xcode scheme the same as any run/dev script, so list order decided. A root scheme (kind xcode, no cwd) now scores like a Spring Boot application; schemes in subfolders and other project types keep their order, and a saved selection still wins. - currentIosSimulator fell back to the first listed simulator, while the backend's pick_simulator takes a booted simulator, then the newest iPhone. The toolbar now applies the same rule, and pick_simulator ranks over simulator::parse_list so both sides agree on ties. Fixes #7354 Co-authored-by: wildcatDownstairs <[email protected]>
Цей коміт міститься в:
1 джерело
71d88d0b55
коміт
2a7975a077
5 files changed
+66
-23
No files matched your search
@@ -230,25 +230,13 @@ pub fn default_simulator(dir: &Path) -> Option<String> {
|
||||
pick_simulator(&String::from_utf8_lossy(&out.stdout))
|
||||
}
|
||||
|
||||
/// The same rule as the toolbar's default (`currentIosSimulator`), over the same ordering.
|
||||
fn pick_simulator(json: &str) -> Option<String> {
|
||||
let devices: serde_json::Value = serde_json::from_str(json).ok()?;
|
||||
let mut runtimes: Vec<(Vec<u32>, &Vec<serde_json::Value>)> = devices
|
||||
.get("devices")?
|
||||
.as_object()?
|
||||
.iter()
|
||||
.filter_map(|(runtime, list)| {
|
||||
let version = runtime.strip_prefix("com.apple.CoreSimulator.SimRuntime.iOS-")?;
|
||||
Some((version.split('-').filter_map(|n| n.parse().ok()).collect(), list.as_array()?))
|
||||
})
|
||||
.collect();
|
||||
runtimes.sort_by(|a, b| b.0.cmp(&a.0));
|
||||
let all = || runtimes.iter().flat_map(|(_, list)| list.iter());
|
||||
let field = |d: &serde_json::Value, key: &str| d.get(key).and_then(|v| v.as_str()).unwrap_or_default().to_owned();
|
||||
all()
|
||||
.find(|d| field(d, "state") == "Booted")
|
||||
.or_else(|| all().find(|d| field(d, "name").starts_with("iPhone")))
|
||||
.map(|d| field(d, "udid"))
|
||||
.filter(|udid| !udid.is_empty())
|
||||
let list = crate::simulator::parse_list(json).ok()?;
|
||||
list.iter()
|
||||
.find(|d| d.state == "Booted")
|
||||
.or_else(|| list.iter().find(|d| d.name.starts_with("iPhone")))
|
||||
.map(|d| d.udid.clone())
|
||||
}
|
||||
|
||||
/// The run configuration parameter that holds the simulator's UDID. Empty means
|
||||
|
||||
@@ -108,6 +108,19 @@ describe("config merge / override", () => {
|
||||
];
|
||||
expect(defaultSelection(spring)?.id).toBe("application:demo.App");
|
||||
});
|
||||
|
||||
it("prefers the root Xcode project's first scheme over scripts in subfolders", () => {
|
||||
const list = [
|
||||
cfg({ id: "npm:Scripts/slack_ios/worker:dev", kind: "npm", cwd: "Scripts/slack_ios/worker" }),
|
||||
cfg({ id: "xcode:run:Tools/Tools.xcodeproj:Tool", kind: "xcode", cwd: "Tools" }),
|
||||
cfg({ id: "xcode:run:wasai.xcworkspace:wasai", name: "wasai", kind: "xcode" }),
|
||||
cfg({ id: "xcode:run:wasai.xcworkspace:WasaiKit", name: "WasaiKit", kind: "xcode" }),
|
||||
cfg({ id: "xcode:test:wasai.xcworkspace:wasai", kind: "xcode-test", isTest: true }),
|
||||
];
|
||||
expect(defaultSelection(list)?.id).toBe("xcode:run:wasai.xcworkspace:wasai");
|
||||
// An Xcode project in a subfolder leaves the root's own run script first.
|
||||
expect(defaultSelection([cfg({ id: "npm:dev", kind: "npm" }), list[1]!])?.id).toBe("npm:dev");
|
||||
});
|
||||
});
|
||||
|
||||
describe("validateConfig", () => {
|
||||
|
||||
@@ -369,11 +369,15 @@ async function reattachRemoteRuns(root: string, knownConfigs: readonly RunConfig
|
||||
}
|
||||
}
|
||||
|
||||
/** IDEA picks an application config first; prefer a run/dev/start target over builds and tests. */
|
||||
/**
|
||||
* IDEA picks an application config first; prefer a run/dev/start target over builds and tests.
|
||||
* In an Xcode project the root's first scheme wins, as it does for the backend's builds.
|
||||
*/
|
||||
export function defaultSelection(configs: readonly RunConfig[]): RunConfig | undefined {
|
||||
const score = (c: RunConfig) => {
|
||||
if (c.isTest) return 1;
|
||||
if (c.kind === "spring-boot") return 4;
|
||||
// A root Xcode scheme has no cwd; one in a subfolder runs there.
|
||||
if (c.kind === "spring-boot" || (c.kind === "xcode" && !c.cwd)) return 4;
|
||||
const s = `${c.id} ${c.name}`.toLowerCase();
|
||||
if (/bootrun|spring-boot:run|:run\b|run:|\bdev\b|\bstart\b|\bserve\b|runserver/.test(s)) return 3;
|
||||
if (/build|package|lint|check|format|clean/.test(s)) return 0;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import type { IosSimulator, RunConfig } from "@/platform/ipc";
|
||||
import { iosSimulatorFor, refreshIosSimulators, useIosSimulators } from "./iosSimulators";
|
||||
import { currentIosSimulator, iosSimulatorFor, refreshIosSimulators, useIosSimulators } from "./iosSimulators";
|
||||
|
||||
vi.mock("./contributions", () => ({ notifications: () => ({ notify: vi.fn() }) }));
|
||||
|
||||
@@ -34,6 +34,34 @@ describe("iosSimulatorFor", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("currentIosSimulator", () => {
|
||||
// Ordered as the backend lists them: booted, then newest runtime, then by name, then devices.
|
||||
const named = (udid: string, name: string, runtime = "iOS 27.0", state = "Shutdown") => ({
|
||||
...sim(udid, state),
|
||||
name,
|
||||
runtime,
|
||||
});
|
||||
const pad = named("PAD", "iPad (A16)");
|
||||
const phone = named("PHONE", "iPhone 18");
|
||||
const oldPhone = named("OLD", "iPhone 16", "iOS 18.2");
|
||||
const device = { ...named("DEVICE", "iPhone", "iOS 27.0", "Available"), physical: true };
|
||||
|
||||
it("defaults to a booted simulator, then the newest iPhone, as the backend does", () => {
|
||||
useIosSimulators.setState({ list: [pad, phone, oldPhone, device], preferred: null });
|
||||
expect(currentIosSimulator()?.udid).toBe("PHONE");
|
||||
const booted = { ...oldPhone, state: "Booted" };
|
||||
useIosSimulators.setState({ list: [booted, pad, phone, device] });
|
||||
expect(currentIosSimulator()?.udid).toBe("OLD");
|
||||
useIosSimulators.setState({ list: [pad, device] });
|
||||
expect(currentIosSimulator()?.udid).toBe("PAD");
|
||||
});
|
||||
|
||||
it("keeps the simulator the user picked", () => {
|
||||
useIosSimulators.setState({ list: [pad, phone], preferred: "PAD" });
|
||||
expect(currentIosSimulator()?.udid).toBe("PAD");
|
||||
});
|
||||
});
|
||||
|
||||
describe("refreshIosSimulators", () => {
|
||||
it("keeps the chooser hidden when the first listing fails, and reports later failures", async () => {
|
||||
useIosSimulators.setState({ root: "/p", list: null, error: null });
|
||||
|
||||
@@ -36,10 +36,20 @@ function storedSimulator(root: string): string | null {
|
||||
}
|
||||
}
|
||||
|
||||
/** The toolbar's simulator: the chosen one while listed, else the first (booted ones come first). */
|
||||
/**
|
||||
* The toolbar's simulator: the chosen one while listed, else the backend's default
|
||||
* (`pick_simulator`): a booted simulator, then the newest iPhone. The list comes booted first,
|
||||
* then newest runtime first.
|
||||
*/
|
||||
export function currentIosSimulator(state = useIosSimulators.getState()): IosSimulator | null {
|
||||
const list = state.list ?? [];
|
||||
return list.find((s) => s.udid === state.preferred) ?? list[0] ?? null;
|
||||
return (
|
||||
list.find((s) => s.udid === state.preferred) ??
|
||||
list.find((s) => !s.physical && s.state === "Booted") ??
|
||||
list.find((s) => !s.physical && s.name.startsWith("iPhone")) ??
|
||||
list[0] ??
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Заблокувати користувача