Skip to content

Commit 78f4146

Browse files
committedMar 24, 2025·
chore: Cleanup vscode extension output channels
1 parent 3bf18d4 commit 78f4146

File tree

7 files changed

+16
-27
lines changed

7 files changed

+16
-27
lines changed
 

‎docs/book/src/contributing/README.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,10 @@ By default, log goes to stderr, but the stderr itself is processed by VS Code.
140140
`--log-file <PATH>` CLI argument allows logging to file.
141141
Setting the `RA_LOG_FILE=<PATH>` environment variable will also log to file, it will also override `--log-file`.
142142

143-
To see stderr in the running VS Code instance, go to the "Output" tab of the panel and select `Rust Analyzer Client`.
143+
To see the server stderr output in the running VS Code instance, go to the "Output" tab of the panel
144+
and select `rust-analyzer Language Server`.
144145
This shows `eprintln!` as well.
145-
Note that `stdout` is used for the actual protocol, so `println!` will break things.
146+
Note that `stdout` is used by LSP messages, so using `println!`—or anything that writes to `stdout`will break rust-analyzer!
146147

147148
To log all communication between the server and the client, there are two choices:
148149

@@ -153,9 +154,11 @@ To log all communication between the server and the client, there are two choice
153154
```
154155

155156
* You can log on the client side, by the `rust-analyzer: Toggle LSP Logs` command or enabling `"rust-analyzer.trace.server": "verbose"` workspace setting.
156-
These logs are shown in a separate tab in the output and could be used with LSP inspector.
157+
These logs are shown in a separate tab named `rust-analyzer LSP Trace` in the output and could be used with LSP inspector.
157158
Kudos to [@DJMcNab](https://github.com/DJMcNab) for setting this awesome infra up!
158159

160+
Finally there are the logs of the VSCode extension itself which go into the `rust-analyzer Extension` output tab.
161+
159162
There are also several VS Code commands which might be of interest:
160163

161164
* `rust-analyzer: Status` shows some memory-usage statistics.

‎editors/code/package.json

-5
Original file line numberDiff line numberDiff line change
@@ -606,11 +606,6 @@
606606
"/rustc/<id>": "${env:USERPROFILE}/.rustup/toolchains/<toolchain-id>/lib/rustlib/src/rust"
607607
}
608608
},
609-
"rust-analyzer.debug.openDebugPane": {
610-
"markdownDescription": "Whether to open up the `Debug Panel` on debugging start.",
611-
"type": "boolean",
612-
"default": false
613-
},
614609
"rust-analyzer.debug.buildBeforeRestart": {
615610
"markdownDescription": "Whether to rebuild the project modules before debugging the same test again",
616611
"type": "boolean",

‎editors/code/src/config.ts

-1
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,6 @@ export class Config {
323323
return {
324324
engine: this.get<string>("debug.engine"),
325325
engineSettings: this.get<object>("debug.engineSettings") ?? {},
326-
openDebugPane: this.get<boolean>("debug.openDebugPane"),
327326
buildBeforeRestart: this.get<boolean>("debug.buildBeforeRestart"),
328327
sourceFileMap: sourceFileMap,
329328
};

‎editors/code/src/ctx.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,11 @@ export class Ctx implements RustAnalyzerExtensionApi {
190190
}
191191

192192
if (!this.traceOutputChannel) {
193-
this.traceOutputChannel = new LazyOutputChannel("Rust Analyzer Language Server Trace");
193+
this.traceOutputChannel = new LazyOutputChannel("rust-analyzer LSP Trace");
194194
this.pushExtCleanup(this.traceOutputChannel);
195195
}
196196
if (!this.outputChannel) {
197-
this.outputChannel = vscode.window.createOutputChannel("Rust Analyzer Language Server");
197+
this.outputChannel = vscode.window.createOutputChannel("rust-analyzer Language Server");
198198
this.pushExtCleanup(this.outputChannel);
199199
}
200200

‎editors/code/src/debug.ts

+4-11
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ import type * as ra from "./lsp_ext";
66
import { Cargo } from "./toolchain";
77
import type { Ctx } from "./ctx";
88
import { createTaskFromRunnable, prepareEnv } from "./run";
9-
import { execute, isCargoRunnableArgs, unwrapUndefinable } from "./util";
9+
import { execute, isCargoRunnableArgs, unwrapUndefinable, log } from "./util";
1010
import type { Config } from "./config";
1111

12-
const debugOutput = vscode.window.createOutputChannel("Debug");
13-
1412
// Here we want to keep track on everything that's currently running
1513
const activeDebugSessionIds: string[] = [];
1614

@@ -56,15 +54,14 @@ export async function startDebugSession(ctx: Ctx, runnable: ra.Runnable): Promis
5654
if (-1 !== index) {
5755
debugConfig = configurations[index];
5856
message = " (from launch.json)";
59-
debugOutput.clear();
6057
} else {
6158
debugConfig = await getDebugConfiguration(ctx.config, runnable);
6259
}
6360

6461
if (!debugConfig) return false;
6562

66-
debugOutput.appendLine(`Launching debug configuration${message}:`);
67-
debugOutput.appendLine(JSON.stringify(debugConfig, null, 2));
63+
log.debug(`Launching debug configuration${message}:`);
64+
log.debug(JSON.stringify(debugConfig, null, 2));
6865
return vscode.debug.startDebugging(undefined, debugConfig);
6966
}
7067

@@ -118,10 +115,6 @@ async function getDebugConfiguration(
118115
return;
119116
}
120117

121-
debugOutput.clear();
122-
if (config.debug.openDebugPane) {
123-
debugOutput.show(true);
124-
}
125118
// folder exists or RA is not active.
126119

127120
const workspaceFolders = vscode.workspace.workspaceFolders!;
@@ -321,7 +314,7 @@ async function getDebugExecutable(
321314
runnableArgs: ra.CargoRunnableArgs,
322315
env: Record<string, string>,
323316
): Promise<string> {
324-
const cargo = new Cargo(runnableArgs.workspaceRoot || ".", debugOutput, env);
317+
const cargo = new Cargo(runnableArgs.workspaceRoot || ".", env);
325318
const executable = await cargo.executableFromArgs(runnableArgs);
326319

327320
// if we are here, there were no compilation errors.

‎editors/code/src/toolchain.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ interface CompilerMessage {
3737
export class Cargo {
3838
constructor(
3939
readonly rootFolder: string,
40-
readonly output: vscode.OutputChannel,
4140
readonly env: Record<string, string>,
4241
) {}
4342

@@ -93,14 +92,14 @@ export class Cargo {
9392
});
9493
}
9594
} else if (message.reason === "compiler-message") {
96-
this.output.append(message.message.rendered);
95+
log.info(message.message.rendered);
9796
}
9897
},
99-
(stderr) => this.output.append(stderr),
98+
(stderr) => log.error(stderr),
10099
env,
101100
);
102101
} catch (err) {
103-
this.output.show(true);
102+
log.error(`Cargo invocation has failed: ${err}`);
104103
throw new Error(`Cargo invocation has failed: ${err}`);
105104
}
106105

‎editors/code/src/util.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export type Env = {
1818
};
1919

2020
class Log {
21-
private readonly output = vscode.window.createOutputChannel("Rust Analyzer Client", {
21+
private readonly output = vscode.window.createOutputChannel("rust-analyzer Extension", {
2222
log: true,
2323
});
2424

0 commit comments

Comments
 (0)
Please sign in to comment.