Skip to content

Commit

Permalink
Auto merge of rust-lang#14067 - jonas-schievink:lazy-trace-output, r=…
Browse files Browse the repository at this point in the history
…jonas-schievink

fix: Lazily create the trace output channel

Fixes rust-lang/rust-analyzer#13055
  • Loading branch information
bors committed Jan 31, 2023
2 parents da24953 + 5b1187a commit 0fcef7f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
6 changes: 2 additions & 4 deletions editors/code/src/ctx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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) {
Expand Down
46 changes: 46 additions & 0 deletions editors/code/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,49 @@ export function execute(command: string, options: ExecOptions): Promise<string>
});
});
}

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?: any, preserveFocus?: any): void {
this.channel.show(column, preserveFocus);
}
hide(): void {
if (this._channel) {
this._channel.hide();
}
}
dispose(): void {
if (this._channel) {
this._channel.dispose();
}
}
}

0 comments on commit 0fcef7f

Please sign in to comment.