-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Add a new /lsp
endpoint to blackd
#2512
base: main
Are you sure you want to change the base?
Conversation
This endpoint implements the document formatting request from the language server protocol spec: https://microsoft.github.io/language-server-protocol/specifications/specification-3-17/#textDocument_formatting There are a few limitations to this implementation: * it ignores all formatting options that are passed in * on syntax error it returns a generic "internal server error" message * it only supports `file://` URIs * there's no support for initialization protocol messages: https://microsoft.github.io/language-server-protocol/specifications/specification-3-17/#initialize TODO: - [ ] Add changelog entry - [ ] Add unit tests to cover lsp.py
Let me revisit this implementation, apparently the dependency I chose is doomed: pengutronix/aiohttp-json-rpc#62 |
@karthiknadig can you give a review? |
Thanks for adding support for the formatting request. But to fully support formatting over LSP, black should be able to handle plain text formatting. This is to support format-on-save and format-on-type, where the contents have not yet been written to the disk, so just having the path won't be enough. There are two cases there to handle, 1) the file exists on disk, but the content is not yet saved to disk. 2) User just created a new (unsaved file), the file is not yet available on disk. (but we can provide a educated guess for the uri of the directory where it might get saved, which could be used to get the formatting settings for black). |
Another key point about supporting the "file not on disk" scenario is that's required to support things like virtual workspaces when the content lives entirely on GitHub (i.e. what https://marketplace.visualstudio.com/items?itemName=GitHub.remotehub enables). This then bleeds into things like any chance of making Black work with github.dev via WebAssembly, etc. |
Hi what's the status on this? Is there still a pressing need for this PR now that the VSCode team have their own Black LSP server? |
@ichard26 I think it depends on who you want to own the server and whether others want access. I see a few options:
We're open to any of this as we want to do what's best for the project and community. |
This endpoint implements the document formatting request from the language server protocol spec: https://microsoft.github.io/language-server-protocol/specifications/specification-3-17/#textDocument_formatting
There are a few limitations to this implementation:
file://
URIsTODO: