Skip to content

Commit 0fcef7f

Browse files
committed
Auto merge of #14067 - jonas-schievink:lazy-trace-output, r=jonas-schievink
fix: Lazily create the trace output channel Fixes #13055
2 parents da24953 + 5b1187a commit 0fcef7f

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

editors/code/src/ctx.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as ra from "./lsp_ext";
44

55
import { Config, substituteVSCodeVariables } from "./config";
66
import { createClient } from "./client";
7-
import { isRustDocument, isRustEditor, log, RustEditor } from "./util";
7+
import { isRustDocument, isRustEditor, LazyOutputChannel, log, RustEditor } from "./util";
88
import { ServerStatusParams } from "./lsp_ext";
99
import { PersistentState } from "./persistent_state";
1010
import { bootstrap } from "./bootstrap";
@@ -128,9 +128,7 @@ export class Ctx {
128128
}
129129

130130
if (!this.traceOutputChannel) {
131-
this.traceOutputChannel = vscode.window.createOutputChannel(
132-
"Rust Analyzer Language Server Trace"
133-
);
131+
this.traceOutputChannel = new LazyOutputChannel("Rust Analyzer Language Server Trace");
134132
this.pushExtCleanup(this.traceOutputChannel);
135133
}
136134
if (!this.outputChannel) {

editors/code/src/util.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,49 @@ export function execute(command: string, options: ExecOptions): Promise<string>
166166
});
167167
});
168168
}
169+
170+
export class LazyOutputChannel implements vscode.OutputChannel {
171+
constructor(name: string) {
172+
this.name = name;
173+
}
174+
175+
name: string;
176+
_channel: vscode.OutputChannel | undefined;
177+
178+
get channel(): vscode.OutputChannel {
179+
if (!this._channel) {
180+
this._channel = vscode.window.createOutputChannel(this.name);
181+
}
182+
return this._channel;
183+
}
184+
185+
append(value: string): void {
186+
this.channel.append(value);
187+
}
188+
appendLine(value: string): void {
189+
this.channel.appendLine(value);
190+
}
191+
replace(value: string): void {
192+
this.channel.replace(value);
193+
}
194+
clear(): void {
195+
if (this._channel) {
196+
this._channel.clear();
197+
}
198+
}
199+
show(preserveFocus?: boolean): void;
200+
show(column?: vscode.ViewColumn, preserveFocus?: boolean): void;
201+
show(column?: any, preserveFocus?: any): void {
202+
this.channel.show(column, preserveFocus);
203+
}
204+
hide(): void {
205+
if (this._channel) {
206+
this._channel.hide();
207+
}
208+
}
209+
dispose(): void {
210+
if (this._channel) {
211+
this._channel.dispose();
212+
}
213+
}
214+
}

0 commit comments

Comments
 (0)