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

ruff does not format the code after ctrl+alt+l (almost always) #531

Open
chaush-server opened this issue Nov 29, 2024 · 12 comments
Open

ruff does not format the code after ctrl+alt+l (almost always) #531

chaush-server opened this issue Nov 29, 2024 · 12 comments

Comments

@chaush-server
Copy link

chaush-server commented Nov 29, 2024

When you press ctrl alt L or in other words, launch code reformat even with a button from the menu, the code is not formatted, almost always (if it is, I return everything back ctrl + z several times and the bug manifests itself). I found a specific behavior when I quickly press ctrl + alt + L several times in a row, after that the code is formatted. And if you format it with expectation, it is not formatted. Also, I have assigned ruff to alt shift f and by this combination the formatting is triggered every time. I also tried all ruff settings (global ruf, lsp), turned off all third-party plugins

  • IDE: PyCharm Pro 2024.3.1
  • OS: Win 11
  • Ruff Version 0.8.1
  • Plugin version 0.0.42

Screenshots
изображение
изображение

@rsheftel
Copy link

I have run into the same issue with plugin verion 0.0.42 and ruff version 0.7.1. To get the ruff plugin to format the code I need to press Ctrl-Alt-L at least 3 times in succession. There are no warnings or errors, but that is the only way to make it format.

@jaens
Copy link

jaens commented Dec 16, 2024

Had the same problem, the "Use ruff format (experimental)" setting fixed it for me, at least temporarily:

image

@Olegt0rr
Copy link

Got the same issue

ruff==0.9.1
PyCharm 2024.3.1.1 (Professional Edition)
Build #PY-243.22562.220, built on December 18, 2024
Runtime version: 21.0.5+8-b631.28 aarch64 (JCEF 122.1.9)
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Toolkit: sun.lwawt.macosx.LWCToolkit
macOS 15.2
GC: G1 Young Generation, G1 Concurrent GC, G1 Old Generation

Non-Bundled Plugins:
  com.koxudaxi.ruff (0.0.42)

@koxudaxi
Copy link
Owner

Sorry for the late confirmation.
I have tested formatting in my environment and it works with a single press.
Here is my environment:

image

IDE: PyCharm Pro 2024.3.1 #PY-243.22562.220
OS: macOS 15.1.1
Ruff Version 0.9.1 (12f86f39a 2025-01-10)
Plugin version 0.0.42

As @jaens pointed out, the Use ruff format... option needs to be enabled for formatting to work. If formatting worked in previous versions without this option enabled, that would be considered a bug.

@koxudaxi
Copy link
Owner

We initially treated format as an experimental option, but if this is going to be used by everyone, it might be better to turn it on by default.

Please comment if the formatting does not take place even after enabling this format option. I also have a windows environment, so I will try that as well.

@Olegt0rr
Copy link

Olegt0rr commented Jan 14, 2025

Formatting is important for me. It would be nice for me to make it enabled by default! :)

I have enabled formatting in every project.
But now it's enabled and not working

@koxudaxi
Copy link
Owner

I also tested it in windows. It works fine.

PyCharm 2024.3.1.1 (Professional Edition)
Build #PY-243.22562.220, built on December 18, 2024
Runtime version: 21.0.5+8-b631.28 amd64 (JCEF 122.1.9)
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Toolkit: sun.awt.windows.WToolkit
Windows 11.0
GC: G1 Young Generation, G1 Concurrent GC, G1 Old Generation
Memory: 2048M
Cores: 20
Registry:
ide.experimental.ui=true
i18n.locale=
Non-Bundled Plugins:
com.redhat.devtools.lsp4ij (0.9.0)
com.intellij.ml.llm (243.22562.251.6)
com.koxudaxi.ruff (0.0.42)

@rsheftel
Copy link

With the latest update it works on the first time for me now as well, I was one of the previous commenters with issues

I would vote for turning it on be default

@koxudaxi
Copy link
Owner

@Olegt0rr
I used the code for the test.

def foo(
    bar: int,
        baz: str,
):
    eggs = [
        1,
            2,
    ]

after enter alt + command + L

def foo(
    bar: int,
    baz: str,
):
    eggs = [
        1,
        2,
    ]

The project doesn't have the any ruff config file like pyproject.toml or ruff.toml

Non-Bundled Plugins:
  com.koxudaxi.ruff (0.0.42)

Which do you use the LSP Client?
Intellij's LSP client or LSP4IJ ?

image

if you select LSP4IJ when you should install LSP4IJ as a plugin.
image

@Olegt0rr
Copy link

Video with both local and global ruff executable
https://github.com/user-attachments/assets/b7916986-6693-4bde-ae32-74e952d3cc1d

@koxudaxi
Copy link
Owner

@Olegt0rr
Thank you for providing the video.
One concerning point is that "Running Ruff Formatter" is not showing in the Window progress bar at the bottom after you execute Reformat. In your video, "Reformat Code" appears briefly, but it should be followed by "Running Ruff Formatter".
For confirmation, are you using any other plugins or formatters? During the development of this plugin, I noticed that only one AsyncDocumentFormatter can run at a time, so if another formatter is executing, the Ruff formatter won't work.

image

I expect the message after that.
image

@Olegt0rr
Copy link

I'm not using any formatters...

But just removed all old plugins from IDE and... magic! ruff works

Unfortunately, in my emotions I deleted all plugins in a row, both the ones that were turned off and the ones I haven't used in a long time... And now I can't say which one had compatibility problems (which would be useful for those who are experiencing problems)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants