cevado

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:

Most Liked

mauricio.szabo

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 :slight_smile:

mjrusso

mjrusso

Hi :wave: Thanks for pinging me. Some really great discussion here.

(For posterity: I just updated the nexREPL README to include a link to the simple demo I shared earlier today on Twitter, and to also link to this thread.)

Having been immersed in this for the past few days, a few thoughts:

  • The biggest advantage of working in the existing nREPL ecosystem (IMO) is access to the editor-specific clients. However, after surveying the landscape of existing client implementations, and excluding the ones that aren’t Clojure-exclusive, there’s not a lot of options.
  • Eval’ing the expression at the given point/cursor position is pretty essential. The clients I tested don’t send all the necessary information over-the-wire to properly implement this on the server (there are optional parameters in the nREPL protocol for the “eval” operation for the file name, line number, column number, etc., which conceivably could let you put the logic on the server, but you still run into trouble with handling unsaved files etc).
  • All that being said, the relative simplicity of the nREPL protocol means that it isn’t a huge stretch to build a custom client. But at that point, why not build something fully custom that directly integrates with IEx and doesn’t have any Clojure baggage?
  • I am bullish on the idea of mediating this through LSP (as described at a high level in the nexREPL README), where LSP is the protocol that a custom “eval code” code action is sent through, the LSP server figures out the context and exactly what code you need to eval, and then sends the code directly to an existing IEx session. This of course is only one path of many options, but it solves the client issues and could reasonably be something built in to a language server (which would really help with adoption).
cevado

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.

Where Next?

Popular in Proposals: Ideas Top

virinchi_cv
The Problem Phoenix 1.8 comes aggressively coupled with Daisy UI, a decision which many developers in the community have had mixed feelin...
New
beepboop
(re-post of: Feature idea: measure and expose socket latency · Issue #1890 · phoenixframework/phoenix_live_view · GitHub) This is relate...
New
andreamancuso
Hey folks, This might sound niche, but I think it’s worth bringing up - especially given Phoenix’s reputation for being lightweight, por...
New
boriscy
Hello I really love phoenix 1.8 and I think the new magic link generator is great but I find the remember me function unintuitive. I have...
New
hst337
Elixir compiler and language specification Purpose of the proposal Elixir language is in mature state and no breaking or heavy changes ar...
New
pelopo
Hi, Oficial docs got this wonderful feature to download the ePub version that we can chuck to our kindles and read it. Now we are in the...
New
zachdaniel
Something we do in various Ash packages is provide routes that the user forwards to in their own application. This is because we are deri...
New
lemaster
Currently we have stream_insert and stream that can either add new items to a stream or update existing items if they are already present...
New
i-n-g-m-a-r
When debug_errors: true javascript can be executed. <html> <body> <form id="xss" action="https://domain.com/NateMai...
New
knoebber
I started a new phoenix project with --no-tailwind and found friction: delete tailwind classes from core components delete tailwind cla...
New

Other popular topics Top

AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 43487 311
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 41989 114
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New

We're in Beta

About us Mission Statement