Open bolliger32 opened 2 months ago
Huh, that is indeed the case. I wonder if it's a bug in VS Code, let me check if the editor is sending the request in the first place.
Hmm, VS Code isn't sending the code action request when a markdown cell is present. This is a bit worrying and could be related to the notebook selector filter here: https://github.com/astral-sh/ruff/blob/3e9c7adeeee639043686a1717a1683f6620efd2a/crates/ruff_server/src/server.rs#L335-L344
Let me look at this later today. Thanks for raising this issue!
Thanks for taking a look so quickly!
This might be related to https://github.com/microsoft/vscode/issues/216653
@bolliger32 Thanks for mentioning "notebook.source.organizeImports"
as a replacement for "source.organizeImports"
! I had no idea this existed, and since a few weeks I've had a bunch of import cells in notebooks turn to gibberish as well. It was quite annoying as the Undo action would also not consistently restore the original version.
I commented on the potentially related issue as well, but I'm experiencing the same issue; manually saving kicks off the importing, but doesn't actually organize the imports and instead creates gibberish.
Important to note though, our setup uses the following, unlike the original poster:
"notebook.formatOnSave.enabled": true,
"notebook.codeActionsOnSave": {
"source.organizeImports": "explicit"
},
Unfortunately, the VSCode issue doesn't seemed to have gained any traction quite yet, but fingers crossed!
It took me a little while, but I finally figured out the use of
notebook.source.fixAll
andnotebook.source.organizeImports
settings (instead of theirsource.*
counterparts) to prevent vscode from turning my import cells in jupyter notebooks into gibberish when using ruff as the formatter. However, it appears that when a notebook starts with a markdown cell (say, to title the notebook) and then has a python cell with imports after the markdown,notebook.source.organizeImports
doesn't work. Here are my relevant vscode settings:And here's the relevant part of my
pyproject.toml
file in the workspace open in vscode:I'm using ruff 0.6.2.
Side Note: If I use
source.organizeImports
instead ofnotebook.source.organizeImports
, it "works" in the sense that something happens, but the effect is to introduce gibberish. Here's an example of the "gibberish" that occurs when usingsource.*
instead ofnotebook.source.*
. The first screenshot is from "pre-save", the second is after saving once, and the third after saving a second time