Skip to content
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

Support "Format Selection" now that Black 23.11.0 adds a --line-ranges= CLI option. #374

Closed
yilei opened this issue Nov 8, 2023 · 8 comments · Fixed by #380
Closed

Support "Format Selection" now that Black 23.11.0 adds a --line-ranges= CLI option. #374

yilei opened this issue Nov 8, 2023 · 8 comments · Fixed by #380
Labels
feature-request Request for new features or functionality

Comments

@yilei
Copy link
Contributor

yilei commented Nov 8, 2023

psf/black#4020 added a --line-ranges= option to Black and is now released in 23.11.0. See https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html#line-ranges

VS Code should now be able to properly support the "Format Selection" command.

Previously related: #176

@github-actions github-actions bot added the triage-needed Issue is not triaged. label Nov 8, 2023
@karthiknadig karthiknadig added feature-request Request for new features or functionality and removed triage-needed Issue is not triaged. labels Nov 8, 2023
@karthiknadig
Copy link
Member

karthiknadig commented Nov 8, 2023

@yilei If you are interested in providing a PR we are open for this. This code here needs to be updated to pass in the line range.

@LSP_SERVER.feature(lsp.TEXT_DOCUMENT_RANGE_FORMATTING)
def range_formatting(params: lsp.DocumentFormattingParams) -> list[lsp.TextEdit] | None:
"""LSP handler for textDocument/formatting request."""
log_warning("Black does not support range formatting. Formatting entire document.")
document = LSP_SERVER.workspace.get_text_document(params.text_document.uri)
return _formatting_helper(document)

There is also proposed support for multiple line ranges via format ranges. That support is still not in pygls, that will allow us to add the multi-range support as well.

@yilei
Copy link
Contributor Author

yilei commented Nov 9, 2023

Thanks for the pointer. Any pointers how to build my local version of the extension and have VS Code use it? The Contributing Guide doesn't mention this.

@karthiknadig
Copy link
Member

You can run this to build it locally:

> npm run package

@karthiknadig
Copy link
Member

I also update the contributing guide. The requirements were a bit out dated.

@yilei
Copy link
Contributor Author

yilei commented Nov 11, 2023

@karthiknadig Thanks for updating. But I think the correct command to build the vsix package is npm run vsce-package, took me a while to poke around the source since I'm not familiar with npm.

@karthiknadig
Copy link
Member

@yilei Were you able to add this support?

@yilei
Copy link
Contributor Author

yilei commented Nov 17, 2023

@karthiknadig I'm able to make it work, but I had a hard time writing tests and make the tests run. Should I still send the PR without tests?

@karthiknadig
Copy link
Member

Yes. I can help with tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants