VSCode Notebooks using notebook.codeActionsOnSave setting removes whole cell
rbange opened this issue · comments
Roman Bange commented
Problem:
While saving, the whole code is removed from the cell. So import os
is removed
Steps to Reproduce:
I have a pretty simple demo setup:
settings.json:
{
"notebook.formatOnSave.enabled": true,
"notebook.codeActionsOnSave": {
"source.fixAll": "explicit",
"source.organizeImports": "explicit"
},
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff"
}
}
test.ipynb:
Cell 1:
import os
import json
Cell 2:
os.getcwd()
json.loads('{"test":1}')
Ruff Output:
2023-12-11 17:47:46.093 [info] [Trace - 17:47:46] Sending request 'textDocument/codeAction - (40)'.
2023-12-11 17:47:46.096 [info] [Trace - 17:47:46] Received response 'textDocument/codeAction - (40)' in 3ms.
2023-12-11 17:47:46.227 [info] [Trace - 17:47:46] Sending request 'textDocument/codeAction - (41)'.
2023-12-11 17:47:46.228 [info] [Trace - 17:47:46] Sending request 'textDocument/codeAction - (42)'.
2023-12-11 17:47:46.229 [info] [Trace - 17:47:46] Sending request 'textDocument/codeAction - (43)'.
2023-12-11 17:47:46.230 [info] [Trace - 17:47:46] Received notification 'window/logMessage'.
2023-12-11 17:47:46.230 [info] Using interpreter executable: PATHTORUFFTEST/ruff-test/.venv/bin/ruff
2023-12-11 17:47:46.230 [info] [Trace - 17:47:46] Received notification 'window/logMessage'.
2023-12-11 17:47:46.230 [info] Found ruff 0.1.7 at PATHTORUFFTEST/ruff-test/.venv/bin/ruff
2023-12-11 17:47:46.231 [info] [Trace - 17:47:46] Received notification 'window/logMessage'.
2023-12-11 17:47:46.231 [info] Running Ruff with: PATHTORUFFTEST/ruff-test/.venv/bin/ruff ['--force-exclude', '--no-cache', '--no-fix', '--quiet', '--output-format', 'json', '-', '--fix', '--stdin-filename', 'PATHTORUFFTEST/ruff-test/test.ipynb']
2023-12-11 17:47:46.243 [info] [Trace - 17:47:46] Received notification 'window/logMessage'.
2023-12-11 17:47:46.243 [info] Using interpreter executable: PATHTORUFFTEST/ruff-test/.venv/bin/ruff
2023-12-11 17:47:46.243 [info] [Trace - 17:47:46] Received notification 'window/logMessage'.
2023-12-11 17:47:46.244 [info] Found ruff 0.1.7 at PATHTORUFFTEST/ruff-test/.venv/bin/ruff
2023-12-11 17:47:46.244 [info] [Trace - 17:47:46] Received notification 'window/logMessage'.
2023-12-11 17:47:46.244 [info] Running Ruff with: PATHTORUFFTEST/ruff-test/.venv/bin/ruff ['--force-exclude', '--no-cache', '--no-fix', '--quiet', '--output-format', 'json', '-', '--fix', '--stdin-filename', 'PATHTORUFFTEST/ruff-test/test.ipynb']
2023-12-11 17:47:46.260 [info] [Trace - 17:47:46] Received notification 'window/logMessage'.
2023-12-11 17:47:46.260 [info] Using interpreter executable: PATHTORUFFTEST/ruff-test/.venv/bin/ruff
2023-12-11 17:47:46.260 [info] [Trace - 17:47:46] Received notification 'window/logMessage'.
2023-12-11 17:47:46.260 [info] Found ruff 0.1.7 at PATHTORUFFTEST/ruff-test/.venv/bin/ruff
2023-12-11 17:47:46.260 [info] [Trace - 17:47:46] Received notification 'window/logMessage'.
2023-12-11 17:47:46.261 [info] Running Ruff with: PATHTORUFFTEST/ruff-test/.venv/bin/ruff ['--force-exclude', '--no-cache', '--no-fix', '--quiet', '--output-format', 'json', '-', '--fix', '--stdin-filename', 'PATHTORUFFTEST/ruff-test/test.ipynb']
2023-12-11 17:47:46.267 [info] [Trace - 17:47:46] Received notification 'window/logMessage'.
2023-12-11 17:47:46.268 [info] []
2023-12-11 17:47:46.268 [info] [Trace - 17:47:46] Received response 'textDocument/codeAction - (41)' in 41ms.
2023-12-11 17:47:46.269 [info] [Trace - 17:47:46] Received notification 'window/logMessage'.
2023-12-11 17:47:46.269 [info] [
{
"cell": 1,
"code": "F821",
"end_location": {
"column": 3,
"row": 1
},
"filename": "PATHTORUFFTEST/ruff-test/test.ipynb",
"fix": null,
"location": {
"column": 1,
"row": 1
},
"message": "Undefined name `os`",
"noqa_row": 1,
"url": "https://docs.astral.sh/ruff/rules/undefined-name"
},
{
"cell": 1,
"code": "F821",
"end_location": {
"column": 5,
"row": 2
},
"filename": "PATHTORUFFTEST/ruff-test/test.ipynb",
"fix": null,
"location": {
"column": 1,
"row": 2
},
"message": "Undefined name `json`",
"noqa_row": 2,
"url": "https://docs.astral.sh/ruff/rules/undefined-name"
}
]
2023-12-11 17:47:46.269 [info] [Trace - 17:47:46] Received response 'textDocument/codeAction - (42)' in 41ms.
2023-12-11 17:47:46.271 [info] [Trace - 17:47:46] Sending notification 'notebookDocument/didChange'.
2023-12-11 17:47:46.276 [info] [Trace - 17:47:46] Received notification 'window/logMessage'.
2023-12-11 17:47:46.276 [info] Using interpreter executable: PATHTORUFFTEST/ruff-test/.venv/bin/ruff
2023-12-11 17:47:46.277 [info] [Trace - 17:47:46] Sending request 'textDocument/codeAction - (44)'.
2023-12-11 17:47:46.277 [info] [Trace - 17:47:46] Received notification 'window/logMessage'.
2023-12-11 17:47:46.277 [info] Found ruff 0.1.7 at PATHTORUFFTEST/ruff-test/.venv/bin/ruff
2023-12-11 17:47:46.277 [info] [Trace - 17:47:46] Received notification 'window/logMessage'.
2023-12-11 17:47:46.278 [info] Running Ruff with: PATHTORUFFTEST/ruff-test/.venv/bin/ruff ['--force-exclude', '--no-cache', '--no-fix', '--quiet', '--output-format', 'json', '-', '--stdin-filename', 'PATHTORUFFTEST/ruff-test/test.ipynb']
2023-12-11 17:47:46.287 [info] [Trace - 17:47:46] Received notification 'window/logMessage'.
2023-12-11 17:47:46.287 [info] []
2023-12-11 17:47:46.288 [info] [Trace - 17:47:46] Received response 'textDocument/codeAction - (43)' in 59ms.
2023-12-11 17:47:46.289 [info] [Trace - 17:47:46] Received notification 'window/logMessage'.
2023-12-11 17:47:46.289 [info] Using interpreter executable: PATHTORUFFTEST/ruff-test/.venv/bin/ruff
2023-12-11 17:47:46.290 [info] [Trace - 17:47:46] Received notification 'window/logMessage'.
2023-12-11 17:47:46.290 [info] Found ruff 0.1.7 at PATHTORUFFTEST/ruff-test/.venv/bin/ruff
2023-12-11 17:47:46.290 [info] [Trace - 17:47:46] Received notification 'window/logMessage'.
2023-12-11 17:47:46.290 [info] Running Ruff with: PATHTORUFFTEST/ruff-test/.venv/bin/ruff ['--force-exclude', '--no-cache', '--no-fix', '--quiet', '--output-format', 'json', '-', '--fix', '--select', 'I001', '--stdin-filename', 'PATHTORUFFTEST/ruff-test/test.ipynb']
2023-12-11 17:47:46.294 [info] [Trace - 17:47:46] Sending request 'textDocument/codeAction - (45)'.
2023-12-11 17:47:46.303 [info] [Trace - 17:47:46] Received notification 'window/logMessage'.
2023-12-11 17:47:46.303 [info] Using interpreter executable: PATHTORUFFTEST/ruff-test/.venv/bin/ruff
2023-12-11 17:47:46.303 [info] [Trace - 17:47:46] Received notification 'window/logMessage'.
2023-12-11 17:47:46.304 [info] Found ruff 0.1.7 at PATHTORUFFTEST/ruff-test/.venv/bin/ruff
2023-12-11 17:47:46.304 [info] [Trace - 17:47:46] Received notification 'window/logMessage'.
2023-12-11 17:47:46.304 [info] Running Ruff with: PATHTORUFFTEST/ruff-test/.venv/bin/ruff ['--force-exclude', '--no-cache', '--no-fix', '--quiet', '--output-format', 'json', '-', '--fix', '--select', 'I001', '--stdin-filename', 'PATHTORUFFTEST/ruff-test/test.ipynb']
2023-12-11 17:47:46.312 [info] [Trace - 17:47:46] Received notification 'textDocument/publishDiagnostics'.
2023-12-11 17:47:46.313 [info] [Trace - 17:47:46] Received notification 'textDocument/publishDiagnostics'.
2023-12-11 17:47:46.313 [info] [Trace - 17:47:46] Received notification 'textDocument/publishDiagnostics'.
2023-12-11 17:47:46.314 [info] [Trace - 17:47:46] Sending request 'textDocument/codeAction - (46)'.
2023-12-11 17:47:46.315 [info] [Trace - 17:47:46] Received notification 'window/logMessage'.
2023-12-11 17:47:46.315 [info] []
2023-12-11 17:47:46.315 [info] [Trace - 17:47:46] Received response 'textDocument/codeAction - (44)' in 38ms.
2023-12-11 17:47:46.318 [info] [Trace - 17:47:46] Received notification 'window/logMessage'.
2023-12-11 17:47:46.319 [info] Using interpreter executable: PATHTORUFFTEST/ruff-test/.venv/bin/ruff
2023-12-11 17:47:46.319 [info] [Trace - 17:47:46] Received notification 'window/logMessage'.
2023-12-11 17:47:46.319 [info] Found ruff 0.1.7 at PATHTORUFFTEST/ruff-test/.venv/bin/ruff
2023-12-11 17:47:46.320 [info] [Trace - 17:47:46] Received notification 'window/logMessage'.
2023-12-11 17:47:46.320 [info] Running Ruff with: PATHTORUFFTEST/ruff-test/.venv/bin/ruff ['--force-exclude', '--no-cache', '--no-fix', '--quiet', '--output-format', 'json', '-', '--fix', '--select', 'I001', '--stdin-filename', 'PATHTORUFFTEST/ruff-test/test.ipynb']
2023-12-11 17:47:46.327 [info] [Trace - 17:47:46] Received notification 'window/logMessage'.
2023-12-11 17:47:46.327 [info] []
2023-12-11 17:47:46.327 [info] [Trace - 17:47:46] Received response 'textDocument/codeAction - (45)' in 33ms.
2023-12-11 17:47:46.335 [info] [Trace - 17:47:46] Received notification 'window/logMessage'.
2023-12-11 17:47:46.336 [info] []
2023-12-11 17:47:46.336 [info] [Trace - 17:47:46] Received response 'textDocument/codeAction - (46)' in 22ms.
2023-12-11 17:47:46.350 [info] [Trace - 17:47:46] Sending request 'textDocument/formatting - (47)'.
2023-12-11 17:47:46.350 [info] [Trace - 17:47:46] Sending request 'textDocument/formatting - (48)'.
2023-12-11 17:47:46.351 [info] [Trace - 17:47:46] Sending request 'textDocument/formatting - (49)'.
2023-12-11 17:47:46.365 [info] [Trace - 17:47:46] Received notification 'window/logMessage'.
2023-12-11 17:47:46.365 [info] Using interpreter executable: PATHTORUFFTEST/ruff-test/.venv/bin/ruff
2023-12-11 17:47:46.366 [info] [Trace - 17:47:46] Received notification 'window/logMessage'.
2023-12-11 17:47:46.366 [info] Found ruff 0.1.7 at PATHTORUFFTEST/ruff-test/.venv/bin/ruff
2023-12-11 17:47:46.367 [info] [Trace - 17:47:46] Received notification 'window/logMessage'.
2023-12-11 17:47:46.368 [info] Running Ruff with: PATHTORUFFTEST/ruff-test/.venv/bin/ruff ['format', '--force-exclude', '--quiet', '--stdin-filename', 'PATHTORUFFTEST/ruff-test/test.ipynb']
2023-12-11 17:47:46.382 [info] [Trace - 17:47:46] Received notification 'window/logMessage'.
2023-12-11 17:47:46.382 [info] Using interpreter executable: PATHTORUFFTEST/ruff-test/.venv/bin/ruff
2023-12-11 17:47:46.382 [info] [Trace - 17:47:46] Received notification 'window/logMessage'.
2023-12-11 17:47:46.382 [info] Found ruff 0.1.7 at PATHTORUFFTEST/ruff-test/.venv/bin/ruff
2023-12-11 17:47:46.382 [info] [Trace - 17:47:46] Received notification 'window/logMessage'.
2023-12-11 17:47:46.382 [info] Running Ruff with: PATHTORUFFTEST/ruff-test/.venv/bin/ruff ['format', '--force-exclude', '--quiet', '--stdin-filename', 'PATHTORUFFTEST/ruff-test/test.ipynb']
2023-12-11 17:47:46.392 [info] [Trace - 17:47:46] Received notification 'window/logMessage'.
2023-12-11 17:47:46.392 [info] Using interpreter executable: PATHTORUFFTEST/ruff-test/.venv/bin/ruff
2023-12-11 17:47:46.393 [info] [Trace - 17:47:46] Received notification 'window/logMessage'.
2023-12-11 17:47:46.393 [info] Found ruff 0.1.7 at PATHTORUFFTEST/ruff-test/.venv/bin/ruff
2023-12-11 17:47:46.393 [info] [Trace - 17:47:46] Received notification 'window/logMessage'.
2023-12-11 17:47:46.393 [info] Running Ruff with: PATHTORUFFTEST/ruff-test/.venv/bin/ruff ['format', '--force-exclude', '--quiet', '--stdin-filename', 'PATHTORUFFTEST/ruff-test/test.ipynb']
2023-12-11 17:47:46.400 [info] [Trace - 17:47:46] Received response 'textDocument/formatting - (47)' in 50ms.
2023-12-11 17:47:46.401 [info] [Trace - 17:47:46] Received response 'textDocument/formatting - (48)' in 51ms.
2023-12-11 17:47:46.407 [info] [Trace - 17:47:46] Received response 'textDocument/formatting - (49)' in 56ms.
2023-12-11 17:47:46.478 [info] [Trace - 17:47:46] Sending notification 'notebookDocument/didSave'.
2023-12-11 17:47:46.482 [info] [Trace - 17:47:46] Received notification 'window/logMessage'.
2023-12-11 17:47:46.482 [info] Using interpreter executable: PATHTORUFFTEST/ruff-test/.venv/bin/ruff
2023-12-11 17:47:46.483 [info] [Trace - 17:47:46] Received notification 'window/logMessage'.
2023-12-11 17:47:46.483 [info] Found ruff 0.1.7 at PATHTORUFFTEST/ruff-test/.venv/bin/ruff
2023-12-11 17:47:46.483 [info] [Trace - 17:47:46] Received notification 'window/logMessage'.
2023-12-11 17:47:46.483 [info] Running Ruff with: PATHTORUFFTEST/ruff-test/.venv/bin/ruff ['--force-exclude', '--no-cache', '--no-fix', '--quiet', '--output-format', 'json', '-', '--stdin-filename', 'PATHTORUFFTEST/ruff-test/test.ipynb']
2023-12-11 17:47:46.499 [info] [Trace - 17:47:46] Received notification 'textDocument/publishDiagnostics'.
2023-12-11 17:47:46.500 [info] [Trace - 17:47:46] Received notification 'textDocument/publishDiagnostics'.
2023-12-11 17:47:46.500 [info] [Trace - 17:47:46] Received notification 'textDocument/publishDiagnostics'.
2023-12-11 17:47:46.789 [info] [Trace - 17:47:46] Sending request 'textDocument/codeAction - (50)'.
2023-12-11 17:47:46.793 [info] [Trace - 17:47:46] Received response 'textDocument/codeAction - (50)' in 3ms
Versions:
ruff --version
: ruff 0.1.7
code --version
: 1.85.0
Ruff Vscode: v2023.50.0
Dhruv Manilawala commented
Hey, thanks for the detailed issue. I'm sorry that you're facing this problem, it has been highlighted to us multiple times (astral-sh/ruff-lsp#320) and I'll try to fix it this week. Closing this in favor of the linked issue.