microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
163.79k stars 29.11k forks source link

VS Code does not send code action to LSP server on save when running on a notebook file #216653

Open snowsignal opened 4 months ago

snowsignal commented 4 months ago

Type: Bug

Ruff (a linting/formatting extension for Python) has been having an issue involving notebook documents not being formatted on save, even with the right configuration. After investigating, we determined that the issue was that VS Code was not sending a code action request to the LSP on save, which doesn't seem like the right behavior.

To reproduce, you'll first need to install the Ruff extension.

Next, add this to your settings.json:

{
  "editor.codeActionsOnSave": {
    "source.fixAll": "always",
    "source.organizeImports": "always"
  },
  "editor.formatOnSave": true,
  "notebook.formatOnSave.enabled": true,
  "notebook.codeActionsOnSave": {
    "notebook.source.fixAll": "explicit",
    "notebook.source.organizeImports": "explicit"
  },
}

Then, with the Ruff extension enabled, create or open a Jupyter notebook file that has unorganized imports. A simple example would be to have a single code cell that looks like the following:

import string
import functools

Then, manually save the notebook (Ctrl/Cmd+S). The imports are neither re-organized nor are they removed, which they should be. This works if you put it in a normal Python file - this only seems to happen with a Jupyter Notebook.

It seems that VS Code isn't sending any code actions during a manual save on a Jupyter Notebook, unlike normal files, where it does.

VS Code version: Code 1.90.1 (Universal) (611f9bfce64f25108829dd295f54a6894e87339d, 2024-06-11T21:02:41.372Z) OS version: Darwin arm64 23.5.0 Modes:

System Info |Item|Value| |---|---| |CPUs|Apple M3 Max (14 x 2400)| |GPU Status|2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
webgl: enabled
webgl2: enabled
webgpu: enabled| |Load (avg)|2, 3, 3| |Memory (System)|36.00GB (2.40GB free)| |Process Argv|--crash-reporter-id bb0f7ee6-0b5f-46b6-94a6-78414cb3a99f| |Screen Reader|no| |VM|0%|
Extensions (17) Extension|Author (truncated)|Version ---|---|--- tsl-problem-matcher|amo|0.6.2 ruff|cha|2024.28.0 vscode-eslint|dba|3.0.10 prettier-vscode|esb|10.4.0 file-icons|fil|1.1.0 insta|mit|1.0.7 debugpy|ms-|2024.6.0 python|ms-|2024.8.1 vscode-pylance|ms-|2024.6.1 jupyter|ms-|2024.5.0 jupyter-keymap|ms-|1.1.2 jupyter-renderers|ms-|1.0.18 vscode-jupyter-cell-tags|ms-|0.1.9 vscode-jupyter-slideshow|ms-|0.1.6 vscode-xml|red|0.27.1 rust-analyzer|rus|0.3.2002 vscode-lldb|vad|1.10.0 (1 theme extensions excluded)
A/B Experiments ``` vsliv368cf:30146710 vspor879:30202332 vspor708:30202333 vspor363:30204092 vscoreces:30445986 vscod805:30301674 binariesv615:30325510 vsaa593:30376534 py29gd2263:31024239 c4g48928:30535728 azure-dev_surveyone:30548225 2i9eh265:30646982 962ge761:30959799 pythongtdpath:30769146 welcomedialog:30910333 pythonidxpt:30866567 pythonnoceb:30805159 asynctok:30898717 pythontestfixt:30902429 pythonregdiag2:30936856 pythonmypyd1:30879173 2e7ec940:31000449 pythontbext0:30879054 accentitlementsc:30995553 dsvsc016:30899300 dsvsc017:30899301 dsvsc018:30899302 cppperfnew:31000557 dsvsc020:30976470 pythonait:31006305 jchc7451:31067544 chatpanelt:31048053 dsvsc021:30996838 724cj586:31013169 pythoncenvpt:31062603 a69g1124:31058053 dvdeprecation:31068756 pythonprt:31056678 dwnewjupyter:31046869 2f103344:31071589 ```
vscodenpa commented 4 months ago

Thanks for creating this issue! It looks like you may be using an old version of VS Code, the latest stable release is 1.90.2. Please try upgrading to the latest version and checking whether this issue remains.

Happy Coding!

snowsignal commented 4 months ago

@VSCodeTriageBot Confirmed that this also happens on 1.90.2.

bolliger32 commented 3 months ago

FWIW, I do get an action to occur with the above settings but it formats the cell into nonsense, rather than correctly sorting imports (currently using version 1.91.1)

matt-dies-tenet3 commented 4 days ago

FWIW, I do get an action to occur with the above settings but it formats the cell into nonsense, rather than correctly sorting imports (currently using version 1.91.1)

I am experiencing the same issue as @bolliger32 -- using the replication instructions from above and:

Version: 1.94.2 (Universal)
OS: Darwin arm64 24.0.0