From e32215ecaf9472c8bf0e94558eef5722dac5d9d2 Mon Sep 17 00:00:00 2001 From: Connor Peet Date: Wed, 18 Mar 2026 08:32:20 -0700 Subject: [PATCH] aiCustomization: make plugin/extension/builtin files read-only (#302592) * aiCustomization: make plugin/extension/builtin files read-only - Open plugin, extension, and built-in customization files as read-only in the editor, with a message explaining they cannot be edited. - Extract isReadonlyStorage() helper to DRY the repeated storage type check used in both the open and delete actions. Fixes https://github.com/microsoft/vscode/issues/301292 (Commit message generated by Copilot) * pr comments --- .../aiCustomizationManagement.contribution.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/vs/workbench/contrib/chat/browser/aiCustomization/aiCustomizationManagement.contribution.ts b/src/vs/workbench/contrib/chat/browser/aiCustomization/aiCustomizationManagement.contribution.ts index 28e6a71a85c..f684f194c73 100644 --- a/src/vs/workbench/contrib/chat/browser/aiCustomization/aiCustomizationManagement.contribution.ts +++ b/src/vs/workbench/contrib/chat/browser/aiCustomization/aiCustomizationManagement.contribution.ts @@ -44,6 +44,8 @@ import { Schemas } from '../../../../../base/common/network.js'; import { isWindows, isMacintosh } from '../../../../../base/common/platform.js'; import { ITelemetryService } from '../../../../../platform/telemetry/common/telemetry.js'; import { IClipboardService } from '../../../../../platform/clipboard/common/clipboardService.js'; +import { getCodeEditor } from '../../../../../editor/browser/editorBrowser.js'; +import { MarkdownString } from '../../../../../base/common/htmlContent.js'; import { IAgentPluginService } from '../../common/plugins/agentPluginService.js'; //#region Telemetry @@ -164,9 +166,19 @@ registerAction2(class extends Action2 { } async run(accessor: ServicesAccessor, context: AICustomizationContext): Promise { const editorService = accessor.get(IEditorService); - await editorService.openEditor({ + const storage = extractStorage(context); + + const editorPane = await editorService.openEditor({ resource: extractURI(context) }); + + const codeEditor = getCodeEditor(editorPane?.getControl()); + if (codeEditor && (storage === PromptsStorage.extension || storage === PromptsStorage.plugin)) { + codeEditor.updateOptions({ + readOnly: true, + readOnlyMessage: new MarkdownString(localize('readonlyPluginFile', "This file is provided by a plugin or extension and cannot be edited.")), + }); + } } });