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
547 stars 31 forks source link

[Bug] Invalid 'line': out of range #158

Closed bob3000 closed 7 months ago

bob3000 commented 7 months ago
`:checkhealth molten` molten-nvim ~ - OK NeoVim >=0.9 - OK Python >=3.10 - OK Python module pynvim found - OK Python module jupyter-client found - WARNING Optional python module cairosvg not found - ADVICE: - pip install cairosvg - WARNING Optional python module pnglatex not found - ADVICE: - pip install pnglatex - WARNING Optional python module plotly not found - ADVICE: - pip install plotly - WARNING Optional python module kaleido not found - ADVICE: - pip install kaleido - WARNING Optional python module pyperclip not found - ADVICE: - pip install pyperclip - WARNING Optional python module nbformat not found - ADVICE: - pip install nbformat
`:checkhealth provider` (the python parts) provider (optional) ~ - pyenv: Path: /opt/homebrew/Cellar/pyenv/2.3.36/libexec/pyenv - pyenv: Root: /Users/user/.pyenv - Using: g:python3_host_prog = "/Users/user/.pyenv/shims/python" - Executable: /Users/user/.pyenv/shims/python - Python version: 3.10.13 - pynvim version: 0.5.0 - OK Latest pynvim is installed. Python virtualenv ~ - OK no $VIRTUAL_ENV

Description

09:25:34 msg_show MoltenEvaluateVisual Error invoking '/Users/user/.local/share/nvim/lazy/molten-nvim/rplugin/python3/molten:command:MoltenEvaluateVisual' on channel 3 (python3-rplugin-host): error caught in request handler '/Users/user/.local/share/nvim/lazy/molten-nvim/rplugin/python3/molten:command:MoltenEvaluateVisual [[]]': Traceback (most recent call last): File "/Users/user/.local/share/nvim/lazy/molten-nvim/rplugin/python3/molten/utils.py", line 11, in inner func(self, args, kwargs) File "/Users/user/.local/share/nvim/lazy/molten-nvim/rplugin/python3/molten/init.py", line 497, in command_evaluate_visual self.kernel_check("MoltenEvaluateVisual %k", self.nvim.current.buffer) File "/Users/user/.local/share/nvim/lazy/molten-nvim/rplugin/python3/molten/init.py", line 586, in kernel_check self.nvim.command(c) File "/Users/user/.pyenv/versions/3.10.13/lib/python3.10/site-packages/pynvim/api/nvim.py", line 311, in command return self.request('nvim_command', string, kwargs) File "/Users/user/.pyenv/versions/3.10.13/lib/python3.10/site-packages/pynvim/api/nvim.py", line 199, in request res = self._session.request(name, args, kwargs) File "/Users/user/.pyenv/versions/3.10.13/lib/python3.10/site-packages/pynvim/msgpack_rpc/session.py", line 139, in request raise self.error_wrapper(err) pynvim.api.common.NvimError: function remote#define#CommandBootstrap[5]..remote#define#request[2]..remote#define#request, line 2: Vim(let):Error invoking '/Users/user/.local/share/nvim/lazy/molten-nvim/rplugin/python3/molten:command:MoltenEvaluateVisual' on channel 3 (python3-rplugin-host): error caught in request handler '/Users/user/.local/share/nvim/lazy/molten-nvim/rplugin/python3/molten:command:MoltenEvaluateVisual [['python3']]': Traceback (most recent call last): File "/Users/user/.local/share/nvim/lazy/molten-nvim/rplugin/python3/molten/utils.py", line 11, in inner func(self, *args, *kwargs) File "/Users/user/.local/share/nvim/lazy/molten-nvim/rplugin/python3/molten/init.py", line 512, in command_evaluate_visual self._do_evaluate(kernel, span) File "/Users/user/.local/share/nvim/lazy/molten-nvim/rplugin/python3/molten/init.py", line 317, in _do_evaluate DynamicPosition(self.nvim, self.extmark_namespace, bufno, pos[0]), File "/Users/user/.local/share/nvim/lazy/molten-nvim/rplugin/python3/molten/position.py", line 42, in init self.extmark_id = self.nvim.funcs.nvim_buf_set_extmark( File "/Users/user/.pyenv/versions/3.10.13/lib/python3.10/site-packages/pynvim/api/nvim.py", line 323, in call return self.request('nvim_call_function', name, args, kwargs) File "/Users/user/.pyenv/versions/3.10.13/lib/python3.10/site-packages/pynvim/api/nvim.py", line 199, in request res = self._session.request(name, *args, **kwargs) File "/Users/user/.pyenv/versions/3.10.13/lib/python3.10/site-packages/pynvim/msgpack_rpc/session.py", line 139, in request raise self.error_wrapper(err) pynvim.api.common.NvimError: Vim:E5555: API call: Invalid 'line': out of range

Reproduction Steps

test file

print("hello world")

execute commands with cursor on line 2

:MoltenInit :MoltenEvaluateVisual

config (added to LazyVim)

{
    "benlubas/molten-nvim",   
    lazy = false,
    version = "^1.0.0",     -- use version <2.0.0 to avoid breaking changes
    dependencies = { "3rd/image.nvim" },
    build = ":UpdateRemotePlugins",
    init = function()
      vim.g.molten_image_provider = "image.nvim"
      vim.g.molten_output_win_max_height = 20
    end,
  },

pip freeze

appnope==0.1.4
asttokens==2.4.1
comm==0.2.1
debugpy==1.8.1
decorator==5.1.1
exceptiongroup==1.2.0
executing==2.0.1
greenlet==3.0.3
ipykernel==6.29.3
ipython==8.22.1
jedi==0.19.1
jupyter_client==8.6.0
jupyter_core==5.7.1
matplotlib-inline==0.1.6
msgpack==1.0.4
nest-asyncio==1.6.0
packaging==23.2
parso==0.8.3
pexpect==4.9.0
pillow==10.2.0
platformdirs==4.2.0
prompt-toolkit==3.0.43
psutil==5.9.8
ptyprocess==0.7.0
pure-eval==0.2.2
Pygments==2.17.2
pynvim==0.5.0
python-dateutil==2.9.0.post0
pyzmq==25.1.2
six==1.16.0
stack-data==0.6.3
tornado==6.4
traitlets==5.14.1
wcwidth==0.2.13

Expected Behavior

Should evaluate to hello world

benlubas commented 7 months ago

Well, unsurprisingly, if you don't have a visual selection, :MoltenEvaluateVisual doesn't work. But it definitely shouldn't crash like that.

thank you for the bug report, I'd imagine this is an easy fix.

bob3000 commented 7 months ago

Thanks for the quick reply and the fix. I can confirm that the exception doesn't occur anymore. However it's it's still not working as expected for me.

What you say makes perfect sense. According to the name of the command the first thing I actually tried was to invoke it with a visual selection but I was and I'm still being told no range allowed šŸ¤·šŸ»ā€ā™‚ļø

Here is a quick video demonstration https://asciinema.org/a/Ho2PkfyeYIpbAyXnIygQkFSfL

benlubas commented 7 months ago

Yeah, it's weird. Inherited from magma. It uses the current visual selection, but you can't pass a range.

That's why it's called out in the README for being weird. You need to map it with :<c-u>MoltenEvaluateRange from visual mode (or you can type that manually obviously). <c-u> in the command line with just delete everything before the cursor, which will be the visual range in this case.

bob3000 commented 7 months ago

It is working now. Thanks a lot for your help šŸ™šŸ» You're doing a great job!