Skip to content

Commit 995a17f

Browse files
committed
Auto merge of #12472 - Veykril:output-ch, r=Veykril
internal: Keep output channels across restarts cc #12470
2 parents d471d92 + 1127d25 commit 995a17f

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

editors/code/src/client.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { WorkspaceEdit } from "vscode";
77
import { Workspace } from "./ctx";
88
import { updateConfig } from "./config";
99
import { substituteVariablesInEnv } from "./config";
10+
import { outputChannel, traceOutputChannel } from "./main";
1011
import { randomUUID } from "crypto";
1112

1213
export interface Env {
@@ -82,9 +83,6 @@ export async function createClient(
8283
run,
8384
debug: run,
8485
};
85-
const traceOutputChannel = vscode.window.createOutputChannel(
86-
"Rust Analyzer Language Server Trace"
87-
);
8886

8987
let initializationOptions = vscode.workspace.getConfiguration("rust-analyzer");
9088

@@ -104,7 +102,8 @@ export async function createClient(
104102
documentSelector: [{ scheme: "file", language: "rust" }],
105103
initializationOptions,
106104
diagnosticCollectionName: "rustc",
107-
traceOutputChannel,
105+
traceOutputChannel: traceOutputChannel(),
106+
outputChannel: outputChannel(),
108107
middleware: {
109108
async provideHover(
110109
document: vscode.TextDocument,

editors/code/src/ctx.ts

-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ export class Ctx {
4343
const res = new Ctx(config, extCtx, client, serverPath, statusBar);
4444

4545
res.pushCleanup(client.start());
46-
res.pushCleanup(client.traceOutputChannel);
47-
res.pushCleanup(client.outputChannel);
4846
await client.onReady();
4947
client.onNotification(ra.serverStatus, (params) => res.setServerStatus(params));
5048
return res;

editors/code/src/main.ts

+26-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,23 @@ let ctx: Ctx | undefined;
1515

1616
const RUST_PROJECT_CONTEXT_NAME = "inRustProject";
1717

18+
let TRACE_OUTPUT_CHANNEL: vscode.OutputChannel | null = null;
19+
export function traceOutputChannel() {
20+
if (!TRACE_OUTPUT_CHANNEL) {
21+
TRACE_OUTPUT_CHANNEL = vscode.window.createOutputChannel(
22+
"Rust Analyzer Language Server Trace"
23+
);
24+
}
25+
return TRACE_OUTPUT_CHANNEL;
26+
}
27+
let OUTPUT_CHANNEL: vscode.OutputChannel | null = null;
28+
export function outputChannel() {
29+
if (!OUTPUT_CHANNEL) {
30+
OUTPUT_CHANNEL = vscode.window.createOutputChannel("Rust Analyzer Language Server");
31+
}
32+
return OUTPUT_CHANNEL;
33+
}
34+
1835
export interface RustAnalyzerExtensionApi {
1936
client: lc.LanguageClient;
2037
}
@@ -110,7 +127,7 @@ async function initCommonContext(context: vscode.ExtensionContext, ctx: Ctx) {
110127
// Reloading is inspired by @DanTup maneuver: https://github.com/microsoft/vscode/issues/45774#issuecomment-373423895
111128
ctx.registerCommand("reload", (_) => async () => {
112129
void vscode.window.showInformationMessage("Reloading rust-analyzer...");
113-
await deactivate();
130+
await doDeactivate();
114131
while (context.subscriptions.length > 0) {
115132
try {
116133
context.subscriptions.pop()!.dispose();
@@ -165,6 +182,14 @@ async function initCommonContext(context: vscode.ExtensionContext, ctx: Ctx) {
165182
}
166183

167184
export async function deactivate() {
185+
TRACE_OUTPUT_CHANNEL?.dispose();
186+
TRACE_OUTPUT_CHANNEL = null;
187+
OUTPUT_CHANNEL?.dispose();
188+
OUTPUT_CHANNEL = null;
189+
await doDeactivate();
190+
}
191+
192+
async function doDeactivate() {
168193
await setContextValue(RUST_PROJECT_CONTEXT_NAME, undefined);
169194
await ctx?.client.stop();
170195
ctx = undefined;

0 commit comments

Comments
 (0)