Remove any from contrib/terminal|terminalContrib

Part of #274723
This commit is contained in:
Daniel Imms
2025-11-10 05:27:15 -08:00
parent 20e3473070
commit 1379c694f5
12 changed files with 43 additions and 49 deletions

View File

@@ -902,18 +902,7 @@ export default tseslint.config(
'src/vs/workbench/contrib/tasks/common/taskSystem.ts',
'src/vs/workbench/contrib/tasks/common/tasks.ts',
'src/vs/workbench/contrib/terminal/browser/remoteTerminalBackend.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/remote/remoteTerminalChannel.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/browser/testExplorerActions.ts',
'src/vs/workbench/contrib/testing/browser/testingExplorerView.ts',
'src/vs/workbench/contrib/testing/common/storedValue.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 { isMacintosh } from '../../../../base/common/platform.js';
import { TerminalLocation, TerminalLocationConfigValue } from '../../../../platform/terminal/common/terminal.js';
import { isString } from '../../../../base/common/types.js';
// #region TerminalConfigurationService
@@ -60,7 +61,7 @@ export class TerminalConfigurationService extends Disposable implements ITermina
this._onConfigChanged.fire();
}
private _normalizeFontWeight(input: any, defaultWeight: FontWeight): FontWeight {
private _normalizeFontWeight(input: FontWeight, defaultWeight: FontWeight): FontWeight {
if (input === 'normal' || input === 'bold') {
return input;
}
@@ -244,8 +245,8 @@ export class TerminalFontMetrics extends Disposable {
// #region Utils
function clampInt<T>(source: any, minimum: number, maximum: number, fallback: T): number | T {
let r = parseInt(source, 10);
function clampInt<T>(source: string | number, minimum: number, maximum: number, fallback: T): number | T {
let r = isString(source) ? parseInt(source, 10) : source;
if (isNaN(r)) {
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: 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
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 }) => {
switch (type) {
case ProcessPropertyType.Cwd:
this._cwd = value;
this._cwd = value as IProcessPropertyMap[ProcessPropertyType.Cwd];
this._labelComputer?.refreshLabel(this);
break;
case ProcessPropertyType.InitialCwd:
this._initialCwd = value;
this._initialCwd = value as IProcessPropertyMap[ProcessPropertyType.InitialCwd];
this._cwd = this._initialCwd;
this._setTitle(this.title, TitleEventSource.Config);
this._icon = this._shellLaunchConfig.attachPersistentProcess?.icon || this._shellLaunchConfig.icon;
this._onIconChanged.fire({ instance: this, userInitiated: false });
break;
case ProcessPropertyType.Title:
this._setTitle(value ?? '', TitleEventSource.Process);
this._setTitle(value as IProcessPropertyMap[ProcessPropertyType.Title] ?? '', TitleEventSource.Process);
break;
case ProcessPropertyType.OverrideDimensions:
this.setOverrideDimensions(value, true);
this.setOverrideDimensions(value as IProcessPropertyMap[ProcessPropertyType.OverrideDimensions], true);
break;
case ProcessPropertyType.ResolvedShellLaunchConfig:
this._setResolvedShellLaunchConfig(value);
this._setResolvedShellLaunchConfig(value as IProcessPropertyMap[ProcessPropertyType.ResolvedShellLaunchConfig]);
break;
case ProcessPropertyType.ShellType:
this.setShellType(value);
this.setShellType(value as IProcessPropertyMap[ProcessPropertyType.ShellType]);
break;
case ProcessPropertyType.HasChildProcesses:
this._onDidChangeHasChildProcesses.fire(value);
this._onDidChangeHasChildProcesses.fire(value as IProcessPropertyMap[ProcessPropertyType.HasChildProcesses]);
break;
case ProcessPropertyType.UsedShellIntegrationInjection:
this._usedShellIntegrationInjection = true;
break;
case ProcessPropertyType.ShellIntegrationInjectionFailureReason:
this._shellIntegrationInjectionInfo = value;
this._shellIntegrationInjectionInfo = value as IProcessPropertyMap[ProcessPropertyType.ShellIntegrationInjectionFailureReason];
break;
}
}));

View File

@@ -34,7 +34,7 @@ export class TerminalProcessExtHostProxy extends Disposable implements ITerminal
readonly onRequestInitialCwd: Event<void> = this._onRequestInitialCwd.event;
private readonly _onRequestCwd = this._register(new Emitter<void>());
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;
private readonly _onProcessExit = this._register(new Emitter<number | undefined>());
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 });
}
emitProcessProperty({ type, value }: IProcessProperty<any>): void {
emitProcessProperty({ type, value }: IProcessProperty): void {
switch (type) {
case ProcessPropertyType.Cwd:
this.emitCwd(value);
this.emitCwd(value as IProcessPropertyMap[ProcessPropertyType.Cwd]);
break;
case ProcessPropertyType.InitialCwd:
this.emitInitialCwd(value);
this.emitInitialCwd(value as IProcessPropertyMap[ProcessPropertyType.InitialCwd]);
break;
case ProcessPropertyType.Title:
this.emitTitle(value);
this.emitTitle(value as IProcessPropertyMap[ProcessPropertyType.Title]);
break;
case ProcessPropertyType.OverrideDimensions:
this.emitOverrideDimensions(value);
this.emitOverrideDimensions(value as IProcessPropertyMap[ProcessPropertyType.OverrideDimensions]);
break;
case ProcessPropertyType.ResolvedShellLaunchConfig:
this.emitResolvedShellLaunchConfig(value);
this.emitResolvedShellLaunchConfig(value as IProcessPropertyMap[ProcessPropertyType.ResolvedShellLaunchConfig]);
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
throw new Error('refreshProperty not implemented on extension host');
}
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;
private readonly _onProcessReplayComplete = this._register(new Emitter<void>());
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;
private readonly _onEnvironmentVariableInfoChange = this._register(new Emitter<IEnvironmentVariableInfo>());
readonly onEnvironmentVariableInfoChanged = this._onEnvironmentVariableInfoChange.event;

View File

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

View File

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

View File

@@ -741,11 +741,13 @@ export class XtermTerminal extends Disposable implements IXtermTerminal, IDetach
if (this.hasSelection() || (asHtml && command)) {
if (asHtml) {
const textAsHtml = await this.getSelectionAsHtml(command);
function listener(e: any) {
if (!e.clipboardData.types.includes('text/plain')) {
e.clipboardData.setData('text/plain', command?.getOutput() ?? '');
function listener(e: ClipboardEvent) {
if (e.clipboardData) {
if (!e.clipboardData.types.includes('text/plain')) {
e.clipboardData.setData('text/plain', command?.getOutput() ?? '');
}
e.clipboardData.setData('text/html', textAsHtml);
}
e.clipboardData.setData('text/html', textAsHtml);
e.preventDefault();
}
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;
protected readonly _onProcessReady = this._register(new Emitter<IProcessReadyEvent>());
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;
protected readonly _onProcessExit = this._register(new Emitter<number | undefined>());
readonly onProcessExit = this._onProcessExit.event;
@@ -68,18 +68,20 @@ export abstract class BasePty extends Disposable implements Partial<ITerminalChi
handleReady(e: IProcessReadyEvent) {
this._onProcessReady.fire(e);
}
handleDidChangeProperty({ type, value }: IProcessProperty<any>) {
handleDidChangeProperty({ type, value }: IProcessProperty) {
switch (type) {
case ProcessPropertyType.Cwd:
this._properties.cwd = value;
this._properties.cwd = value as IProcessPropertyMap[ProcessPropertyType.Cwd];
break;
case ProcessPropertyType.InitialCwd:
this._properties.initialCwd = value;
this._properties.initialCwd = value as IProcessPropertyMap[ProcessPropertyType.InitialCwd];
break;
case ProcessPropertyType.ResolvedShellLaunchConfig:
if (value.cwd && typeof value.cwd !== 'string') {
value.cwd = URI.revive(value.cwd);
case ProcessPropertyType.ResolvedShellLaunchConfig: {
const cast = value as IProcessPropertyMap[ProcessPropertyType.ResolvedShellLaunchConfig];
if (cast.cwd && typeof cast.cwd !== 'string') {
cast.cwd = URI.revive(cast.cwd);
}
}
}
this._onDidChangeProperty.fire({ type, value });
}

View File

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

View File

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