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

Notebook Format Cell//Notebook not working with ruff-lsp #490

Open
jamesvrt opened this issue Sep 4, 2024 · 16 comments
Open

Notebook Format Cell//Notebook not working with ruff-lsp #490

jamesvrt opened this issue Sep 4, 2024 · 16 comments

Comments

@jamesvrt
Copy link

jamesvrt commented Sep 4, 2024

  • A minimal code snippet that reproduces the bug.

Create test.ipynb, create a cell with

from abc import (a, b, c
)

Perform Format Select/Cell/Document/Notebook via ctrl+shift+P, the right click menu or the keyboard shortcuts.

No changes observed in the cell.

Ruff output:

2024-09-04 11:28:50.174 [info] Using interpreter executable: /home/jamesvrt/miniconda3/envs/test/bin/ruff
2024-09-04 11:28:50.174 [info] Found ruff 0.6.4 at /home/jamesvrt/miniconda3/envs/test/bin/ruff
2024-09-04 11:28:50.174 [info] Running Ruff with: /home/jamesvrt/miniconda3/envs/test/bin/ruff ['format', '--force-exclude', '--quiet', '--stdin-filename', '/home/jamesvrt/test/test.ipynb', '--config', 'line-length=120']

Performing ruff format test.ipynb on the CLI works as expected.

Including "ruff.nativeServer": "on" in settings.json resolves the issue.

  • The current Ruff and VS Code settings (any relevant sections from your pyproject.toml and settings.json).

No ruff.toml or pyproject.toml

settings.json includes:

    "[python]": {
        "editor.defaultFormatter": "charliermarsh.ruff",
    },
    "ruff.format.args": ["--config", "line-length=120"],
    "notebook.defaultFormatter": "charliermarsh.ruff",
  • The current Ruff and VS Code extension versions (ruff --version).

ruff 0.6.3
ruff vscode extension 2024.42.0

  • A description of your environment (e.g., operating system, Python version, etc.).

Ubuntu 22.04
VSCode 1.92.2
Python 3.10.11

@dhruvmanila
Copy link
Member

Do you see anything in the logs? Refer to the troubleshooting guide.

There was a bug that's been fixed in #485, I'll bump the version of ruff-lsp today to get it out.

@dhruvmanila
Copy link
Member

Including "ruff.nativeServer": "off" in settings.json resolves the issue.

What do you mean by this? Like, using the ruff-lsp resolves the issue? But, the issue title says that it doesn't work with ruff-lsp?

@jamesvrt
Copy link
Author

jamesvrt commented Sep 5, 2024

What do you mean by this?

Sorry, typo! I meant:

Including "ruff.nativeServer": "on" in settings.json resolves the issue.

I updated the issue. So using the Rust based version is a workaround. I'll try the updated ruff-lsp when it's out.

@jamesvrt
Copy link
Author

jamesvrt commented Sep 5, 2024

Do you see anything in the logs? Refer to the troubleshooting guide.

Sorry, I missed that bit. Logs:

2024-09-05 09:31:17.874 [info] [Trace - 9:31:17 AM] Sending request 'textDocument/rangeFormatting - (6)'.
2024-09-05 09:31:17.877 [info] [Trace - 9:31:17 AM] Received notification 'window/logMessage'.
2024-09-05 09:31:17.877 [info] Using interpreter executable: /home/jamesvrt/miniconda3/envs/test/bin/ruff
2024-09-05 09:31:17.877 [info] [Trace - 9:31:17 AM] Received notification 'window/logMessage'.
2024-09-05 09:31:17.877 [info] Found ruff 0.6.3 at /home/jamesvrt/miniconda3/envs/test/bin/ruff
2024-09-05 09:31:17.877 [info] [Trace - 9:31:17 AM] Received notification 'window/logMessage'.
2024-09-05 09:31:17.877 [info] Running Ruff with: /home/jamesvrt/miniconda3/envs/test/bin/ruff ['format', '--force-exclude', '--quiet', '--stdin-filename', '/home/jamesvrt/code/test/test.ipynb', '--config', 'line-length=120']

@dhruvmanila
Copy link
Member

@jamesvrt the new ruff-lsp version is out, can you try it out?

Although I don't see any error in the logs :(

@dhruvmanila
Copy link
Member

dhruvmanila commented Sep 5, 2024

Also, I'd recommend to switch over to the Rust based server as it has the same functionalities (+ a few more) with no additional installation and high performance :)

@jamesvrt
Copy link
Author

jamesvrt commented Sep 5, 2024

How do you get the VSCode extension to use the latest ruff-lsp? The latest extension version still uses the previous ruff-lsp and it doesn't pick up ruff-lsp in my Python environment, only ruff.

BTW, I'm content to use ruff rather than ruff-lsp since it's faster anyway.

@dhruvmanila
Copy link
Member

How do you get the VSCode extension to use the latest ruff-lsp? The latest extension version still uses the previous ruff-lsp and it doesn't pick up ruff-lsp in my Python environment, only ruff.

Ah right, sorry. I'd need to release a new VS Code extension as well.

@dhruvmanila
Copy link
Member

I've released a new extension version which should be available in a couple of minutes.

@HenryDashwood
Copy link

Just to say I've been having similar issues as the people above.

adding "ruff.nativeServer": "on" to my workspace's settings.json got ruff formatting my notebook cells again.

However, I'm on the latest version of your extension, v2024.44.0 so should setting that explicitly have been necessary?

I'm also on ruff 0.6.4 everywhere else and in the documentation I think it says that it should default to the native server without explicit setting?

@dhruvmanila
Copy link
Member

@HenryDashwood can you share the VS Code settings and Ruff logs? I just tested with 2024.44.0 VS Code with ruff.nativeServer: "off" and it works. And, it doesn't work when using ruff-lsp with 2024.42.0.

@jamesvrt
Copy link
Author

jamesvrt commented Sep 9, 2024

ruff-lsp still doesn't work for me with the VSCode extension version 2024.44.0. Logs:

2024-09-09 09:13:16.808 [info] Interpreter executable (/home/jamesvrt/miniconda3/envs/test/bin/ruff) not found
2024-09-09 09:13:16.808 [info] [Trace - 9:13:16 AM] Received notification 'window/logMessage'.
2024-09-09 09:13:16.808 [info] Falling back to bundled executable: /home/jamesvrt/.vscode/extensions/charliermarsh.ruff-2024.44.0-linux-x64/bundled/libs/bin/ruff
2024-09-09 09:13:16.808 [info] [Trace - 9:13:16 AM] Received notification 'window/logMessage'.
2024-09-09 09:13:16.808 [info] Found ruff 0.6.4 at /home/jamesvrt/.vscode/extensions/charliermarsh.ruff-2024.44.0-linux-x64/bundled/libs/bin/ruff
2024-09-09 09:13:16.808 [info] [Trace - 9:13:16 AM] Received notification 'window/logMessage'.
2024-09-09 09:13:16.808 [info] Running Ruff with: /home/jamesvrt/.vscode/extensions/charliermarsh.ruff-2024.44.0-linux-x64/bundled/libs/bin/ruff ['format', '--force-exclude', '--quiet', '--stdin-filename', '/home/jamesvrt/code/test/test.ipynb', '--config', 'line-length=120']
2024-09-09 09:13:16.812 [info] [Trace - 9:13:16 AM] Received response 'textDocument/rangeFormatting - (15)' in 6ms.

Appreciate your hard work with ruff btw!

@dhruvmanila
Copy link
Member

2024-09-09 09:13:16.812 [info] [Trace - 9:13:16 AM] Received response 'textDocument/rangeFormatting - (15)' in 6ms.

I think we don't support range formatting for Notebooks in ruff-lsp and that's only supported in the native server. Can you try running other formatting operations that apply on the entire notebook and verify? Although it might just be better to completely switch to the native server ;)

@jamesvrt
Copy link
Author

jamesvrt commented Sep 9, 2024

"Format Notebook", "Format Cell" and "Format Range" don't work, but "Ruff: Format document" (only available through ctrl+shift+P) does work. I need more granular control than document formatting, so I'll stick with the native server. Thanks!

You can set this to closed if this is expected behaviour, though it might be nice to mention it in the extension page or default to the native server.

@dhruvmanila
Copy link
Member

"Format Notebook", "Format Cell" and "Format Range" don't work, but "Ruff: Format document" (only available through ctrl+shift+P) does work.

Oh, that's unexpected and could very well be a bug in ruff-lsp. I think at least "Format Notebook" and "Format Cell" are suppose to work.

@dhruvmanila dhruvmanila transferred this issue from astral-sh/ruff-vscode Sep 9, 2024
@dhruvmanila dhruvmanila changed the title Notebook Format Selection/Cell/Document/Notebook not working with ruff-lsp Notebook Format Cell//Notebook not working with ruff-lsp Sep 9, 2024
@HenryDashwood
Copy link

@HenryDashwood can you share the VS Code settings and Ruff logs? I just tested with 2024.44.0 VS Code with ruff.nativeServer: "off" and it works. And, it doesn't work when using ruff-lsp with 2024.42.0.

Tried to replicate this evening and couldn't I'm afraid. But I guess that does mean it's working!

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

3 participants