Skip to content

feat: add toggleLSPLogs command #17438

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 19, 2024
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
2 changes: 1 addition & 1 deletion docs/dev/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!

Expand Down
2 changes: 1 addition & 1 deletion docs/user/manual.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions editors/code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down Expand Up @@ -3123,6 +3128,10 @@
{
"command": "rust-analyzer.viewMemoryLayout",
"when": "inRustProject"
},
{
"command": "rust-analyzer.toggleLSPLogs",
"when": "inRustProject"
}
],
"editor/context": [
Expand Down
13 changes: 13 additions & 0 deletions editors/code/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<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();
}
};
}
1 change: 1 addition & 0 deletions editors/code/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down