From 56f81ebc3e52ac7e6dd8a3359e290d8765975edc Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Tue, 31 Jan 2023 15:43:47 +0100 Subject: [PATCH 1/2] Lazily create the trace output channel --- editors/code/src/ctx.ts | 6 ++---- editors/code/src/util.ts | 46 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/editors/code/src/ctx.ts b/editors/code/src/ctx.ts index 8b04182155..e2a30e0cc4 100644 --- a/editors/code/src/ctx.ts +++ b/editors/code/src/ctx.ts @@ -4,7 +4,7 @@ import * as ra from "./lsp_ext"; import { Config, substituteVSCodeVariables } from "./config"; import { createClient } from "./client"; -import { isRustDocument, isRustEditor, log, RustEditor } from "./util"; +import { isRustDocument, isRustEditor, LazyOutputChannel, log, RustEditor } from "./util"; import { ServerStatusParams } from "./lsp_ext"; import { PersistentState } from "./persistent_state"; import { bootstrap } from "./bootstrap"; @@ -128,9 +128,7 @@ export class Ctx { } if (!this.traceOutputChannel) { - this.traceOutputChannel = vscode.window.createOutputChannel( - "Rust Analyzer Language Server Trace" - ); + this.traceOutputChannel = new LazyOutputChannel("Rust Analyzer Language Server Trace"); this.pushExtCleanup(this.traceOutputChannel); } if (!this.outputChannel) { diff --git a/editors/code/src/util.ts b/editors/code/src/util.ts index a92c90f7ff..33d42986ad 100644 --- a/editors/code/src/util.ts +++ b/editors/code/src/util.ts @@ -166,3 +166,49 @@ export function execute(command: string, options: ExecOptions): Promise }); }); } + +export class LazyOutputChannel implements vscode.OutputChannel { + constructor(name: string) { + this.name = name; + } + + name: string; + _channel: vscode.OutputChannel | undefined; + + get channel(): vscode.OutputChannel { + if (!this._channel) { + this._channel = vscode.window.createOutputChannel(this.name); + } + return this._channel; + } + + append(value: string): void { + this.channel.append(value); + } + appendLine(value: string): void { + this.channel.appendLine(value); + } + replace(value: string): void { + this.channel.replace(value); + } + clear(): void { + if (this._channel) { + this._channel.clear(); + } + } + show(preserveFocus?: boolean): void; + show(column?: vscode.ViewColumn, preserveFocus?: boolean): void; + show(column?: vscode.ViewColumn, preserveFocus?: boolean): void { + this.channel.show(column, preserveFocus); + } + hide(): void { + if (this._channel) { + this._channel.hide(); + } + } + dispose(): void { + if (this._channel) { + this._channel.dispose(); + } + } +} From 5b1187a04654d3d95926265e3d9762f695b31c1d Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Tue, 31 Jan 2023 15:49:39 +0100 Subject: [PATCH 2/2] =?UTF-8?q?Remove=20some=20types=20=C2=AF\=5F(?= =?UTF-8?q?=E3=83=84)=5F/=C2=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- editors/code/src/util.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/editors/code/src/util.ts b/editors/code/src/util.ts index 33d42986ad..d93b9caeb1 100644 --- a/editors/code/src/util.ts +++ b/editors/code/src/util.ts @@ -198,7 +198,7 @@ export class LazyOutputChannel implements vscode.OutputChannel { } show(preserveFocus?: boolean): void; show(column?: vscode.ViewColumn, preserveFocus?: boolean): void; - show(column?: vscode.ViewColumn, preserveFocus?: boolean): void { + show(column?: any, preserveFocus?: any): void { this.channel.show(column, preserveFocus); } hide(): void {