kovisoft / slimv

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

[SOLVED] Unable to start swank server in NixOS #120

Closed rollschild closed 2 years ago

rollschild commented 2 years ago

Hi,

I'm a Common Lisp beginner. I installed Slimv and sbcl. Now when I tried to evaluate a simple hello world lisp file using ,e, vim said Starting SWANK server... then after a few seconds returned error SWANK server is not running. Does anyone know how to fix this? Thank you so much!

kovisoft commented 2 years ago

When you start vim, type this command, this is the command for starting the swank server:

:echo SlimvSwankCommand()

What does it print? What happens if you try to manually enter the command that was printed in the OS shell command prompt (outside vim)? Does it start sbcl? If no command was printed at all, or if the command is wrong on your system, then sbcl autodetection fails. In this case you need to configure the command for starting the swank server in your .vimrc, e.g.:

let g:slimv_swank_cmd = '! xterm -e sbcl --load /usr/share/common-lisp/source/slime/start-swank.lisp &'

The above is just an example, see details in the documentation.

rollschild commented 2 years ago

Hi,

Thanks for the help.

When I open up a non-lisp file in NeoVim and type in :echo SlimvSwankCommand() it prints nothing (I think it's expected?). When I open up a lisp file and type in the command, it prints out

! xterm -e sbcl --load /nix/store/ccw0alq4m7zzx5rldrr280bkycnf2h1l-vimplugin-slimv-2021-08-24/slime/start-swank.lisp &

Now if I quit NeoVim and copy and paste that output in terminal, it successfully executes SBCL and loads the REPL for me.

I did set this in the Vim portion of my /etc/configuration.nix (the config used by NixOS):

let g:slimv_swank_cmd = "! xterm -e sbcl --load ${pkgs.vimPlugins.slimv}/slime/start-swank.lisp &"

So I think on the surface everything looks good? But if I open up a lisp file in NeoVim and type ,e to evaluate it, it would still say "Starting SWANK server..." then after a while "SWANK server is not running" for some reason.

kovisoft commented 2 years ago

What happens if you try to enter this command in the vim command line, i.e. if you press : then paste the above ! xterm ... command and press Enter? ! means that vim should open an OS shell and execute the external command that follows it. Well, that's true for "regular" vim, I have no experience with NeoVim, but I suppose it should behave the same way. Does any shell command work for you from within NeoVim, e.g. ! ls? Does a simple ! xterm & or ! xterm work?

Until the problem is resolved, a workaround can be that you manually start the swank server from the OS shell (outside of vim). When it's running, slimv should be able to connect to it upon pressing ,c or any evaluation shortcuts.

rollschild commented 2 years ago

Hi,

So I copied and pasted

! xterm -e sbcl --load /nix/store/ccw0alq4m7zzx5rldrr280bkycnf2h1l-vimplugin-slimv-2021-08-24/slime/start-swank.lisp &

into NeoVim command after : and hit Enter and nothing happened.

I typed :! ls and it showed me the correct output, but didn't open up a new shell. It just printed the output in the default Vim output area, at the bottom of Vim, as shown in this picture: IMG_20220302_205549

I typed in :! xterm, it did open up a new window, which was a shell. So I think this part works correctly. IMG_20220302_205628

If I omitted the & in the original command and typed it in NeoVim, it successfully opened up a new shell with SWANK server successfully connected. However, I don't know how to give control back to NeoVim to test whether I can actually connect to the server so I wasn't able to test.

IMG_20220302_205839

As you suggested, as a workaround, I could launch this command in terminal to open up a new shell and then open a lisp file separately in NeoVim. This worked perfectly well. I was able to connect to the server and evaluate.

So, to summarize, I guess the issue is somehow NeoVim couldn't detect or work with command like :! xterm some_command &, which, is supposed to run this command in the background?

rollschild commented 2 years ago

I posted a question in NeoVim's discourse forum: https://neovim.discourse.group/t/what-is-the-correct-recommended-way-to-run-a-shell-command-in-neovim-in-the-background/2130?u=rollschild. I will post here if there are any replies to that question.

kovisoft commented 2 years ago

Thank you for the feedback. Are you absolutely sure that the xterm command with & at the end really did nothing? & means the given command should be executed in the background and immediately return control to the calling process. Can you check what processes are running on your system? Maybe xterm is running but you cannot see it because it is running in the background. Well, that's the main purpose of & at the end of the swank command: the swank server should be started in the background, but control should be returned to vim.

rollschild commented 2 years ago

I figured it out.

I was right that the xterm command was never fired by that :! xterm .... & command in NeoVim. I was running a ps a | grep xterm command in the same tmux session and found nothing.

I had to use NeoVim's own job control mechanism to sort of "spawn" a process. What I added to /ect/configuration.nix was this:

            let g:slimv_swank_cmd = "call jobstart('xterm -e & sbcl --load ${pkgs.vimPlugins.slimv}/slime/start-swank.lisp')"

To non-NixOS users, it would be something like

let g:slimv_swank_cmd = "call jobstart('xterm -e & sbcl --load /usr/share/common-lisp/source/slime/start-swank.lisp')"

Basically, I just changed the original let g:slimv_swank_cmd = '! xterm -e sbcl --load /usr/share/common-lisp/source/slime/start-swank.lisp &' to a more NeoVim way.

You can consider this as closed now. Thanks for your help!

kovisoft commented 2 years ago

Great! Thank you for the feedback.