kovisoft / slimv

Official mirror of Slimv versions released on vim.org
454 stars 60 forks source link

Setting `syntax on` in Neovim causes error when connecting to SWANK #135

Closed crowdigit closed 6 months ago

crowdigit commented 10 months ago

Description

Connecting to SWANK with setting syntax on in Neovim causes error (see below logs).

How to Reproduce

  1. Install Neovim and package manager
    # Suppose Neovim is already installed
    # Install minpac in test Neovim profile directory
    export NVIM_APPNAME=nvim-test
    mkdir -p $XDG_CONFIG_HOME/$NVIM_APPNAME
    git clone https://github.com/k-takata/minpac.git ~/.config/$NVIM_APPNAME/pack/minpac/opt/minpac
  2. Edit Neovim config, here's minimal reproducible config

    " $XDG_CONFIG_HOME/$NVIM_APPNAME/init.vim
    packadd minpac
    
    call minpac#init()
    call minpac#add('k-takata/minpac', {'type': 'opt'})
    call minpac#add('kovisoft/slimv')
    
    syntax on

    After sourcing them, install packages by executing :call minpac#update()

  3. Open Lisp source file and try connect to SWANK using <C-,>
    env NVIM_APPNAME=nvim-test nvim ./foo.lisp

Comment

Executing syntax on on Neovim, actually does source syntax files as per their documentation.

This issue is not critical because Neovim enables syntax highlight by default. Weird though, what it does is sourcing syntax files (again I guess). I was unable to reproduce it with Vim.

Output

Getting SWANK connection info...
Error detected while processing function SlimvConnectServer[7]..SlimvConnectSwank[46]..SlimvSwankResponse[3]..provider#python3#
Call:                                                                   
line   18:                                                                                                              
Error invoking 'python_execute' on channel 3 (python3-script-host):
Traceback (most recent call last):                                                                       
  File "<string>", line 1, in <module>
NameError: name 'swank_output' is not defined
Error invoking 'python_execute' on channel 3 (python3-script-host):                                              
Traceback (most recent call last):                                 
  File "<string>", line 1, in <module>
NameError: name 'swank_response' is not defined
Error detected while processing function SlimvConnectServer[7]..SlimvConnectSwank[46]..SlimvSwankResponse:
line   20:                                                                        
E121: Undefined variable: s:swank_actions_pending
line   26:                      
E121: Undefined variable: s:swank_actions_pending
Error detected while processing function SlimvConnectServer[7]..SlimvConnectSwank[46]..SlimvSwankResponse[3]..provider#python3#
Call:
line   18:
Error invoking 'python_execute' on channel 3 (python3-script-host):
Traceback (most recent call last):
  File "<string>", line 1, in <module>
NameError: name 'swank_output' is not defined
Error invoking 'python_execute' on channel 3 (python3-script-host):
Traceback (most recent call last):
  File "<string>", line 1, in <module>
NameError: name 'swank_response' is not defined
Error detected while processing function SlimvConnectServer[7]..SlimvConnectSwank[46]..SlimvSwankResponse:
line   20:
E121: Undefined variable: s:swank_actions_pending
line   26:
E121: Undefined variable: s:swank_actions_pending
Error detected while processing function SlimvConnectServer[7]..SlimvConnectSwank[46]..SlimvSwankResponse[3]..provider#python3#
Call:
line   18:
Error invoking 'python_execute' on channel 3 (python3-script-host):
Traceback (most recent call last):
  File "<string>", line 1, in <module>
NameError: name 'swank_output' is not defined
Error invoking 'python_execute' on channel 3 (python3-script-host):
Traceback (most recent call last):
  File "<string>", line 1, in <module>
NameError: name 'swank_response' is not defined
Error detected while processing function SlimvConnectServer[7]..SlimvConnectSwank[46]..SlimvSwankResponse:
line   20:
E121: Undefined variable: s:swank_actions_pending
line   26:
E121: Undefined variable: s:swank_actions_pending
Error detected while processing function SlimvConnectServer[7]..SlimvConnectSwank[46]..SlimvSwankResponse[3]..provider#python3#
Call:
[38:5:121m-- More --
kovisoft commented 10 months ago

Thank you for the feedback and sorry for the late response. I had some hard time to install neovim on my ubuntu system, because of some incompatible dependencies in some python modules. After that I was unable to successfully install and configure minpac, maybe I did not fully understand all the steps you described. I don't have $XDG_CONFIG_HOME, so maybe I used the wrong directory, I don't know. At the end minpac compained about missing minpac#impl#update() that I was unable to find.

Is it possible that the issue can be reproduced without minpac and maybe just manually executing syntax on? Or do we really need to have a package manager? Is it really the syntax on line in the config that is causing the problem?

TBH I'm clueless. The error message you pasted here says that the python functions defined in swank.py are missing. This was called from SlimvConnectSwank(), but this function starts by first loading the python module, if script variable s:python_initialized is zero. So the python module initialization could in theory be skipped only if this script variable is already nozero. But whenever we source slimv.vim, this variable is cleared and set only after the python module is initialized. This is very strange.

crowdigit commented 10 months ago

Strange, I tried to reproduce the error without package manager, following :help.

export NVIM_APPNAME=nvim-test

mkdir ~/.local/share/"${NVIM_APPNAME}"/site/plugin
mv ~/Downloads/slimv-master ~/.local/share/"${NVIM_APPNAME}"/site/plugin/slimv
ls ~/.local/share/"${NVIM_APPNAME}"/site/plugin/slimv
# doc  ftdetect  ftplugin  indent  plugin  README.txt  slime  swank-clojure  syntax
Error detected while processing /home/asdf/.local/share/nvim-test/site/plugin/slimv/ftplugin/clojure/slimv-clojure.vim:
line  198:
E117: Unknown function: SlimvInitBuffer

Now another error occurs :thinking:, It happened with empty vimrc (init.vim)

cat ~/.config/nvim-test/init.vim
# " syntax on

My :checkhealth reports it has python3 enabled. And I thought syntax on was corrupting because without it, this error does not occur.

One more thing to note is, opening empty buffer and then opening lisp source does not issues the error. But only when nvim is executed with filename on command line. e.g.

# no error
nvim
# open file with :e
# ,C

# error occurs
nvim ./foo.lisp
# ,C
kovisoft commented 10 months ago

I'm not familiar with neovim, but I suppose it uses a directory structure similar to vim. In vim user vim files are usually located in ~/.vim in subdirectories like autoload, ftplugin, indent, plugin, syntax, etc. The slimv package also contains the same directory structure, which means that files in slimv/ftplugin should go into into ~/.vim/ftplugin, files in slimv/plugin should to into ~/vim/plugin, etc. You cannot put everything into e.g. ~/.vim/slimv subdirectory, because then vim would not find the proper files (vim searches for the ftplugin files in ~/.vim/ftplugin).

I assume that you have just put everything into a slimv subdirectory, and maybe that is why neovim does not find some of the files. But I'm just guessing, as I said, I'm not familiar with neovim, nor with the plugin managers in neovim.

I suggest that first you try to follow the basic logic for placing the plugin files, as described above or in the documentation, and check that you still have such issues that some of the scripts are not found/not loaded.

crowdigit commented 6 months ago

I think this issue is invalid. Since it only happens in non-standard vim and it is easy to work around and does not worth the effort to fix it.

I've been tumbling these days 😅, I couldn't afford time. I wanted to setup plugin in plain Vim way and reproduce the error, unfortunately it was too long times ago I setup Vim in the standard way.

Closing this issue due to being stale, invalid. I don't want to leave clutters on something I enjoy using.

sauercrowd commented 5 months ago

I ran into the same problem - for me it was unrelated of any syntax setting or empty/non-empty buffer. It turned out my system upgrade resulted in a missing neovim python package, leading to the python code failing and the variable being undefined.

To make sure it's set up correctly, check if the neovim package is installed, and also :checkhealth will tell you if there are any issues with the python setup in neovim