chipsenkbeil / distant.nvim

🚧 (Alpha stage software) Edit files, run programs, and work with LSP on a remote machine from the comfort of your local environment 🚧
https://distant.dev
Apache License 2.0
1.2k stars 12 forks source link

vim-slime remote python anaconda env and distant? #79

Closed zippeurfou closed 1 year ago

zippeurfou commented 1 year ago

Hey there, I am trying to figure out if I can use this great plugin with my workflow. Right now my remote machine has anaconda virtual environment and on my neovim I have vim-slime. So a good workflow would be:

  1. allow vim-slime to connect to my ipython remote anaconda environment with vim-slime.
  2. Easily switch between anaconda remote environment. Ultimately I'd love to be able to execute remotely in a command conda list env, select my env in a nvim prompt and have lsp/vim-slime switch. This would be close to what vscode does.
  3. this one is out of scope for this ticket but I'd love to be able to run QuartoPreview (https://github.com/quarto-dev/quarto-nvim) or MarkdownPreview commands (https://github.com/iamcco/markdown-preview.nvim) as well. Having it behave like if it is local when it is actually executing it on the remote environment.

Sorry to ask for so much 😃. If anyone has guidance I'm sure this would help other python users. Best,

chipsenkbeil commented 1 year ago

@zippeurfou hey there and thanks for reaching out! I'm unfamiliar with vim-slime, but I took a look at this repository: https://github.com/jpalardy/vim-slime

If that's the right one, it seems that it supports any interface that you can send text to such as a REPL. If that's the case, then you should be able to use the v0.2 branch to do this via distant. It supports spawning a shell on the remote machine that is exposed via a neovim terminal. You might be able to use it in combination with the neovim terminal support.

With the v0.2 branch, you can spawn a terminal for a specific program via :DistantShell /remote/path/to/python. It just runs the distant cli in a neovim terminal, so I imagine you could just use it in a similar way to :terminal in neovim?

For the other plugins, you'd need some way to hook into how they access files/programs. If you can configure a custom program, then they can be set up to use distant.

Underneath, this plugin's v0.2 branch just calls the distant CLI by default to send data to the remote server and respond.

zippeurfou commented 1 year ago

Thanks for the quick answer. I actually use iron.nvim (https://github.com/hkupty/iron.nvim) but thought nvim slime was more popular. My bad ahah. I think from what you’re saying it’s basically doing a lua function that start a remote shell and then specifying it with whatever plug-in you use. Thanks. I will look for the other one. Much appreciated.

chipsenkbeil commented 1 year ago

Yes. I just added a function to make this a little easier. With iron.nvim, it looks like you would want to specify the repl definition to be the distant cli that will act as the remote program.

Use require('distant.state').client:shell():to_cmd({ cmd = 'python' }). The client is only available if you have used DistantLaunch or DistantConnect to establish a connection to the remote machine. I may expose this in a more friendly manner later, but you can try this out for now.

-- The following would print out the command that can be run locally to run python on your remote machine
print(vim.inspect(require('distant.state').client:shell():to_cmd({ cmd = 'python' })))

-- The above would print out a table like this, only if you have connected to your distant server
-- already via `DistantLaunch` or `DistantConnect`
--
-- { 
--     "distant", "client", "shell", 
--     "--unix-socket", "/path/to/nvim-8996.sock", 
--     "--windows-pipe", "nvim-5671", 
--     "--connection", "2377319893", 
--     "--", "python" 
-- }
zippeurfou commented 1 year ago

Thanks I'll give it a try whenever I can. Much appreciated.

chipsenkbeil commented 1 year ago

Going to close this out. You should be able to use #88 (wrap API) to do this more easily.

For your iron situation, I think something like this would work:

iron.setup {
  config = {
    -- Your repl definitions come here
    repl_definition = {
      sh = {
        -- Can be a table or a function that
        -- returns a table (see below)
        command = require("distant").wrap({ cmd = {"zsh"} })
      }
    },
  }
}