Skip to content

internal: Keep output channels across restarts #12472

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions editors/code/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { WorkspaceEdit } from "vscode";
import { Workspace } from "./ctx";
import { updateConfig } from "./config";
import { substituteVariablesInEnv } from "./config";
import { outputChannel, traceOutputChannel } from "./main";
import { randomUUID } from "crypto";

export interface Env {
Expand Down Expand Up @@ -82,9 +83,6 @@ export async function createClient(
run,
debug: run,
};
const traceOutputChannel = vscode.window.createOutputChannel(
"Rust Analyzer Language Server Trace"
);

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

Expand All @@ -104,7 +102,8 @@ export async function createClient(
documentSelector: [{ scheme: "file", language: "rust" }],
initializationOptions,
diagnosticCollectionName: "rustc",
traceOutputChannel,
traceOutputChannel: traceOutputChannel(),
outputChannel: outputChannel(),
middleware: {
async provideHover(
document: vscode.TextDocument,
Expand Down
2 changes: 0 additions & 2 deletions editors/code/src/ctx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ export class Ctx {
const res = new Ctx(config, extCtx, client, serverPath, statusBar);

res.pushCleanup(client.start());
res.pushCleanup(client.traceOutputChannel);
res.pushCleanup(client.outputChannel);
await client.onReady();
client.onNotification(ra.serverStatus, (params) => res.setServerStatus(params));
return res;
Expand Down
27 changes: 26 additions & 1 deletion editors/code/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,23 @@ let ctx: Ctx | undefined;

const RUST_PROJECT_CONTEXT_NAME = "inRustProject";

let TRACE_OUTPUT_CHANNEL: vscode.OutputChannel | null = null;
export function traceOutputChannel() {
if (!TRACE_OUTPUT_CHANNEL) {
TRACE_OUTPUT_CHANNEL = vscode.window.createOutputChannel(
"Rust Analyzer Language Server Trace"
);
}
return TRACE_OUTPUT_CHANNEL;
}
let OUTPUT_CHANNEL: vscode.OutputChannel | null = null;
export function outputChannel() {
if (!OUTPUT_CHANNEL) {
OUTPUT_CHANNEL = vscode.window.createOutputChannel("Rust Analyzer Language Server");
}
return OUTPUT_CHANNEL;
}

export interface RustAnalyzerExtensionApi {
client: lc.LanguageClient;
}
Expand Down Expand Up @@ -110,7 +127,7 @@ async function initCommonContext(context: vscode.ExtensionContext, ctx: Ctx) {
// Reloading is inspired by @DanTup maneuver: https://github.com/microsoft/vscode/issues/45774#issuecomment-373423895
ctx.registerCommand("reload", (_) => async () => {
void vscode.window.showInformationMessage("Reloading rust-analyzer...");
await deactivate();
await doDeactivate();
while (context.subscriptions.length > 0) {
try {
context.subscriptions.pop()!.dispose();
Expand Down Expand Up @@ -165,6 +182,14 @@ async function initCommonContext(context: vscode.ExtensionContext, ctx: Ctx) {
}

export async function deactivate() {
TRACE_OUTPUT_CHANNEL?.dispose();
TRACE_OUTPUT_CHANNEL = null;
OUTPUT_CHANNEL?.dispose();
OUTPUT_CHANNEL = null;
await doDeactivate();
}

async function doDeactivate() {
await setContextValue(RUST_PROJECT_CONTEXT_NAME, undefined);
await ctx?.client.stop();
ctx = undefined;
Expand Down