microsoft / vscode-jupyter

VS Code Jupyter extension
https://marketplace.visualstudio.com/items?itemName=ms-toolsai.jupyter
MIT License
1.27k stars 284 forks source link

Jupyter notebook cell menu incorrect for new cells #15906

Open paul-rogers opened 1 month ago

paul-rogers commented 1 month ago

Jupyter notebook cells provide a pop-up mention at the top-left corner of cell when focus is on the cell. However, the content of the menu fails to update to reflect the current cell. This seems to be a UI event issue.

To reproduce, read these instructions on your phone or a separate window so you don't have to change focus from VS code while following along.

  1. Create a new notebook.
  2. In the top cell, type, say import sys. Notice that the cell menu contains "... <trashcan>".
  3. Switch focus away from VS code to another application window. Switch back. Now you see the full Python menu.
  4. Use the "+ Markdown" button to add a markdown cell. Type, "example". Notice that the cell menu contains the "<run by line>, <execute cells below>, <execute cells above>, ..., <trashcan>" items.
  5. Again switch focus to another application, then back to VS Code. Now you see the "<checkmark>, <split cell>, ..., <trashcan>" menu items.
  6. Use "+ Code" to add a Python cell. Notice that the menu again contains only "... <trashcan>".
  7. Again switch to another window and back. The proper Python menu appears.

I have found that, sometimes, I can get the menus to reset by clicking onto another cell and back. I find I must frequently do this when adding a Markdown cell.

Here is another variation:

  1. Add a Python cell. Type a = 10. Switch away from VS code and back again to get the proper menu.
  2. Add a Markdown cell below. Notice that the menu contains the Python cell menu items. Switch away and back to get the Markdown cell menu items.

Yet another variation. The above examples all added cells at the bottom. This time, we'll add one in the middle.

  1. Select your top Python cell. Add a Markdown cell. You will see the "<run by line>, <execute cells below>, <execute cells above>, ..., <trashcan>" menu.
  2. Switch away and back to get the Markdown menu.
  3. Add a Code cell below you Markdown cell. You'll get only the "..., <trashcan>" menu.
  4. Switch and and back to get the Python menu.
  5. Add another Markdown cell. This time you get the Markdown menu immediately.
  6. Add a Code cell. You'll get the proper Python menu.
  7. Add another Code cell. You'll get the Python menu but without the "Split Cell" item.
  8. Add another Code cell. Again the truncated menu.
  9. Click on the cell created in 6. Back to the Python menu.
  10. Click on the cell added in 7. Still the truncated menu.
  11. Click on the cell created in 6. Switch to another app and back to VS Code.
  12. Click on the cell added in 7. This time you get the full Python menu.

This behavior does not happen all the time. It only happens for new cells. If you click around your existing cells, you'll see that the cell menu is correct.

In short, it seems that the UI is not receiving some kind of UI event that tells it to switch the hover menu to the version for a newly created cell. The menu seems to lag a bit. We can force an update by switching application focus.

Workaround

Having incorrect menus is a nuisance. One can often get the correct menu by clicking on another cell, then back. Sometimes switching to another app and VS Code is necessary.

Environment data

About dialog information: ```text Version: 1.91.1 Commit: f1e16e1e6214d7c44d078b1f0607b2388f29d729 Date: 2024-07-09T22:08:12.169Z Electron: 29.4.0 ElectronBuildId: 9728852 Chromium: 122.0.6261.156 Node.js: 20.9.0 V8: 12.2.281.27-electron.0 OS: Linux x64 5.15.0-113-generic ``` - Jupyter Extension version (available under the Extensions sidebar): v2024.6.0 - Python Extension version (available under the Extensions sidebar): v2024.10.0 - OS (Windows | Mac | Linux distro) and version: Linux Mint 21.3 (also see above) - Python and/or Anaconda version: Python 3.10.12 - Type of virtual environment used (N/A | venv | virtualenv | conda | ...): N/A - Jupyter server running: N/A (VS-Code provided server)
paul-rogers commented 1 month ago

This issue also affects the left hand side ">" run menu for Python cells. Sometimes the "> v" pull-down does not appear for debugging. That is, the right-hand side contains only the ">" run triangle. Switching application windows, then switching back fixes the problem.

In addition, I observed the following which occurred after PyLance crashed due to a known bug that will be fixed in the next release. I don't see how the crash relates to the UI, however.

In the present case, clicking the "Debug" option did its thing, then the cell reverted to not having the debug pull-down. Switching application windows and back restored the pull-down.

Further, I decided to restart the notebook. However, the top Menu, where Restart is supposed to appear, did not contain the Restart button. An abbreviated set of options appeared instead. Again, switching application windows, and switching back to VS Code caused the full menu to appear.

DonJayamanne commented 1 month ago

Please can you share a screen recording of the issue. You can use gifcap.dev to record the screen into a gif file.

paul-rogers commented 1 month ago

@DonJayamanne, please see the attached recording. It isn't a GIF: It is a video in a zip file. In it I create a new notebook. The default Python cell has the wrong menu. It changes to the correct one after I select a Python environment from a popup. Then, I add a Markdown cell. Wrong menu. I switch to another app and back. The menu corrects itself.

Let me know if you need more detail.

Screen_Recording.zip

paul-rogers commented 1 month ago

Just upgraded to the latest VS Code. Menu fonts changed, as did some aspects of notebooks. However, the menu behavior described here is, unfortunately, the same.

A few more hints.

  1. Create a new notebook.
  2. In the default code cell, type import sys. Flip away and back so that the menu is correct.
  3. Below it add a Markdown cell. The menu is wrong. Type test. Flip away and back so the menu is correct.
  4. Select the code cell. Note the menu. Below the code cell, add a Markdown cell. Notice that the menu seems to be a variation of the previous code cell.
  5. Select the Markdown cell. Note the menu. Below this cell, add a Code cell. Notice that the menu seems to be a variation of the previous Markdown code cell.
  6. Select the earlier Markdown cell. The menu is correct. Select the just-added Markdown cell. The menu is wrong. (Be sure to not switch windows after step 3.)
  7. Do the same for the code cells.

An interesting aspect is that if we now delete a Markdown cell, and add a new one in its place, the menu is correct. But, if we add a Markdown cell at the end, the menu starts wrong.

All of this points to something about the menu display being out-of-sync with respect to the cell type. Maybe the menu is a floating object and it is not being informed when it is moved from one cell to another, if the cell is in a "new" state?

About info after the update ```text Version: 1.92.0 Commit: b1c0a14de1414fcdaa400695b4db1c0799bc3124 Date: 2024-07-31T23:26:45.634Z Electron: 30.1.2 ElectronBuildId: 9870757 Chromium: 124.0.6367.243 Node.js: 20.14.0 V8: 12.4.254.20-electron.0 OS: Linux x64 5.15.0-113-generic ```