cevado
Extending IEx to have nREPL capabilities
IEx is a very powerfull shell and it would be awesome to have all this power integrated inside a code editor. Clojure enables something like that with nREPL.
nrepl has a set of operations that it support. I think for Elixir a good initial point would be the IEx helpers and autocomplete.
what I envision is:
you can run IEx on “network mode”, this way there is a port where IEx can receive operations and eval it and return the result of the operation to the caller.
this way any language(lua for nvim, js for vscode, elisp for emacs) could have a client that issues those commands and can use the response to extend the capabilities of the editor.
difference from LSP:
language servers are limited to what the protocol allows you to do. in other words, if there is no way to expose a functionality through LSP to the editor, it won’t be available. in the other hand with a “network iex” we could handle all the IEx helpers and shell tools directly to the editor.
advantages of that approach:
new features and functionalities added to IEx could easily become new features and capabilities in the editor. instead of the herculean job of interfacing elixir functionalities to the LSP.
there other nrepl approaches:
it’s not listed there but there is a ruby one too:
Trending in Proposals: Ideas
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #performance










First 10 of 27 Posts
cevado
some stuff that would be possible with a nrepl that is impossible with LSP:
The initial objective here is to understand if this is a welcomed idea, we could discuss further details as the discussion moves forward.
sodapopcan
I would love this.
cevado
Stuff that would be possible and great to have in that scenario would be once IEx stablishes an interface for network, other tools could expose apis ready to be used from the editor. like running credo checks or execute a particular tests and put you on the line that broke for that test and show a pop up with the error. maybe a logger backend that once attached to a editor shows the log as a pop up under the line that logged it.
I think it’s possible to have a nrepl in elixir outside of IEx, but being it inside IEx, we could start decoupling some outputs from being exposed in the shell, this way it’s easier to send it to the editor. I belive there might be some stuff like that already in place for Livebook(i need to take a look in the code).
cevado
@mauricio.szabo that works on the nrepl for ruby and wrote the client for clojure nrepl on atom/pulsar did a video showing the powers of nrepl in ruby, i think that’s a good way to see how different and helpful a nrepl is from a usual language server.
mauricio.szabo
Author here, ask me anything :).
So, the project itself is not that hard. nREPL itself is very simple to implement, and even bencode is not that hard (having implemented it in Clojure and ClojureScript, in a purely functional way). It give a huge benefit to development, too.
The most complicated part, for Ruby at least, was (and still is) the actual editor part - parsing code and identifying where we are in the source, and what exactly do we need to evaluate, especially considering all special syntax that Ruby have.
For Ruby, things work quite well because the “binding” of the current “context” (like, inside a method which variables are visible, what are their values, etc) is first-class - meaning that I can “store” this binding in the nREPL side and then evaluate code as if I was still running that method (again, huge debugging capabilities here!). I don’t know how much IEx exposes, but considering that Elixir is a functional language, maybe we don’t even need these “hacks” because we don’t need to create a class, then set attributes, mutate stuff, before we can actually run some function
tj0
I remember there was an editor for clojure that allowed viewing of every variable of a call. Rather than doing an IO.inspect and re-running, the last variable was available.
It was a combination of debugger + editor of some kind…I think it was LightTable. Or perhaps emacs also supported it, but it has been roughly a decade, so I don’t remember anymore.
It seems that nREPL could support something like this, do you know if this type of functionality has been implemented for other languages?
cevado
I was thinking to approach it with the bare minimum, either json or just plain string(that would be elixir code), this way the editor could just work with interpolation and just use the responses back directly in the editor, with no encoding/decoding overhead.
I was thinking thinking to approach that with delegating it to the nrepl itself… since elixir has the
Code.Fragmentmodule. the idea was to send the current entire buffer and send the line+column that your command was being executed.I’ve actually just copied iex code and i’m trying to make it work with just simple socket and binaries for now, the worse part is that iex expects an executing shell to do it’s work(i guess it relies heavily on the erlang shell if i understood it correctly). i’m thinking to explore livebook code to see if it would be easier to start from there. I wish I had more free time to work on that
i’m planning to do a POC of this nrepl based on iex to write a good proposal to send in the language mailing list
mauricio.szabo
LightTable did offer a “watch variable” (I believe) that allowed you to check the contents of the variable, but you had to watch before running the code.
I know FlowStorm (not an editor, but a different kind of debugger) allows you to inspect everything without re-running, and it’s still in active development.
Lazuli (my project for Ruby) does basically the same - it allows you to inspect the contents of a variable without re-running anything, but it’ll show the variable after things happened - meaning that if you have a parameter called
a, and that is an empty array, and that gets mutated over and over (even outside the method) the only info Lazuli will have is the final, mutated version - not the original parameter (don’t know if there’s a way around that, to be honest).cevado
@joelwallis just pointed me to this
https://github.com/mjrusso/nexrepl
are you around @mjrusso ?
sodapopcan
It’s a shame there’s generally not more interest in this kind of thing, but what can you do ¯\(ツ)/¯ I used the REPL constantly when I was working in Rails, especially for debugging but also for spiking. I do find myself just doing puts debugging most of the time in Elixir since state is much easier to follow in FP. I also find myself spiking less in IEx because it’s a pain to work with for that purpose. This is frustrating because IEx is so good otherwise.
Perhaps it’s the idea that this could compete with LSP? Just guessing here. The cross-editor/cross-language is a very important problem LSP (mostly) solves, but for those of us who are power users of a single editor we never plan on ditching and only work in a few languages, the possibilities that this would open up are exciting.