kiyoon / jupynium.nvim

Selenium-automated Jupyter Notebook that is synchronised with NeoVim in real-time.
MIT License
520 stars 15 forks source link

Add support for ipdb #76

Closed fecet closed 1 year ago

fecet commented 1 year ago

TIL there is a debugger in jupyter, namely, we can use

%debug

to enter most recent traceback, see https://ipython.readthedocs.io/en/stable/interactive/magics.html#magic-debug.

This feature is extremely useful for me, but currently I have to leave neovim and interact with ipdb command line in Jupyter. If there is a dap-like interface that can be opened in neovim, it would be a killer feature.

Normally, we may need to implement dap for ipykernel's pdb, but because jupynium runs through the browser, we only need to forward input from neovim and output from Jupyter.

This is a big request, but if you also find this feature useful, I am willing to do my best to provide help.

kiyoon commented 1 year ago

Thanks for the request!

I'd like to understand the use case, and set the expectations better.

Is it correct that you'd want to use this ipdb interface directly from the neovim?

image

But how complicated are the commands in ipdb, so you need to use vim keybinds for it? I might be wrong here, but is it as simple as p var, n, ... or do you use complicated commands so you'd need vim keybindings and Jupyter completion as well? Do you need arrow keys to scroll through the command history as well? For me, I wouldn't mind going to the browser and typing some commands, but your use case may be different.

fecet commented 1 year ago

Yes, I would like ipdb to be displayed as a terminal in neovim, where I can manipulate it within neovim. It is not important whether the output is displayed within neovim. image Most of the time, ipdb commands are simple, but ipdb can also input any Python command, and some variable names may be long. It would be convenient if it could communicate with neovim to obtain automatic completion.

Additionally, ipdb displays the filename and line number in trace, if we could directly jump to the corresponding code snippet, we could modify it directly and use the %autoreload magic to test the changes.

kiyoon commented 1 year ago

Instead of using %debug directly in the notebook, there must be a way to connect to an existing kernel with ipdb in terminal. If you can do this, probably there's no need for Jupynium's browser synchronisation?

fecet commented 1 year ago

You are pefectly right, but I could not locate any documentation on how to connect to an existing kernel in ipdb. I have opened an issue to address this matter https://github.com/gotcha/ipdb/issues/267.

kiyoon commented 1 year ago

I don't know if this could be relevant, but in this plugin (https://github.com/lkhphuc/jupyter-kernel.nvim/blob/main/rplugin/python3/jupyter_kernel/__init__.py) they have a minimal python code to connect to the exiting Jupyter kernel and get completion etc. Maybe there's a same way to connect to the kernel and do something else like opening directly in terminal?

If not, I think you can find a way to connect to the existing ipython/jupyter kernel and attach to it. Maybe it's not an issue with ipdb, but with ipython? And once you have the ipython ready you can just run %debug.

kiyoon commented 1 year ago

https://stackoverflow.com/questions/22447572/connect-terminal-ipython-to-existing-notebook-kernel

Maybe jupyter console --existing

fecet commented 1 year ago

It seems that jupyter_client can accomplish this task, but I haven't found a simple way to connect to an existing notebook. The jupyter console --existing option will freeze and throw a timeout error.

I will continue to investigate and see if it can meet my needs. Thank you for your reply.