Unnamed repository; edit this file 'description' to name the repository.
Auto merge of #17438 - jjoeldaniel:toggle_lsp_logs, r=Veykril
feat: add `toggleLSPLogs` command Implement client-side command to toggle LSP logs in VSCode. The command replaces the need to add/remove the `"rust-analyzer.trace.server": "verbose"` setting each time one wants to display logs. I've also updated the docs/ instances that reference the now outdated manual method. The command labeled `rust-analyzer: Toggle LSP Logs` enables the setting project-wide and opens the relevant trace output channel. Closes #8233
bors 2024-06-19
parent fe4232c · parent 2ebcf55 · commit 87ee18d
-rw-r--r--docs/dev/README.md2
-rw-r--r--docs/user/manual.adoc2
-rw-r--r--editors/code/package.json9
-rw-r--r--editors/code/src/commands.ts13
-rw-r--r--editors/code/src/main.ts1
5 files changed, 25 insertions, 2 deletions
diff --git a/docs/dev/README.md b/docs/dev/README.md
index 8897f02e27..002b8ba2a6 100644
--- a/docs/dev/README.md
+++ b/docs/dev/README.md
@@ -145,7 +145,7 @@ To log all communication between the server and the client, there are two choice
```
env RA_LOG=lsp_server=debug code .
```
-* You can log on the client side, by enabling `"rust-analyzer.trace.server": "verbose"` workspace setting.
+* You can log on the client side, by the `rust-analyzer: Toggle LSP Logs` command or enabling `"rust-analyzer.trace.server": "verbose"` workspace setting.
These logs are shown in a separate tab in the output and could be used with LSP inspector.
Kudos to [@DJMcNab](https://github.com/DJMcNab) for setting this awesome infra up!
diff --git a/docs/user/manual.adoc b/docs/user/manual.adoc
index 3bc739e934..e1c1c54ec4 100644
--- a/docs/user/manual.adoc
+++ b/docs/user/manual.adoc
@@ -591,7 +591,7 @@ The next thing to check would be panic messages in rust-analyzer's log.
Log messages are printed to stderr, in VS Code you can see them in the `Output > Rust Analyzer Language Server` tab of the panel.
To see more logs, set the `RA_LOG=info` environment variable, this can be done either by setting the environment variable manually or by using `rust-analyzer.server.extraEnv`, note that both of these approaches require the server to be restarted.
-To fully capture LSP messages between the editor and the server, set `"rust-analyzer.trace.server": "verbose"` config and check
+To fully capture LSP messages between the editor and the server, run the `rust-analyzer: Toggle LSP Logs` command and check
`Output > Rust Analyzer Language Server Trace`.
The root cause for many "`nothing works`" problems is that rust-analyzer fails to understand the project structure.
diff --git a/editors/code/package.json b/editors/code/package.json
index b447106d99..db2a989106 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -300,6 +300,11 @@
"command": "rust-analyzer.toggleCheckOnSave",
"title": "Toggle Check on Save",
"category": "rust-analyzer"
+ },
+ {
+ "command": "rust-analyzer.toggleLSPLogs",
+ "title": "Toggle LSP Logs",
+ "category": "rust-analyzer"
}
],
"keybindings": [
@@ -3123,6 +3128,10 @@
{
"command": "rust-analyzer.viewMemoryLayout",
"when": "inRustProject"
+ },
+ {
+ "command": "rust-analyzer.toggleLSPLogs",
+ "when": "inRustProject"
}
],
"editor/context": [
diff --git a/editors/code/src/commands.ts b/editors/code/src/commands.ts
index c226aefeab..f0f9fab1c6 100644
--- a/editors/code/src/commands.ts
+++ b/editors/code/src/commands.ts
@@ -1489,3 +1489,16 @@ export function toggleCheckOnSave(ctx: Ctx): Cmd {
ctx.refreshServerStatus();
};
}
+
+export function toggleLSPLogs(ctx: Ctx): Cmd {
+ return async () => {
+ const config = vscode.workspace.getConfiguration("rust-analyzer");
+ const targetValue =
+ config.get<string | undefined>("trace.server") === "verbose" ? undefined : "verbose";
+
+ await config.update("trace.server", targetValue, vscode.ConfigurationTarget.Workspace);
+ if (targetValue && ctx.client && ctx.client.traceOutputChannel) {
+ ctx.client.traceOutputChannel.show();
+ }
+ };
+}
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index 788f9a0c14..a9bf54c776 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -177,6 +177,7 @@ function createCommands(): Record<string, CommandFactory> {
serverVersion: { enabled: commands.serverVersion },
viewMemoryLayout: { enabled: commands.viewMemoryLayout },
toggleCheckOnSave: { enabled: commands.toggleCheckOnSave },
+ toggleLSPLogs: { enabled: commands.toggleLSPLogs },
// Internal commands which are invoked by the server.
applyActionGroup: { enabled: commands.applyActionGroup },
applySnippetWorkspaceEdit: { enabled: commands.applySnippetWorkspaceEditCommand },