-
Notifications
You must be signed in to change notification settings - Fork 62
Show document with server debug info #694
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
Conversation
## 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
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, | ||
}, | ||
], | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
registerCommand( | ||
`${serverId}.debugInformation`, | ||
createDebugInformationProvider(getClient, serverId, context), | ||
), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to avoid creating the command if it is the native server?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
{ | |
"title": "Print debug information (native server only)", | |
"category": "Ruff", | |
"command": "ruff.debugInformation" | |
}, |
Summary
This PR is inspired by
rust-analyzer/status
request 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:
undefined
Test Plan
Screen.Recording.2025-02-18.at.4.03.37.PM.mov