-
Notifications
You must be signed in to change notification settings - Fork 23
Support ruff format
#53
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
Comments
Hi, are you talking about this? https://github.com/astral-sh/ruff/blob/main/crates/ruff_python_formatter/README.md |
Yes, that's exactly what I mean. As this will probably come up again sooner or later, one could consider adding it behind an environment variable like ruff-lsp does it: https://github.com/astral-sh/ruff-lsp/blob/0bb19b4f56e2c99c7651ac391a964a1c8e59ffa5/ruff_lsp/server.py#L732 |
Just a short note: The formatter was moved to beta and essentially production-ready today: https://astral.sh/blog/the-ruff-formatter |
I'm the maintainer for python-lsp-black, feel free to look and borrow its implementation to implement the formatting capabilities. If nobody else is planning on working on it I will try to find time to implement it, I have been moving into a ruff-exclusive workflow and black was the last piece. |
@haplo I would greatly appreciate you working on it! I am not opposed to the idea but can currently not invest a lot of time into it |
@jhossbach I started work on this, but hit some issues and I'm not sure about the UX we should have. The plugin already has a format document action to sort the imports, and the Another thing I discovered is that One last thing: I think the plugin should disable |
Yes, that sounds like a good idea.
I am not entirely sure what change in the semantics can happen but I suppose they know what they are doing. If they come up with a solution that formats the code just like running
You're right, also good idea, except it is called |
@haplo is there anything i could help you with, working on this? |
I put it on pause waiting for the new ruff command that will do formatting and linting, so feel free to work on this. Change is straightforward, just update python-lsp-ruff/pylsp_ruff/plugin.py Lines 416 to 434 in be27747
Do add/update tests and documentation too. @jhossbach I think as part of this work we should update the ruff dependency on python-lsp-ruff to the first ruff version with format support (0.1.2). You can tag me in the pull request, would be happy to give it a try and review. |
Maybe not quite so straightforward as |
You are right, some extra refactor work would be needed on |
You could modify this function and add an argument |
Sliding in here because I think my issue might be related to this discussion. I'm just trying to get ruff to format my files using the black ruleset they reimplemented. Is there a way to set this up yet? All I can get to work is isort. |
@Mithrandir2k18 Yes this is your problem. If you're in the mood to test you can try installing python-lsp-ruff from |
works like a charm :) here's my pylsp config:
Weirdly enough it doesn't fix missing trailing commas, which it should do, right? |
I believe it should, yes, same as Black does. Do check out the magic trailing comma docs in case that explains your situation. |
Hi, as far as I can see, the new ruff formatter comparable to black is not yet supported by this plugin. If I understand it correctly, the term "format" in the code of this repo relates to fixing errors. Would it be possible to add formatting (in the sense of black) as a new code action?
The text was updated successfully, but these errors were encountered: