kovisoft / slimv

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

Can slimv use ssh etc to connect to remote image ? #113

Closed kwccoin closed 2 years ago

kwccoin commented 3 years ago

Seems not as said. But why it can’t? Any tunnelling approach.

kovisoft commented 3 years ago

Slimv does not have any built-in support for encrypted communication between vim and the swank server. I think tunneling may work, but TBH I have never tried it. By default the swank server is using port 4005 (see slime/start-swank.lisp). So I think if you:

then slimv might be able to connect to the remote swank server.

Jach commented 2 years ago

At least for Common Lisp, SSH forwarding works. It's partially documented on the CL cookbook: https://lispcookbook.github.io/cl-cookbook/debugging.html#remote-debugging

In one of my experimental use cases, I ship a binary exe to my server and it serves some web pages with hunchentoot. In its loader I make sure to load and init swank (I don't think this is needed if instead you're using ASDF and specify :swank as a dependency)

(load "~/.vim/bundle/slimv/slime/swank-loader.lisp")
(swank-loader:init :delete nil
                   :reload nil
                   :load-contribs nil)

and I start it at the same time as I start my hunchentoot server:

(defvar *acceptor*) ; hunchentoot handle
(defun start-server (port)
  ; sorry, I don't remember why I initially included these and then commented them out
  ;(setf swank:*use-dedicated-output-stream* nil)
  ;(setf swank:*communication-style* :fd-handler)

  ; the key line:
  (swank:create-server :dont-close t)

  ; hunchentoot only:
  (setf *acceptor*
        (start (make-instance 'easy-acceptor :port port))))

After that, I launch the exe on the server in a screen session, and I can later connect with ssh -C -L4005:127.0.0.1:4005 myserver and so long as I don't have anything locally slimv's ,c will connect to the remote program and I can inspect and recompile stuff and so on.

kwccoin commented 2 years ago

At least for Common Lisp, SSH forwarding works. It's partially documented on the CL cookbook: https://lispcookbook.github.io/cl-cookbook/debugging.html#remote-debugging

In one of my experimental use cases, I ship a binary exe to my server and it serves some web pages with hunchentoot. In its loader I make sure to load and init swank (I don't think this is needed if instead you're using ASDF and specify :swank as a dependency)

(load "~/.vim/bundle/slimv/slime/swank-loader.lisp")
(swank-loader:init :delete nil
                   :reload nil
                   :load-contribs nil)

and I start it at the same time as I start my hunchentoot server:

(defvar *acceptor*) ; hunchentoot handle
(defun start-server (port)
  ; sorry, I don't remember why I initially included these and then commented them out
  ;(setf swank:*use-dedicated-output-stream* nil)
  ;(setf swank:*communication-style* :fd-handler)

  ; the key line:
  (swank:create-server :dont-close t)

  ; hunchentoot only:
  (setf *acceptor*
        (start (make-instance 'easy-acceptor :port port))))

After that, I launch the exe on the server in a screen session, and I can later connect with ssh -C -L4005:127.0.0.1:4005 myserver and so long as I don't have anything locally slimv's ,c will connect to the remote program and I can inspect and recompile stuff and so on.

I am trying to run two sbcl and two image. The program use 4545 to isolate the two swank. I am using slimv and remote ssh ok. But can this be done in two images with different port. In particular how can my gvim found the right swank.

the advice is to use .vimrc but there is only one per vim, wonder how and whether one can use two swank ports for two different sbcl images.

Thank in advance again for any advice.

kovisoft commented 2 years ago

Maybe this approach could work: override the g:swank_port option before opening the REPL buffer. Define two separate key mappings (e.g. ,1 and ,2) for opening the swank server on two different ports:

:noremap <silent> ,1 :let g:swank_port=4545 <bar> call SlimvConnectServer()<CR>
:noremap <silent> ,2 :let g:swank_port=4546 <bar> call SlimvConnectServer()<CR>

Then open swank on port 4545 by pressing ,1 and open swank on port 4546 by pressing ,2.

kwccoin commented 2 years ago

Thanks. Thanks and thanks. All goods!!!!!!


TL;dr

All good, except I use nmap. (I know nothing about vim but somehow the as the command noremap just not working; I check this https://stackoverflow.com/questions/3776117/what-is-the-difference-between-the-remap-noremap-nnoremap-and-vnoremap-mapping and as there is something call nmap I just try that. I guess I need to investigate a bit more; but it is not my focus).

That do the job and may I as a novice to this, add some conceptual and operational note. In particular, the key is your note on "before the REPL"

Let us concentrate on the second part :let g:swank_port=4545 call SlimvConnectServer()

vim will use that to connect to a different swank server by a different sbcl image. Hence, one has to do the in-package etc. anew.

The nmap is to map the keyboard using the lead-character "," in slimv case. It map ,1 to 4545 port (and you can see a message in the real to reflect this).

Typing this down as this is so far of my conceptual scope that I really ensure I can understand this a few months later. I think I need to re-fresh my understanding of load-compile-executive plus vim-repl-image ...

(P.S. It is like "ssh -C -L4005:127.0.0.1:4005 myserver" is so strange it is only last week I aware that I do not need to expose my web server on the Internet for my testing. I can just tunnel my SSH to 8080 from local host to AWS! I only aware the similarity, after re-reading this post. )

Sorry for such a long post. Just to say my gratitude if you read to here. Just to say again all thanks!!!!