diff --git a/src/tools/rust-analyzer/docs/dev/README.md b/src/tools/rust-analyzer/docs/dev/README.md index 8897f02e277..002b8ba2a66 100644 --- a/src/tools/rust-analyzer/docs/dev/README.md +++ b/src/tools/rust-analyzer/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/src/tools/rust-analyzer/docs/user/manual.adoc b/src/tools/rust-analyzer/docs/user/manual.adoc index 8e6c53d0c5a..df7310f240e 100644 --- a/src/tools/rust-analyzer/docs/user/manual.adoc +++ b/src/tools/rust-analyzer/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/src/tools/rust-analyzer/editors/code/package.json b/src/tools/rust-analyzer/editors/code/package.json index b447106d999..db2a989106f 100644 --- a/src/tools/rust-analyzer/editors/code/package.json +++ b/src/tools/rust-analyzer/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/src/tools/rust-analyzer/editors/code/src/commands.ts b/src/tools/rust-analyzer/editors/code/src/commands.ts index 5cec2c61a5b..8ca285915e6 100644 --- a/src/tools/rust-analyzer/editors/code/src/commands.ts +++ b/src/tools/rust-analyzer/editors/code/src/commands.ts @@ -1485,3 +1485,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("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/src/tools/rust-analyzer/editors/code/src/main.ts b/src/tools/rust-analyzer/editors/code/src/main.ts index 0af58fd7812..f5c488c0e91 100644 --- a/src/tools/rust-analyzer/editors/code/src/main.ts +++ b/src/tools/rust-analyzer/editors/code/src/main.ts @@ -177,6 +177,7 @@ function createCommands(): Record { 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 },