Don't use experimental decorators in extensions

Seeing if we can compile our extensions using TS native which doesn't support these. The usage is so low that I think we can just remove them
This commit is contained in:
Matt Bierner
2025-08-06 13:24:19 -07:00
parent 0dce61c27f
commit d8c9852fe9
14 changed files with 24 additions and 79 deletions

View File

@@ -12,13 +12,13 @@ import type * as Proto from '../tsServer/protocol/protocol';
import * as typeConverters from '../typeConverters';
import { ClientCapability, ITypeScriptServiceClient } from '../typescriptService';
import { nulToken } from '../utils/cancellation';
import { memoize } from '../utils/memoize';
import { Lazy } from '../utils/lazy';
import { equals } from '../utils/objects';
import { DiagnosticsManager } from './diagnostics';
import FileConfigurationManager from './fileConfigurationManager';
import { applyCodeActionCommands, getEditForCodeAction } from './util/codeAction';
import { CompositeCommand, EditorChatFollowUp, EditorChatFollowUp_Args, Expand } from './util/copilot';
import { conditionalRegistration, requireSomeCapability } from './util/dependentRegistration';
import { Expand, EditorChatFollowUp_Args, CompositeCommand, EditorChatFollowUp } from './util/copilot';
type ApplyCodeActionCommand_args = {
readonly document: vscode.TextDocument;
@@ -199,17 +199,16 @@ class SupportedCodeActionProvider {
) { }
public async getFixableDiagnosticsForContext(diagnostics: readonly vscode.Diagnostic[]): Promise<DiagnosticsSet> {
const fixableCodes = await this.fixableDiagnosticCodes;
const fixableCodes = await this.fixableDiagnosticCodes.value;
return DiagnosticsSet.from(
diagnostics.filter(diagnostic => typeof diagnostic.code !== 'undefined' && fixableCodes.has(diagnostic.code + '')));
}
@memoize
private get fixableDiagnosticCodes(): Thenable<Set<string>> {
private readonly fixableDiagnosticCodes = new Lazy<Thenable<Set<string>>>(() => {
return this.client.execute('getSupportedCodeFixes', null, nulToken)
.then(response => response.type === 'response' ? response.body || [] : [])
.then(codes => new Set(codes));
}
});
}
class TypeScriptQuickFixProvider implements vscode.CodeActionProvider<VsCodeCodeAction> {

View File

@@ -4,25 +4,24 @@
*--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode';
import { memoize } from '../utils/memoize';
import { Lazy } from '../utils/lazy';
export class Logger {
@memoize
private get output(): vscode.LogOutputChannel {
private readonly output = new Lazy<vscode.LogOutputChannel>(() => {
return vscode.window.createOutputChannel('TypeScript', { log: true });
}
});
public get logLevel(): vscode.LogLevel {
return this.output.logLevel;
return this.output.value.logLevel;
}
public info(message: string, ...args: any[]): void {
this.output.info(message, ...args);
this.output.value.info(message, ...args);
}
public trace(message: string, ...args: any[]): void {
this.output.trace(message, ...args);
this.output.value.trace(message, ...args);
}
public error(message: string, data?: any): void {
@@ -30,6 +29,6 @@ export class Logger {
if (data && data.message === 'No content available.') {
return;
}
this.output.error(message, ...(data ? [data] : []));
this.output.value.error(message, ...(data ? [data] : []));
}
}

View File

@@ -6,8 +6,8 @@
import * as fs from 'fs';
import * as path from 'path';
import * as vscode from 'vscode';
import { memoize } from '../utils/memoize';
import { ILogDirectoryProvider } from './logDirectoryProvider';
import { Lazy } from '../utils/lazy';
export class NodeLogDirectoryProvider implements ILogDirectoryProvider {
public constructor(
@@ -15,7 +15,7 @@ export class NodeLogDirectoryProvider implements ILogDirectoryProvider {
) { }
public getNewLogDirectory(): vscode.Uri | undefined {
const root = this.logDirectory();
const root = this.logDirectory.value;
if (root) {
try {
return vscode.Uri.file(fs.mkdtempSync(path.join(root, `tsserver-log-`)));
@@ -26,8 +26,7 @@ export class NodeLogDirectoryProvider implements ILogDirectoryProvider {
return undefined;
}
@memoize
private logDirectory(): string | undefined {
private readonly logDirectory = new Lazy<string | undefined>(() => {
try {
const path = this.context.logPath;
if (!fs.existsSync(path)) {
@@ -37,5 +36,5 @@ export class NodeLogDirectoryProvider implements ILogDirectoryProvider {
} catch {
return undefined;
}
}
});
}

View File

@@ -10,7 +10,6 @@ import { TelemetryReporter } from '../logging/telemetry';
import Tracer from '../logging/tracer';
import { OngoingRequestCancellerFactory } from '../tsServer/cancellation';
import { ClientCapabilities, ClientCapability, ServerType } from '../typescriptService';
import { memoize } from '../utils/memoize';
import { isWeb, isWebAndHasSharedArrayBuffers } from '../utils/platform';
import { API } from './api';
import { ILogDirectoryProvider } from './logDirectoryProvider';
@@ -20,6 +19,7 @@ import { GetErrRoutingTsServer, ITypeScriptServer, SingleTsServer, SyntaxRouting
import { TypeScriptVersionManager } from './versionManager';
import { ITypeScriptVersionProvider, TypeScriptVersion } from './versionProvider';
import { NodeVersionManager } from './nodeManager';
import { Lazy } from '../utils/lazy';
const enum CompositeServerType {
/** Run a single server that handles all commands */
@@ -37,10 +37,9 @@ const enum CompositeServerType {
export class TypeScriptServerSpawner {
@memoize
public static get tsServerLogOutputChannel(): vscode.OutputChannel {
public static readonly tsServerLogOutputChannel = new Lazy<vscode.OutputChannel>(() => {
return vscode.window.createOutputChannel(vscode.l10n.t("TypeScript Server Log"));
}
});
public constructor(
private readonly _versionProvider: ITypeScriptVersionProvider,
@@ -223,7 +222,7 @@ export class TypeScriptServerSpawner {
if (TypeScriptServerSpawner.isLoggingEnabled(configuration)) {
if (isWeb()) {
args.push('--logVerbosity', TsServerLogLevel.toString(configuration.tsServerLogLevel));
tsServerLog = { type: 'output', output: TypeScriptServerSpawner.tsServerLogOutputChannel };
tsServerLog = { type: 'output', output: TypeScriptServerSpawner.tsServerLogOutputChannel.value };
} else {
const logDir = this._logDirectoryProvider.getNewLogDirectory();
if (logDir) {

View File

@@ -1,34 +0,0 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
export function memoize(_target: any, key: string, descriptor: any) {
let fnKey: string | undefined;
let fn: Function | undefined;
if (typeof descriptor.value === 'function') {
fnKey = 'value';
fn = descriptor.value;
} else if (typeof descriptor.get === 'function') {
fnKey = 'get';
fn = descriptor.get;
} else {
throw new Error('not supported');
}
const memoizeKey = `$memoize$${key}`;
descriptor[fnKey] = function (...args: any[]) {
if (!this.hasOwnProperty(memoizeKey)) {
Object.defineProperty(this, memoizeKey, {
configurable: false,
enumerable: false,
writable: false,
value: fn!.apply(this, args)
});
}
return this[memoizeKey];
};
}