Show document with server debug info#694
Merged
dhruvmanila merged 3 commits intomainfrom Feb 18, 2025
Merged
Conversation
dhruvmanila
added a commit
to astral-sh/ruff
that referenced
this pull request
Feb 18, 2025
## Summary This PR updates the `ruff.printDebugInformation` command to return the info as string in the response. Currently, we send a `window/logMessage` request with the info but that has the disadvantage that it's not visible to the user directly. What `rust-analyzer` does with it's `rust-analyzer/status` request which returns it as a string which then the client can just display it in a separate window. This is what I'm thinking of doing as well. Other editors can also benefit from it by directly opening a temporary file with this information that the user can see directly. There are couple of options here: 1. Keep using the command, keep the log request and return the string 2. Keep using the command, remove the log request and return the string 3. Create a new request similar to `rust-analyzer/status` which returns a string This PR implements (1) but I'd want to move towards (2) and remove the log request completely. We haven't advertised it as such so this would only require updating the VS Code extension to handle it by opening a new document with the debug content. ## Test plan For VS Code, refer to astral-sh/ruff-vscode#694. For Neovim, one could do: ```lua local function execute_ruff_command(command) local client = vim.lsp.get_clients({ bufnr = vim.api.nvim_get_current_buf(), name = name, method = 'workspace/executeCommand', })[1] if not client then return end client.request('workspace/executeCommand', { command = command, arguments = { { uri = vim.uri_from_bufnr(0) } }, function(err, result) if err then -- log error return end vim.print(result) -- Or, open a new window with the `result` content end } ```
2a347c8 to
0627873
Compare
0627873 to
3d3fae7
Compare
3d3fae7 to
7022bbc
Compare
dhruvmanila
commented
Feb 18, 2025
Comment on lines
+70
to
+83
| const textEditor = vscode.window.activeTextEditor; | ||
| const notebookEditor = vscode.window.activeNotebookEditor; | ||
| const params = { | ||
| command: `${serverId}.printDebugInformation`, | ||
| arguments: [ | ||
| { | ||
| textDocument: notebookEditor | ||
| ? { uri: notebookEditor.notebook.uri.toString() } | ||
| : textEditor | ||
| ? { uri: textEditor.document.uri.toString() } | ||
| : undefined, | ||
| }, | ||
| ], | ||
| }; |
Member
Author
There was a problem hiding this comment.
I updated this in this PR from main to check if we're in a notebook context and then use text document. I don't think there's any specific information for a notebook cell so using a notebook for them should be fine.
MichaReiser
approved these changes
Feb 18, 2025
Comment on lines
+200
to
+203
| registerCommand( | ||
| `${serverId}.debugInformation`, | ||
| createDebugInformationProvider(getClient, serverId, context), | ||
| ), |
Member
There was a problem hiding this comment.
Would it be possible to avoid creating the command if it is the native server?
Member
Author
There was a problem hiding this comment.
I don't think so. Looking at https://code.visualstudio.com/api/references/contribution-points#contributes.commands, we need to add it to the UI via package.json which makes this not possible (
Lines 434 to 438 in b4e0698
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR is inspired by
rust-analyzer/statusrequest to show the debug information in a separate window.Reference: https://github.com/rust-lang/rust-analyzer/blob/e865b249e63a9c73e4741b32fd1c977a98d3c556/editors/code/src/commands.ts#L37-L71
It has been adopted to fit out needs:
undefinedTest Plan
Screen.Recording.2025-02-18.at.4.03.37.PM.mov