Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline simple methods #236299

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Schemes } from './configuration/schemes';
import { IExperimentationTelemetryReporter } from './experimentTelemetryReporter';
import { DiagnosticKind, DiagnosticsManager } from './languageFeatures/diagnostics';
import { Logger } from './logging/logger';
import { TelemetryProperties, TelemetryReporter, VSCodeTelemetryReporter } from './logging/telemetry';
import { TelemetryReporter, VSCodeTelemetryReporter } from './logging/telemetry';
import Tracer from './logging/tracer';
import { ProjectType, inferredProjectCompilerOptions } from './tsconfig';
import { API } from './tsServer/api';
Expand Down Expand Up @@ -319,7 +319,7 @@ export default class TypeScriptServiceClient extends Disposable implements IType

public restartTsServer(fromUserAction = false): void {
if (this.serverState.type === ServerState.Type.Running) {
this.info('Killing TS Server');
this.logger.info('Killing TS Server');
this.isRestarting = true;
this.serverState.server.kill();
}
Expand Down Expand Up @@ -372,18 +372,6 @@ export default class TypeScriptServiceClient extends Disposable implements IType
return this._onReady!.promise.then(f);
}

private info(message: string, ...data: any[]): void {
this.logger.info(message, ...data);
}

private error(message: string, ...data: any[]): void {
this.logger.error(message, ...data);
}

private logTelemetry(eventName: string, properties?: TelemetryProperties) {
this.telemetryReporter.logTelemetry(eventName, properties);
}

public ensureServiceStarted() {
if (this.serverState.type !== ServerState.Type.Running) {
this.startService();
Expand All @@ -392,15 +380,15 @@ export default class TypeScriptServiceClient extends Disposable implements IType

private token: number = 0;
private startService(resendModels: boolean = false): ServerState.State {
this.info(`Starting TS Server`);
this.logger.info(`Starting TS Server`);

if (this.isDisposed) {
this.info(`Not starting server: disposed`);
this.logger.info(`Not starting server: disposed`);
return ServerState.None;
}

if (this.hasServerFatallyCrashedTooManyTimes) {
this.info(`Not starting server: too many crashes`);
this.logger.info(`Not starting server: too many crashes`);
return ServerState.None;
}

Expand All @@ -412,10 +400,10 @@ export default class TypeScriptServiceClient extends Disposable implements IType
version = this._versionManager.currentVersion;
}

this.info(`Using tsserver from: ${version.path}`);
this.logger.info(`Using tsserver from: ${version.path}`);
const nodePath = this._nodeVersionManager.currentVersion;
if (nodePath) {
this.info(`Using Node installation from ${nodePath} to run TS Server`);
this.logger.info(`Using Node installation from ${nodePath} to run TS Server`);
}

this.resetWatchers();
Expand Down Expand Up @@ -451,7 +439,7 @@ export default class TypeScriptServiceClient extends Disposable implements IType
"typeScriptVersionSource": { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
}
*/
this.logTelemetry('tsserver.spawned', {
this.telemetryReporter.logTelemetry('tsserver.spawned', {
...typeScriptServerEnvCommonProperties,
localTypeScriptVersion: this.versionProvider.localVersion ? this.versionProvider.localVersion.displayName : '',
typeScriptVersionSource: version.source,
Expand All @@ -468,9 +456,9 @@ export default class TypeScriptServiceClient extends Disposable implements IType
}

this.serverState = new ServerState.Errored(err, handle.tsServerLog);
this.error('TSServer errored with error.', err);
this.logger.error('TSServer errored with error.', err);
if (handle.tsServerLog?.type === 'file') {
this.error(`TSServer log file: ${handle.tsServerLog.uri.fsPath}`);
this.logger.error(`TSServer log file: ${handle.tsServerLog.uri.fsPath}`);
}

/* __GDPR__
Expand All @@ -482,15 +470,15 @@ export default class TypeScriptServiceClient extends Disposable implements IType
]
}
*/
this.logTelemetry('tsserver.error', {
this.telemetryReporter.logTelemetry('tsserver.error', {
...typeScriptServerEnvCommonProperties
});
this.serviceExited(false, apiVersion);
});

handle.onExit((data: TypeScriptServerExitEvent) => {
const { code, signal } = data;
this.error(`TSServer exited. Code: ${code}. Signal: ${signal}`);
this.logger.error(`TSServer exited. Code: ${code}. Signal: ${signal}`);

// In practice, the exit code is an integer with no ties to any identity,
// so it can be classified as SystemMetaData, rather than CallstackOrException.
Expand All @@ -505,7 +493,7 @@ export default class TypeScriptServiceClient extends Disposable implements IType
"signal" : { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" }
}
*/
this.logTelemetry('tsserver.exitWithCode', {
this.telemetryReporter.logTelemetry('tsserver.exitWithCode', {
...typeScriptServerEnvCommonProperties,
code: code ?? undefined,
signal: signal ?? undefined,
Expand All @@ -517,7 +505,7 @@ export default class TypeScriptServiceClient extends Disposable implements IType
}

if (handle.tsServerLog?.type === 'file') {
this.info(`TSServer log file: ${handle.tsServerLog.uri.fsPath}`);
this.logger.info(`TSServer log file: ${handle.tsServerLog.uri.fsPath}`);
}
this.serviceExited(!this.isRestarting, apiVersion);
this.isRestarting = false;
Expand Down Expand Up @@ -678,7 +666,7 @@ export default class TypeScriptServiceClient extends Disposable implements IType
]
}
*/
this.logTelemetry('serviceExited');
this.telemetryReporter.logTelemetry('serviceExited');
} else if (diff < 60 * 1000 * 5 /* 5 Minutes */) {
this.lastStart = Date.now();
if (!this._isPromptingAfterCrash) {
Expand Down Expand Up @@ -956,14 +944,14 @@ export default class TypeScriptServiceClient extends Disposable implements IType
"command" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
}
*/
this.logTelemetry('fatalError', { ...(error instanceof TypeScriptServerError ? error.telemetry : { command }) });
this.telemetryReporter.logTelemetry('fatalError', { ...(error instanceof TypeScriptServerError ? error.telemetry : { command }) });
console.error(`A non-recoverable error occurred while executing tsserver command: ${command}`);
if (error instanceof TypeScriptServerError && error.serverErrorText) {
console.error(error.serverErrorText);
}

if (this.serverState.type === ServerState.Type.Running) {
this.info('Killing TS Server');
this.logger.info('Killing TS Server');
const logfile = this.serverState.server.tsServerLog;
this.serverState.server.kill();
if (error instanceof TypeScriptServerError) {
Expand Down Expand Up @@ -1235,7 +1223,7 @@ export default class TypeScriptServiceClient extends Disposable implements IType
}
*/
// __GDPR__COMMENT__: Other events are defined by TypeScript.
this.logTelemetry(telemetryData.telemetryEventName, properties);
this.telemetryReporter.logTelemetry(telemetryData.telemetryEventName, properties);
}

private configurePlugin(pluginName: string, configuration: {}): any {
Expand Down
Loading