Merge pull request #276490 from microsoft/tyriar/274723_terminal_contrib

Remove any from contrib/terminal|terminalContrib
This commit is contained in:
Daniel Imms
2025-11-10 07:57:33 -08:00
committed by GitHub
13 changed files with 50 additions and 50 deletions

View File

@@ -835,17 +835,6 @@ export default tseslint.config(
'src/vs/workbench/contrib/tasks/common/taskConfiguration.ts', 'src/vs/workbench/contrib/tasks/common/taskConfiguration.ts',
'src/vs/workbench/contrib/tasks/common/taskSystem.ts', 'src/vs/workbench/contrib/tasks/common/taskSystem.ts',
'src/vs/workbench/contrib/tasks/common/tasks.ts', 'src/vs/workbench/contrib/tasks/common/tasks.ts',
'src/vs/workbench/contrib/terminal/browser/terminalConfigurationService.ts',
'src/vs/workbench/contrib/terminal/browser/terminalExtensions.ts',
'src/vs/workbench/contrib/terminal/browser/terminalProcessExtHostProxy.ts',
'src/vs/workbench/contrib/terminal/browser/terminalProcessManager.ts',
'src/vs/workbench/contrib/terminal/browser/terminalProfileQuickpick.ts',
'src/vs/workbench/contrib/terminal/browser/terminalProfileService.ts',
'src/vs/workbench/contrib/terminal/browser/xterm/xtermTerminal.ts',
'src/vs/workbench/contrib/terminal/common/basePty.ts',
'src/vs/workbench/contrib/terminal/common/terminal.ts',
'src/vs/workbench/contrib/terminalContrib/links/browser/links.ts',
'src/vs/workbench/contrib/terminalContrib/suggest/browser/terminalSuggestAddon.ts',
'src/vs/workbench/contrib/testing/common/storedValue.ts', 'src/vs/workbench/contrib/testing/common/storedValue.ts',
'src/vs/workbench/contrib/testing/common/testItemCollection.ts', 'src/vs/workbench/contrib/testing/common/testItemCollection.ts',
'src/vs/workbench/contrib/testing/test/browser/testObjectTree.ts', 'src/vs/workbench/contrib/testing/test/browser/testObjectTree.ts',

View File

@@ -13,6 +13,7 @@ import type { IXtermCore } from './xterm-private.js';
import { DEFAULT_BOLD_FONT_WEIGHT, DEFAULT_FONT_WEIGHT, DEFAULT_LETTER_SPACING, DEFAULT_LINE_HEIGHT, FontWeight, ITerminalConfiguration, MAXIMUM_FONT_WEIGHT, MINIMUM_FONT_WEIGHT, MINIMUM_LETTER_SPACING, TERMINAL_CONFIG_SECTION, type ITerminalFont } from '../common/terminal.js'; import { DEFAULT_BOLD_FONT_WEIGHT, DEFAULT_FONT_WEIGHT, DEFAULT_LETTER_SPACING, DEFAULT_LINE_HEIGHT, FontWeight, ITerminalConfiguration, MAXIMUM_FONT_WEIGHT, MINIMUM_FONT_WEIGHT, MINIMUM_LETTER_SPACING, TERMINAL_CONFIG_SECTION, type ITerminalFont } from '../common/terminal.js';
import { isMacintosh } from '../../../../base/common/platform.js'; import { isMacintosh } from '../../../../base/common/platform.js';
import { TerminalLocation, TerminalLocationConfigValue } from '../../../../platform/terminal/common/terminal.js'; import { TerminalLocation, TerminalLocationConfigValue } from '../../../../platform/terminal/common/terminal.js';
import { isString } from '../../../../base/common/types.js';
// #region TerminalConfigurationService // #region TerminalConfigurationService
@@ -60,7 +61,7 @@ export class TerminalConfigurationService extends Disposable implements ITermina
this._onConfigChanged.fire(); this._onConfigChanged.fire();
} }
private _normalizeFontWeight(input: any, defaultWeight: FontWeight): FontWeight { private _normalizeFontWeight(input: FontWeight, defaultWeight: FontWeight): FontWeight {
if (input === 'normal' || input === 'bold') { if (input === 'normal' || input === 'bold') {
return input; return input;
} }
@@ -244,8 +245,11 @@ export class TerminalFontMetrics extends Disposable {
// #region Utils // #region Utils
function clampInt<T>(source: any, minimum: number, maximum: number, fallback: T): number | T { function clampInt<T>(source: string | number, minimum: number, maximum: number, fallback: T): number | T {
let r = parseInt(source, 10); if (source === null || source === undefined) {
return fallback;
}
let r = isString(source) ? parseInt(source, 10) : source;
if (isNaN(r)) { if (isNaN(r)) {
return fallback; return fallback;
} }

View File

@@ -41,7 +41,7 @@ export type ITerminalContributionDescription = { readonly id: string } & (
*/ */
export function registerTerminalContribution<Services extends BrandedService[]>(id: string, ctor: { new(ctx: ITerminalContributionContext, ...services: Services): ITerminalContribution }, canRunInDetachedTerminals?: false): void; export function registerTerminalContribution<Services extends BrandedService[]>(id: string, ctor: { new(ctx: ITerminalContributionContext, ...services: Services): ITerminalContribution }, canRunInDetachedTerminals?: false): void;
export function registerTerminalContribution<Services extends BrandedService[]>(id: string, ctor: { new(ctx: IDetachedCompatibleTerminalContributionContext, ...services: Services): ITerminalContribution }, canRunInDetachedTerminals: true): void; export function registerTerminalContribution<Services extends BrandedService[]>(id: string, ctor: { new(ctx: IDetachedCompatibleTerminalContributionContext, ...services: Services): ITerminalContribution }, canRunInDetachedTerminals: true): void;
export function registerTerminalContribution<Services extends BrandedService[]>(id: string, ctor: { new(ctx: any, ...services: Services): ITerminalContribution }, canRunInDetachedTerminals: boolean = false): void { export function registerTerminalContribution(id: string, ctor: TerminalContributionCtor | DetachedCompatibleTerminalContributionCtor, canRunInDetachedTerminals: boolean = false): void {
// eslint-disable-next-line local/code-no-dangerous-type-assertions // eslint-disable-next-line local/code-no-dangerous-type-assertions
TerminalContributionRegistry.INSTANCE.registerTerminalContribution({ id, ctor, canRunInDetachedTerminals } as ITerminalContributionDescription); TerminalContributionRegistry.INSTANCE.registerTerminalContribution({ id, ctor, canRunInDetachedTerminals } as ITerminalContributionDescription);
} }

View File

@@ -1468,36 +1468,36 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
this._register(processManager.onDidChangeProperty(({ type, value }) => { this._register(processManager.onDidChangeProperty(({ type, value }) => {
switch (type) { switch (type) {
case ProcessPropertyType.Cwd: case ProcessPropertyType.Cwd:
this._cwd = value; this._cwd = value as IProcessPropertyMap[ProcessPropertyType.Cwd];
this._labelComputer?.refreshLabel(this); this._labelComputer?.refreshLabel(this);
break; break;
case ProcessPropertyType.InitialCwd: case ProcessPropertyType.InitialCwd:
this._initialCwd = value; this._initialCwd = value as IProcessPropertyMap[ProcessPropertyType.InitialCwd];
this._cwd = this._initialCwd; this._cwd = this._initialCwd;
this._setTitle(this.title, TitleEventSource.Config); this._setTitle(this.title, TitleEventSource.Config);
this._icon = this._shellLaunchConfig.attachPersistentProcess?.icon || this._shellLaunchConfig.icon; this._icon = this._shellLaunchConfig.attachPersistentProcess?.icon || this._shellLaunchConfig.icon;
this._onIconChanged.fire({ instance: this, userInitiated: false }); this._onIconChanged.fire({ instance: this, userInitiated: false });
break; break;
case ProcessPropertyType.Title: case ProcessPropertyType.Title:
this._setTitle(value ?? '', TitleEventSource.Process); this._setTitle(value as IProcessPropertyMap[ProcessPropertyType.Title] ?? '', TitleEventSource.Process);
break; break;
case ProcessPropertyType.OverrideDimensions: case ProcessPropertyType.OverrideDimensions:
this.setOverrideDimensions(value, true); this.setOverrideDimensions(value as IProcessPropertyMap[ProcessPropertyType.OverrideDimensions], true);
break; break;
case ProcessPropertyType.ResolvedShellLaunchConfig: case ProcessPropertyType.ResolvedShellLaunchConfig:
this._setResolvedShellLaunchConfig(value); this._setResolvedShellLaunchConfig(value as IProcessPropertyMap[ProcessPropertyType.ResolvedShellLaunchConfig]);
break; break;
case ProcessPropertyType.ShellType: case ProcessPropertyType.ShellType:
this.setShellType(value); this.setShellType(value as IProcessPropertyMap[ProcessPropertyType.ShellType]);
break; break;
case ProcessPropertyType.HasChildProcesses: case ProcessPropertyType.HasChildProcesses:
this._onDidChangeHasChildProcesses.fire(value); this._onDidChangeHasChildProcesses.fire(value as IProcessPropertyMap[ProcessPropertyType.HasChildProcesses]);
break; break;
case ProcessPropertyType.UsedShellIntegrationInjection: case ProcessPropertyType.UsedShellIntegrationInjection:
this._usedShellIntegrationInjection = true; this._usedShellIntegrationInjection = true;
break; break;
case ProcessPropertyType.ShellIntegrationInjectionFailureReason: case ProcessPropertyType.ShellIntegrationInjectionFailureReason:
this._shellIntegrationInjectionInfo = value; this._shellIntegrationInjectionInfo = value as IProcessPropertyMap[ProcessPropertyType.ShellIntegrationInjectionFailureReason];
break; break;
} }
})); }));

View File

@@ -34,7 +34,7 @@ export class TerminalProcessExtHostProxy extends Disposable implements ITerminal
readonly onRequestInitialCwd: Event<void> = this._onRequestInitialCwd.event; readonly onRequestInitialCwd: Event<void> = this._onRequestInitialCwd.event;
private readonly _onRequestCwd = this._register(new Emitter<void>()); private readonly _onRequestCwd = this._register(new Emitter<void>());
readonly onRequestCwd: Event<void> = this._onRequestCwd.event; readonly onRequestCwd: Event<void> = this._onRequestCwd.event;
private readonly _onDidChangeProperty = this._register(new Emitter<IProcessProperty<any>>()); private readonly _onDidChangeProperty = this._register(new Emitter<IProcessProperty>());
readonly onDidChangeProperty = this._onDidChangeProperty.event; readonly onDidChangeProperty = this._onDidChangeProperty.event;
private readonly _onProcessExit = this._register(new Emitter<number | undefined>()); private readonly _onProcessExit = this._register(new Emitter<number | undefined>());
readonly onProcessExit: Event<number | undefined> = this._onProcessExit.event; readonly onProcessExit: Event<number | undefined> = this._onProcessExit.event;
@@ -63,22 +63,22 @@ export class TerminalProcessExtHostProxy extends Disposable implements ITerminal
this._onProcessReady.fire({ pid, cwd, windowsPty: undefined }); this._onProcessReady.fire({ pid, cwd, windowsPty: undefined });
} }
emitProcessProperty({ type, value }: IProcessProperty<any>): void { emitProcessProperty({ type, value }: IProcessProperty): void {
switch (type) { switch (type) {
case ProcessPropertyType.Cwd: case ProcessPropertyType.Cwd:
this.emitCwd(value); this.emitCwd(value as IProcessPropertyMap[ProcessPropertyType.Cwd]);
break; break;
case ProcessPropertyType.InitialCwd: case ProcessPropertyType.InitialCwd:
this.emitInitialCwd(value); this.emitInitialCwd(value as IProcessPropertyMap[ProcessPropertyType.InitialCwd]);
break; break;
case ProcessPropertyType.Title: case ProcessPropertyType.Title:
this.emitTitle(value); this.emitTitle(value as IProcessPropertyMap[ProcessPropertyType.Title]);
break; break;
case ProcessPropertyType.OverrideDimensions: case ProcessPropertyType.OverrideDimensions:
this.emitOverrideDimensions(value); this.emitOverrideDimensions(value as IProcessPropertyMap[ProcessPropertyType.OverrideDimensions]);
break; break;
case ProcessPropertyType.ResolvedShellLaunchConfig: case ProcessPropertyType.ResolvedShellLaunchConfig:
this.emitResolvedShellLaunchConfig(value); this.emitResolvedShellLaunchConfig(value as IProcessPropertyMap[ProcessPropertyType.ResolvedShellLaunchConfig]);
break; break;
} }
} }
@@ -163,8 +163,9 @@ export class TerminalProcessExtHostProxy extends Disposable implements ITerminal
}); });
} }
async refreshProperty<T extends ProcessPropertyType>(type: T): Promise<any> { async refreshProperty<T extends ProcessPropertyType>(type: T): Promise<IProcessPropertyMap[T]> {
// throws if called in extHostTerminalService // throws if called in extHostTerminalService
throw new Error('refreshProperty not implemented on extension host');
} }
async updateProperty<T extends ProcessPropertyType>(type: T, value: IProcessPropertyMap[T]): Promise<void> { async updateProperty<T extends ProcessPropertyType>(type: T, value: IProcessPropertyMap[T]): Promise<void> {

View File

@@ -117,7 +117,7 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce
readonly onProcessData = this._onProcessData.event; readonly onProcessData = this._onProcessData.event;
private readonly _onProcessReplayComplete = this._register(new Emitter<void>()); private readonly _onProcessReplayComplete = this._register(new Emitter<void>());
readonly onProcessReplayComplete = this._onProcessReplayComplete.event; readonly onProcessReplayComplete = this._onProcessReplayComplete.event;
private readonly _onDidChangeProperty = this._register(new Emitter<IProcessProperty<any>>()); private readonly _onDidChangeProperty = this._register(new Emitter<IProcessProperty>());
readonly onDidChangeProperty = this._onDidChangeProperty.event; readonly onDidChangeProperty = this._onDidChangeProperty.event;
private readonly _onEnvironmentVariableInfoChange = this._register(new Emitter<IEnvironmentVariableInfo>()); private readonly _onEnvironmentVariableInfoChange = this._register(new Emitter<IEnvironmentVariableInfo>());
readonly onEnvironmentVariableInfoChanged = this._onEnvironmentVariableInfoChange.event; readonly onEnvironmentVariableInfoChanged = this._onEnvironmentVariableInfoChange.event;

View File

@@ -112,7 +112,7 @@ export class TerminalProfileQuickpick {
if (hasKey(context.item.profile, { id: true })) { if (hasKey(context.item.profile, { id: true })) {
return; return;
} }
const configProfiles: { [key: string]: any } = this._configurationService.getValue(TerminalSettingPrefix.Profiles + platformKey); const configProfiles: { [key: string]: ITerminalExecutable | null | undefined } = this._configurationService.getValue(TerminalSettingPrefix.Profiles + platformKey);
const existingProfiles = !!configProfiles ? Object.keys(configProfiles) : []; const existingProfiles = !!configProfiles ? Object.keys(configProfiles) : [];
const name = await this._quickInputService.input({ const name = await this._quickInputService.input({
prompt: nls.localize('enterTerminalProfileName', "Enter terminal profile name"), prompt: nls.localize('enterTerminalProfileName', "Enter terminal profile name"),
@@ -127,7 +127,7 @@ export class TerminalProfileQuickpick {
if (!name) { if (!name) {
return; return;
} }
const newConfigValue: { [key: string]: ITerminalExecutable } = { const newConfigValue: { [key: string]: ITerminalExecutable | null | undefined } = {
...configProfiles, ...configProfiles,
[name]: this._createNewProfileConfig(context.item.profile) [name]: this._createNewProfileConfig(context.item.profile)
}; };

View File

@@ -169,7 +169,7 @@ export class TerminalProfileService extends Disposable implements ITerminalProfi
private async _updateContributedProfiles(): Promise<boolean> { private async _updateContributedProfiles(): Promise<boolean> {
const platformKey = await this.getPlatformKey(); const platformKey = await this.getPlatformKey();
const excludedContributedProfiles: string[] = []; const excludedContributedProfiles: string[] = [];
const configProfiles: { [key: string]: any } = this._configurationService.getValue(TerminalSettingPrefix.Profiles + platformKey); const configProfiles: { [key: string]: ITerminalExecutable | null | undefined } = this._configurationService.getValue(TerminalSettingPrefix.Profiles + platformKey);
for (const [profileName, value] of Object.entries(configProfiles)) { for (const [profileName, value] of Object.entries(configProfiles)) {
if (value === null) { if (value === null) {
excludedContributedProfiles.push(profileName); excludedContributedProfiles.push(profileName);

View File

@@ -741,11 +741,13 @@ export class XtermTerminal extends Disposable implements IXtermTerminal, IDetach
if (this.hasSelection() || (asHtml && command)) { if (this.hasSelection() || (asHtml && command)) {
if (asHtml) { if (asHtml) {
const textAsHtml = await this.getSelectionAsHtml(command); const textAsHtml = await this.getSelectionAsHtml(command);
function listener(e: any) { function listener(e: ClipboardEvent) {
if (e.clipboardData) {
if (!e.clipboardData.types.includes('text/plain')) { if (!e.clipboardData.types.includes('text/plain')) {
e.clipboardData.setData('text/plain', command?.getOutput() ?? ''); e.clipboardData.setData('text/plain', command?.getOutput() ?? '');
} }
e.clipboardData.setData('text/html', textAsHtml); e.clipboardData.setData('text/html', textAsHtml);
}
e.preventDefault(); e.preventDefault();
} }
const doc = dom.getDocument(this.raw.element); const doc = dom.getDocument(this.raw.element);

View File

@@ -37,7 +37,7 @@ export abstract class BasePty extends Disposable implements Partial<ITerminalChi
readonly onProcessReplayComplete = this._onProcessReplayComplete.event; readonly onProcessReplayComplete = this._onProcessReplayComplete.event;
protected readonly _onProcessReady = this._register(new Emitter<IProcessReadyEvent>()); protected readonly _onProcessReady = this._register(new Emitter<IProcessReadyEvent>());
readonly onProcessReady = this._onProcessReady.event; readonly onProcessReady = this._onProcessReady.event;
protected readonly _onDidChangeProperty = this._register(new Emitter<IProcessProperty<any>>()); protected readonly _onDidChangeProperty = this._register(new Emitter<IProcessProperty>());
readonly onDidChangeProperty = this._onDidChangeProperty.event; readonly onDidChangeProperty = this._onDidChangeProperty.event;
protected readonly _onProcessExit = this._register(new Emitter<number | undefined>()); protected readonly _onProcessExit = this._register(new Emitter<number | undefined>());
readonly onProcessExit = this._onProcessExit.event; readonly onProcessExit = this._onProcessExit.event;
@@ -68,17 +68,20 @@ export abstract class BasePty extends Disposable implements Partial<ITerminalChi
handleReady(e: IProcessReadyEvent) { handleReady(e: IProcessReadyEvent) {
this._onProcessReady.fire(e); this._onProcessReady.fire(e);
} }
handleDidChangeProperty({ type, value }: IProcessProperty<any>) { handleDidChangeProperty({ type, value }: IProcessProperty) {
switch (type) { switch (type) {
case ProcessPropertyType.Cwd: case ProcessPropertyType.Cwd:
this._properties.cwd = value; this._properties.cwd = value as IProcessPropertyMap[ProcessPropertyType.Cwd];
break; break;
case ProcessPropertyType.InitialCwd: case ProcessPropertyType.InitialCwd:
this._properties.initialCwd = value; this._properties.initialCwd = value as IProcessPropertyMap[ProcessPropertyType.InitialCwd];
break;
case ProcessPropertyType.ResolvedShellLaunchConfig: {
const cast = value as IProcessPropertyMap[ProcessPropertyType.ResolvedShellLaunchConfig];
if (cast.cwd && typeof cast.cwd !== 'string') {
cast.cwd = URI.revive(cast.cwd);
}
break; break;
case ProcessPropertyType.ResolvedShellLaunchConfig:
if (value.cwd && typeof value.cwd !== 'string') {
value.cwd = URI.revive(value.cwd);
} }
} }
this._onDidChangeProperty.fire({ type, value }); this._onDidChangeProperty.fire({ type, value });

View File

@@ -288,7 +288,7 @@ export interface ITerminalProcessManager extends IDisposable, ITerminalProcessIn
readonly onProcessData: Event<IProcessDataEvent>; readonly onProcessData: Event<IProcessDataEvent>;
readonly onProcessReplayComplete: Event<void>; readonly onProcessReplayComplete: Event<void>;
readonly onEnvironmentVariableInfoChanged: Event<IEnvironmentVariableInfo>; readonly onEnvironmentVariableInfoChanged: Event<IEnvironmentVariableInfo>;
readonly onDidChangeProperty: Event<IProcessProperty<any>>; readonly onDidChangeProperty: Event<IProcessProperty>;
readonly onProcessExit: Event<number | undefined>; readonly onProcessExit: Event<number | undefined>;
readonly onRestoreCommands: Event<ISerializedCommandDetectionCapability>; readonly onRestoreCommands: Event<ISerializedCommandDetectionCapability>;
@@ -336,7 +336,7 @@ export interface ITerminalProcessExtHostProxy extends IDisposable {
readonly instanceId: number; readonly instanceId: number;
emitData(data: string): void; emitData(data: string): void;
emitProcessProperty(property: IProcessProperty<any>): void; emitProcessProperty(property: IProcessProperty): void;
emitReady(pid: number, cwd: string, windowsPty: IProcessReadyWindowsPty | undefined): void; emitReady(pid: number, cwd: string, windowsPty: IProcessReadyWindowsPty | undefined): void;
emitExit(exitCode: number | undefined): void; emitExit(exitCode: number | undefined): void;

View File

@@ -164,4 +164,6 @@ export interface IResolvedValidLink {
isDirectory: boolean; isDirectory: boolean;
} }
// Suppress as the any type is being removed anyway
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type OmitFirstArg<F> = F extends (x: any, ...args: infer P) => infer R ? (...args: P) => R : never; export type OmitFirstArg<F> = F extends (x: any, ...args: infer P) => infer R ? (...args: P) => R : never;

View File

@@ -786,7 +786,6 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest
private _ensureSuggestWidget(terminal: Terminal): SimpleSuggestWidget<TerminalCompletionModel, TerminalCompletionItem> { private _ensureSuggestWidget(terminal: Terminal): SimpleSuggestWidget<TerminalCompletionModel, TerminalCompletionItem> {
if (!this._suggestWidget) { if (!this._suggestWidget) {
// eslint-disable-next-line local/code-no-any-casts
this._suggestWidget = this._register(this._instantiationService.createInstance( this._suggestWidget = this._register(this._instantiationService.createInstance(
SimpleSuggestWidget, SimpleSuggestWidget,
this._container!, this._container!,
@@ -799,7 +798,7 @@ export class SuggestAddon extends Disposable implements ITerminalAddon, ISuggest
this._getFontInfo.bind(this), this._getFontInfo.bind(this),
this._onDidFontConfigurationChange.event.bind(this), this._onDidFontConfigurationChange.event.bind(this),
this._getAdvancedExplainModeDetails.bind(this) this._getAdvancedExplainModeDetails.bind(this)
)) as any as SimpleSuggestWidget<TerminalCompletionModel, TerminalCompletionItem>; )) as unknown as SimpleSuggestWidget<TerminalCompletionModel, TerminalCompletionItem>;
this._register(this._suggestWidget.onDidSelect(async e => this.acceptSelectedSuggestion(e))); this._register(this._suggestWidget.onDidSelect(async e => this.acceptSelectedSuggestion(e)));
this._register(this._suggestWidget.onDidHide(() => this._terminalSuggestWidgetVisibleContextKey.reset())); this._register(this._suggestWidget.onDidHide(() => this._terminalSuggestWidgetVisibleContextKey.reset()));
this._register(this._suggestWidget.onDidShow(() => this._terminalSuggestWidgetVisibleContextKey.set(true))); this._register(this._suggestWidget.onDidShow(() => this._terminalSuggestWidgetVisibleContextKey.set(true)));