From 6c1efa9aaf1d275d5f110123511d638e422c122d Mon Sep 17 00:00:00 2001 From: Peng Lyu Date: Sat, 21 Feb 2026 16:13:34 -0800 Subject: [PATCH] improve handling of titleTemplate for proposed API (#296760) --- src/vs/workbench/api/common/extHost.api.impl.ts | 12 +++++++----- .../api/common/extHostTerminalService.ts | 15 +++++++++++---- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/vs/workbench/api/common/extHost.api.impl.ts b/src/vs/workbench/api/common/extHost.api.impl.ts index 1ed78327aa5a9..a8a6733b681f5 100644 --- a/src/vs/workbench/api/common/extHost.api.impl.ts +++ b/src/vs/workbench/api/common/extHost.api.impl.ts @@ -941,13 +941,15 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I }, createTerminal(nameOrOptions?: vscode.TerminalOptions | vscode.ExtensionTerminalOptions | string, shellPath?: string, shellArgs?: readonly string[] | string): vscode.Terminal { if (typeof nameOrOptions === 'object') { - if ('titleTemplate' in nameOrOptions && nameOrOptions.titleTemplate !== undefined) { - checkProposedApiEnabled(extension, 'terminalTitle'); + let options = nameOrOptions; + if (!isProposedApiEnabled(extension, 'terminalTitle') && 'titleTemplate' in nameOrOptions && nameOrOptions.titleTemplate !== undefined) { + console.error(`[${extension.identifier.value}] \`titleTemplate\` was provided to window.createTerminal but is ignored because the \`terminalTitle\` proposed API is not enabled.`); + options = { ...nameOrOptions, titleTemplate: undefined }; } - if ('pty' in nameOrOptions) { - return extHostTerminalService.createExtensionTerminal(nameOrOptions); + if ('pty' in options) { + return extHostTerminalService.createExtensionTerminal(options); } - return extHostTerminalService.createTerminalFromOptions(nameOrOptions); + return extHostTerminalService.createTerminalFromOptions(options); } return extHostTerminalService.createTerminal(nameOrOptions, shellPath, shellArgs); }, diff --git a/src/vs/workbench/api/common/extHostTerminalService.ts b/src/vs/workbench/api/common/extHostTerminalService.ts index 52becdb964960..b50811f77158f 100644 --- a/src/vs/workbench/api/common/extHostTerminalService.ts +++ b/src/vs/workbench/api/common/extHostTerminalService.ts @@ -29,7 +29,7 @@ import { MarshalledId } from '../../../base/common/marshallingIds.js'; import { ISerializedTerminalInstanceContext } from '../../contrib/terminal/common/terminal.js'; import { isWindows } from '../../../base/common/platform.js'; import { hasKey } from '../../../base/common/types.js'; -import { checkProposedApiEnabled } from '../../services/extensions/common/extensions.js'; +import { isProposedApiEnabled } from '../../services/extensions/common/extensions.js'; export interface IExtHostTerminalService extends ExtHostTerminalServiceShape, IDisposable { @@ -862,11 +862,18 @@ export abstract class BaseExtHostTerminalService extends Disposable implements I throw new Error(`No terminal profile options provided for id "${id}"`); } - if (profile.options.titleTemplate !== undefined) { - checkProposedApiEnabled(profileProviderData.extension, 'terminalTitle'); + const hasTerminalTitleProposal = isProposedApiEnabled(profileProviderData.extension, 'terminalTitle'); + if (!hasTerminalTitleProposal && profile.options.titleTemplate !== undefined) { + console.error(`[${profileProviderData.extension.identifier.value}] \`titleTemplate\` returned from TerminalProfileProvider is ignored because the \`terminalTitle\` proposed API is not enabled.`); + profile = { options: { ...profile.options, titleTemplate: undefined } }; + } + // options.titleTemplate is not explicitly stripped here because the profileOptions + // assignment below only applies it when hasTerminalTitleProposal is true. + if (!hasTerminalTitleProposal && options.titleTemplate !== undefined) { + console.error(`[${profileProviderData.extension.identifier.value}] \`titleTemplate\` passed to createContributedTerminalProfile is ignored because the \`terminalTitle\` proposed API is not enabled.`); } - const profileOptions = options.titleTemplate && !profile.options.titleTemplate + const profileOptions = hasTerminalTitleProposal && options.titleTemplate && !profile.options.titleTemplate ? { ...profile.options, titleTemplate: options.titleTemplate } : profile.options;