fix(run): keep a saved configuration when its gutter action creates it again (#6079)

"Modify Run Configuration…" from a Dockerfile's gutter icon (and the Maven tool window's Create Run Configuration) saved a freshly built configuration over the saved one with the same fixed id, so the bound ports and other edits were gone the next time it was opened. A saved configuration with that id now opens as the user left it; only a new one is saved.

Fixes #6047
Цей коміт міститься в:
l0ng-ai authored and GitHub committed 2026-11-26 13:33:39 +08:00
1 джерело 0324bc368d
коміт 6dddfde3bc
3 files changed
+42 -5

No files matched your search

+20
Переглянути файл
@@ -6,6 +6,7 @@ import {
categoryOf,
kindLabel,
commandLine,
createdConfigs,
duplicateConfig,
formatArgs,
groupConfigs,
@@ -584,3 +585,22 @@ describe("categoryOf", () => {
dispose();
});
});
describe("createdConfigs", () => {
const gutter = cfg({ id: "docker:dockerfile:Dockerfile", detected: false, params: { tag: "app" } });
it("saves a new configuration after the saved ones, leaving out detected and temporary ones", () => {
const configs = [cfg({ id: "d" }), cfg({ id: "u", detected: false }), cfg({ id: "t", detected: false })];
expect(createdConfigs(configs, ["t"], gutter)?.map((c) => c.id)).toEqual(["u", gutter.id]);
});
it("keeps a saved configuration with the same id as the user edited it (#6047)", () => {
const saved = { ...gutter, params: { tag: "app", ports: "8080:80" } };
expect(createdConfigs([saved], [], gutter)).toBeNull();
});
it("saves over a detected or temporary configuration with the same id", () => {
expect(createdConfigs([cfg({ id: gutter.id })], [], gutter)).toEqual([gutter]);
expect(createdConfigs([{ ...gutter, detected: false }], [gutter.id], gutter)).toEqual([gutter]);
});
});
+16
Переглянути файл
@@ -227,6 +227,22 @@ export function upsertConfig(configs: readonly RunConfig[], edited: RunConfig):
return out;
}
/**
* The saved configurations after "Create Run Configuration" for `config`, or `null` when one with
* its id is already saved: that one opens as the user left it. Gutter and tool-window actions
* build their configuration with a fixed id, so saving it again would reset the user's edits
* (a Dockerfile configuration's bound ports, #6047).
*/
export function createdConfigs(
configs: readonly RunConfig[],
temporary: readonly string[],
config: RunConfig,
): RunConfig[] | null {
const saved = configs.filter((c) => !c.detected && !temporary.includes(c.id));
if (saved.some((c) => c.id === config.id)) return null;
return [...saved, { ...config, detected: false }];
}
export function removeConfig(configs: readonly RunConfig[], id: string): RunConfig[] {
return configs.filter((c) => c.id !== id);
}
+6 -5
Переглянути файл
@@ -67,7 +67,7 @@ import { ServiceImportHost } from "./serviceImport";
import { selectedBuildTarget } from "./buildTarget";
import { configurationChecks } from "./configurationChecks";
import { runBeforeLaunch } from "./beforeLaunch";
import { compoundChildren } from "./configs";
import { compoundChildren, createdConfigs } from "./configs";
import { containerDebuggable, remoteDebugBlocked } from "./remote";
import { debugInContainer } from "./containerDebug";
import { isDebugOnly, registerBuiltinTypes } from "./types";
@@ -929,17 +929,18 @@ export function activate(): () => void {
{
id: "run.createConfig",
title: "Create Run Configuration",
description: "Saves the given `RunConfig` as a user configuration and opens it in Edit Configurations.",
description:
"Saves the given `RunConfig` as a user configuration and opens it in Edit Configurations; a saved one with its id opens unchanged.",
category: "Run",
hidden: true,
when: "projectOpen",
run: async ({ arg }) => {
if (!arg || typeof arg !== "object") return;
await ensureConfigs();
const config: RunConfig = { ...(arg as RunConfig), detected: false };
const config = arg as RunConfig;
const { configs, temporary } = useRun.getState();
const user = configs.filter((c) => !c.detected && !temporary.includes(c.id) && c.id !== config.id);
await saveUserConfigs([...user, config]);
const created = createdConfigs(configs, temporary, config);
if (created) await saveUserConfigs(created);
selectConfig(config.id);
useRun.setState({ editorOpen: true, chooserOpen: false, editTarget: config.id });
},