diff --git a/vscode/src/client.ts b/vscode/src/client.ts index 5779dbc1a..8d9e544c2 100644 --- a/vscode/src/client.ts +++ b/vscode/src/client.ts @@ -339,29 +339,29 @@ export default class Client extends LanguageClient implements ClientInterface { await vscode.window.showErrorMessage( `Ruby LSP error ${error.data.errorClass}: ${error.data.errorMessage}\n\n${error.data.backtrace}`, ); - } else if ( - error.data.errorMessage && - error.data.errorClass && - error.data.backtrace - ) { - // Sanitize the backtrace coming from the server to remove the user's home directory from it, then mark it as a - // trusted value. Otherwise the VS Code telemetry logger redacts the entire backtrace and we are unable to see - // where in the server the error occurred - const stack = new vscode.TelemetryTrustedValue( - error.data.backtrace - .split("\n") - .map((line: string) => line.replace(os.homedir(), "~")) - .join("\n"), - ) as any; - - this.telemetry.logError( - { - message: error.data.errorMessage, - name: error.data.errorClass, - stack, - }, - { ...error.data, serverVersion: this.serverVersion }, - ); + } else if (error.data) { + const { errorMessage, errorClass, backtrace } = error.data; + + if (errorMessage && errorClass && backtrace) { + // Sanitize the backtrace coming from the server to remove the user's home directory from it, then mark it as + // a trusted value. Otherwise the VS Code telemetry logger redacts the entire backtrace and we are unable to + // see where in the server the error occurred + const stack = new vscode.TelemetryTrustedValue( + backtrace + .split("\n") + .map((line: string) => line.replace(os.homedir(), "~")) + .join("\n"), + ) as any; + + this.telemetry.logError( + { + message: errorMessage, + name: errorClass, + stack, + }, + { ...error.data, serverVersion: this.serverVersion }, + ); + } } throw error; diff --git a/vscode/src/extension.ts b/vscode/src/extension.ts index e86df821f..e903bbbbb 100644 --- a/vscode/src/extension.ts +++ b/vscode/src/extension.ts @@ -28,6 +28,8 @@ export async function activate(context: vscode.ExtensionContext) { } const logger = await createLogger(context); + context.subscriptions.push(logger); + extension = new RubyLsp(context, logger); await extension.activate(); }