benlubas / molten-nvim

A neovim plugin for interactively running code with the jupyter kernel. Fork of magma-nvim with improvements in image rendering, performance, and more
GNU General Public License v3.0
398 stars 23 forks source link

Running several cells prompts for a kernel on every cell #208

Open serhez opened 3 weeks ago

serhez commented 3 weeks ago
`:checkhealth molten` ``` molten: require("molten.health").check() molten-nvim ~ - OK NeoVim >=0.9 - OK Python >=3.10 - OK Python module pynvim found - OK Python module jupyter-client found - OK Python module cairosvg found - OK Python module pnglatex found - OK Python module plotly found - OK Python module kaleido found - WARNING Optional python module pyperclip not found - ADVICE: - pip install pyperclip - OK Python module nbformat found - OK Python module pillow found ```
`:checkhealth provider` (the python parts) ``` provider.python: require("provider.python.health").check() Python 3 provider (optional) ~ - Using: g:python3_host_prog = "~/envs/nvim/bin/python" - Executable: /Users/ser/envs/nvim/bin/python - Python version: 3.10.4 - pynvim version: 0.4.3 - OK Latest pynvim is installed. Python virtualenv ~ - OK no $VIRTUAL_ENV ```

Description

When using molten and no kernel has been chosen yet, running the quarto-nvim functions run_below() and run_above() (and perhaps run_all(), as I haven't tested it) prompt the user for the desired kernel on every cell. Instead, running these functions should just prompt the user for choosing a kernel in the first cell being run. I opened an issue in quarto-nvim repo and the maintainers said this looked like a bug with molten.

Reproduction Steps

  1. Install molten and quarto-nvim.
  2. Open a multi-cell quarto file and use either of the commands run_below() or run_above().
  3. The user will be prompted with a kernel (via telescope, for example) and, after making a selection, the user will keep being prompted for kernel selections for as many times as cells it tried to run.

This does not look like a personal config-related issue, but I could provide my config for both plugins if needed.

Expected Behavior

Kernel selection should only happen once for a quarto (or any notebook type) buffer, whenever the first cell/range is run.

benlubas commented 2 weeks ago

I think the best way to fix this will be with some type of state check in here https://github.com/benlubas/molten-nvim/blob/47b9a56d4bc0f877ff9469910b9653c46d462db4/rplugin/python3/molten/__init__.py#L579 to see if we're waiting for a kernel to be ready, and if we are, just using that as the kernel. Might need a new variable to track that, not sure

benlubas commented 2 weeks ago

That actually should work right now, we start tracking the kernel immediately after :MoltenInit is called, and we do check for the kernel in the same way.

https://github.com/benlubas/molten-nvim/blob/47b9a56d4bc0f877ff9469910b9653c46d462db4/lua/prompt.lua#L62

But this schedule wrap ruins things...