дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-05 01:31:41 +02:00
fix(run): don't let an unedited invalid configuration block saving others (#7708)
Running the same Maven goals with different options (clean install / clean install -U) named two temporary configurations alike, which made both invalid; any invalid configuration disabled OK and Apply in Run/Debug Configurations, so no other configuration could be saved. A temporary configuration whose name is taken now gets a numbered name, and only configurations added or changed in the dialog block saving. One that was already invalid when the dialog opened keeps its marker; Run and Debug stay disabled for it. Fixes #7621
Цей коміт міститься в:
1 джерело
8397e5e2a3
коміт
e30651473d
3 files changed
+53
-5
No files matched your search
@@ -230,8 +230,20 @@ function EditConfigsDialog() {
|
||||
}
|
||||
return out;
|
||||
}, [draft, formErrorsById, types]);
|
||||
const invalid = Object.keys(errorsById).length > 0;
|
||||
// Only configurations added or changed here keep the dialog from saving: one that was already
|
||||
// invalid when it opened (an older temporary, a project file) doesn't block the others.
|
||||
const [opened] = useState(() => new Map(initialConfigs.map((c) => [c.id, JSON.stringify(c)])));
|
||||
const [savedUnedited] = useState(() => (useRun.getState().editDirty ? target : null));
|
||||
const blocking = useMemo(
|
||||
() =>
|
||||
draft
|
||||
.filter((c) => errorsById[c.id] && (c.id === savedUnedited || opened.get(c.id) !== JSON.stringify(c)))
|
||||
.map((c) => c.id),
|
||||
[draft, errorsById, opened, savedUnedited],
|
||||
);
|
||||
const invalid = blocking.length > 0;
|
||||
const errors = (current && errorsById[current.id]) ?? {};
|
||||
const cannotLaunch = invalid || (!!current && !!errorsById[current.id]);
|
||||
const currentType = current ? typeForConfig(current, types) : undefined;
|
||||
const currentTemplateType = currentTemplate ? typeFor(currentTemplate.kind) : undefined;
|
||||
|
||||
@@ -323,7 +335,7 @@ function EditConfigsDialog() {
|
||||
|
||||
const save = async (andClose: boolean): Promise<boolean> => {
|
||||
if (invalid) {
|
||||
const firstBad = Object.keys(errorsById)[0];
|
||||
const firstBad = blocking[0];
|
||||
if (firstBad) {
|
||||
setMode("configs");
|
||||
setSelection({ type: "config", id: firstBad });
|
||||
@@ -414,14 +426,14 @@ function EditConfigsDialog() {
|
||||
<span className={styles.footerRun}>
|
||||
<Button
|
||||
icon="run"
|
||||
disabled={!current || saving || invalid || mode !== "configs"}
|
||||
disabled={!current || saving || cannotLaunch || mode !== "configs"}
|
||||
onClick={() => void launch(false)}
|
||||
>
|
||||
<T>Run</T>
|
||||
</Button>
|
||||
<Button
|
||||
icon="debug"
|
||||
disabled={!current || saving || invalid || mode !== "configs"}
|
||||
disabled={!current || saving || cannotLaunch || mode !== "configs"}
|
||||
onClick={() => void launch(true)}
|
||||
>
|
||||
<T>Debug</T>
|
||||
|
||||
@@ -222,3 +222,34 @@ it("keeps unedited temporary configurations temporary and saves edited ones", as
|
||||
expect(useRun.getState().temporary).toEqual([goal.id]);
|
||||
expect(temporaryOf().map((c) => c.id)).toEqual([goal.id]);
|
||||
});
|
||||
|
||||
it("names a Maven goal run with other options apart from the earlier one", () => {
|
||||
const goal: RunConfig = { ...config("maven"), id: "maven:goal:pom.xml:clean install", name: "app [clean,install]" };
|
||||
adoptTemporary({ ...goal, detected: false });
|
||||
adoptTemporary({ ...goal, id: "maven:goal:pom.xml:clean install -U", detected: false });
|
||||
expect(useRun.getState().configs.map((c) => c.name)).toEqual([
|
||||
"Detected app",
|
||||
"app [clean,install]",
|
||||
"app [clean,install] (2)",
|
||||
]);
|
||||
});
|
||||
|
||||
it("saves an edited configuration next to one that was already invalid", async () => {
|
||||
// Saved before temporaries got distinct names: both are flagged, neither blocks the other.
|
||||
const goal: RunConfig = { ...config("maven"), id: "maven:goal:pom.xml:test", name: "app [test]", detected: false };
|
||||
const twin: RunConfig = { ...goal, id: "maven:goal:pom.xml:test -U" };
|
||||
const user: RunConfig = { ...config("npm"), id: "user:app", name: "App", detected: false };
|
||||
useRun.setState({ configs: [...backend, goal, twin, user], temporary: [goal.id, twin.id], editTarget: user.id });
|
||||
render(<EditConfigsOverlay />);
|
||||
expect(screen.getAllByLabelText("Invalid")).toHaveLength(2);
|
||||
fireEvent.change(screen.getByRole("textbox", { name: "Name" }), { target: { value: "App 2" } });
|
||||
expect(screen.queryByText("Fix the highlighted fields")).not.toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole("button", { name: "Apply" }));
|
||||
await waitFor(() =>
|
||||
expect(ipc.runSaveConfigs).toHaveBeenCalledWith([expect.objectContaining({ id: user.id, name: "App 2" })], []),
|
||||
);
|
||||
// An edit that makes a configuration invalid still blocks saving.
|
||||
fireEvent.change(screen.getByRole("textbox", { name: "Name" }), { target: { value: "app [test]" } });
|
||||
expect(screen.getByText("Fix the highlighted fields")).toBeInTheDocument();
|
||||
expect(screen.getByRole("button", { name: "OK" })).toBeDisabled();
|
||||
});
|
||||
@@ -71,7 +71,7 @@ import {
|
||||
} from "./testing/snapshots";
|
||||
import type { StateQuery } from "./testing/states";
|
||||
import { buildCMake, isCMakeBuild } from "./cmake";
|
||||
import { compoundChildren } from "./configs";
|
||||
import { compoundChildren, uniqueName } from "./configs";
|
||||
import { remoteLabel, startWithRemedies } from "./remote";
|
||||
import { TerminalOutput } from "./terminalOutput";
|
||||
import { typeFor, typeForConfig } from "./types";
|
||||
@@ -569,6 +569,11 @@ export function adoptTemporary(config: RunConfig): RunConfig {
|
||||
selectConfig(existing.id);
|
||||
return existing;
|
||||
}
|
||||
// Two configurations with one name can't be saved (IDEA's `suggestUniqueName`): goals that differ
|
||||
// only in options (`clean install` / `clean install -U`) are named alike.
|
||||
const others = state.configs.filter((c) => c.id !== config.id);
|
||||
if (others.some((c) => c.name.trim() === config.name.trim()))
|
||||
config = { ...config, name: uniqueName(config.name, others) };
|
||||
let temporary = [...state.temporary.filter((id) => id !== config.id), config.id];
|
||||
const busy = new Set(state.sessions.filter(isLive).map((x) => x.config.id));
|
||||
for (const session of useDebugRunSessions.getState().sessions) if (session.configId) busy.add(session.configId);
|
||||
|
||||
Reference in new issue
Заблокувати користувача