Vigemus / iron.nvim

Interactive Repl Over Neovim
BSD 3-Clause "New" or "Revised" License
1.01k stars 81 forks source link

"Project-local" REPLs / dynamically detecting REPL settings? #195

Open gwerbin opened 3 years ago

gwerbin commented 3 years ago

Hi, thanks for the very useful plugin! I've found Iron to be a nice alternative to the (also excellent) Neoterm.

However, I don't see an obvious way to configure the REPL invocation dynamically.For example, I'd ideally like to have logic along these lines for a Python project (hypothetical code):

iron.core.add_repl_definitions({
  python = {
    dynamic = function(bufno)
      local venv_root = _py_find_venv_root()
      local pipenv_root = _py_find_pipenv_root()
      local pyproject_root = _py_find_pyproject_root()
      local poetry_root = _py_is_poetry(pyproject_root)

      local command
      if poetry_root then
        command = {"poetry", "run", "ipython", "--no-autoindent"}
      elseif pipenv_root then
        command = {"pipenv", "run", "ipython", "--no-autoindent"}
      elseif venv_root then
        command = {venv_root .. "/bin/ipython", "--no-autoindent"}
      end

      return {
        command = command
      }
    end
  }
})

I'd also want to do other things, like try to detect if ipython is available in the current env and use it only if present.

Is this kind of thing possible currently? It would be a really useful feature for working with GUI frontends to Neovim, which you don't necessarily want to have to start from within a shell session.

hkupty commented 3 years ago

I'm really glad iron is being useful for you!

I definitely think we wan get something dynamic working, but I don't think it was prioritized so far... Shouldn't be too hard to add there though..

I surely want to improve and make it easier for users to tailor the best possible individual experience, so dynamic configuration would definitely make sense, as well as providing functions for dynamically detecting binaries.

The issue is that, due to work and personal life, I couldn't focus on iron as much as it deserves. In fact, I'm super glad it is at a somewhat stable state now, because it is being useful for many people without needing patching or intense overlook from me. Hopefully I can change that situation in the future, but for now I can try to squeeze in a few improvements here and there.

I'll check if/how I can add dynamic config support. Thanks for the issue!

gwerbin commented 3 years ago

I totally understand your situation!

I started looking into the Iron source code and found it fairly readable. But I'm myself trying to spend more time with family and less time coding.

I think one thing that might help other people contribute would be some informal documentation of how Iron fits together internally, and what changes you already have planned. That way people don't have to spend as long familiarizing themselves with the codebase, and can do things like internal refactoring that won't be "offensive" or obstructive towards your other planned improvements.

hkupty commented 2 years ago

I've recently merged v3.0 which greatly simplifies how the repl is picked up. I can definitely foresee now adding repl providers instead of picking them up straight away. I'll bump this issue and try to fix this in the next iteration.