From 6dddfde3bc244754cb1f551a12e323fb3f6ca3d7 Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Thu, 26 Nov 2026 13:33:39 +0800 Subject: [PATCH] fix(run): keep a saved configuration when its gutter action creates it again (#6079) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "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 --- src/features/run/configs.test.ts | 20 ++++++++++++++++++++ src/features/run/configs.ts | 16 ++++++++++++++++ src/features/run/index.ts | 11 ++++++----- 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/src/features/run/configs.test.ts b/src/features/run/configs.test.ts index e3a8457f4..bb706e2ba 100644 --- a/src/features/run/configs.test.ts +++ b/src/features/run/configs.test.ts @@ -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]); + }); +}); diff --git a/src/features/run/configs.ts b/src/features/run/configs.ts index e9a86c8ca..4d03c121b 100644 --- a/src/features/run/configs.ts +++ b/src/features/run/configs.ts @@ -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); } diff --git a/src/features/run/index.ts b/src/features/run/index.ts index 0fd9355ef..acfb69416 100644 --- a/src/features/run/index.ts +++ b/src/features/run/index.ts @@ -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 }); },