felix-starman

felix-starman

Someone please correct me if I’m wrong but I believe the use case here is that your language server, if using the same version of Elixir going forward, is running and compiles your application then it would serve that purpose for you.

Whether the LSPs do that yet with 1.18, I’m not sure but I believe that is the idea going forward

But yes, if you were editing without an LSP running, and no new request came in, then it would not be recompiled. You’d need some other OS process to watch and manually recompile on save.
The LSP approach is likely your best option though, since presumably you’d be in your editor anyway

2
Post #22
mjrusso

mjrusso

I haven’t tried 1.18 yet (waiting on Nixpkgs release, which should be imminent) but I would imagine that the following would do exactly what you want:

  • in one terminal: git ls-files | entr mix compile
  • run IEx in another terminal

(This particular example uses entr; here’s a nice writeup about it.)

4
Post #23
mjrusso

mjrusso

On the topic of the Nixpkgs release, there’s a discussion going on about what the policy should be for how to pair Erlang/OTP versions with Elixir (and other BEAM lang) updates.

My position is that Elixir should use the latest stable Erlang/OTP release at the time of release. (This is just the default, you can of course pick a different version if you’re inclined, it’s just extra work.) If anyone else has feedback please chime in here: elixir_1_18: init at 1.18.0 by ankhers · Pull Request #366645 · NixOS/nixpkgs · GitHub

2
Post #24
sodapopcan

sodapopcan

Type type I typed it was a joke. What was I typing? I have a lot type learn.

1
Post #25
josevalim

josevalim

Creator of Elixir

To confirm what others have already said, you can use fsevents or similar to watch your lib and run mix compile. Or in the future, when LSP is using the listeners too, they will automatically recompile, and then they will appear automatically in IEx. :slight_smile:

FWIW, that’s precisely why the option is named auto_reload and not auto_recompile!

10
Post #26
sodapopcan

sodapopcan

Type you :pray:

0
Post #27
arrowsmith

arrowsmith

Thanks for clarifying, everybody.

Based on these responses, I wrote up a short guide to the new :auto_reload feature. I hope people like it, and please tell me if I got anything wrong!

5
Post #28
josevalim

josevalim

Creator of Elixir

In case you want to go even deeper, you can note that previously, if you did this:

  1. Started iex -S mix
  2. Changed a file
  3. Called mix compile
  4. Called recompile() in IEx

recompile() would not pick up the new module at all, because it had already been compiled. Elixir v1.18 makes it so recompile() works consistently AND adds the auto_reload option. Overall, it is all about playing better with multiple OS processes. :slight_smile:

10
Post #29
olivermt

olivermt

Whaaaaat?? This explains some very rare absolute headscratchers where I have had to nuke the LS and build and go make ritual sacrifices to the old gods in the woods before it all just start magically working again.

Usually when rapidly prototyping new schema and just going ??? on me :sob: haven’t really thought about restarting iex since recompile returns :noop :joy:

5
Post #30
delitrem

delitrem

The following test was failed only once while I tested deterministic builds:

  1) test Unix cmd/3 by line (SystemTest)
     test/elixir/system_test.exs:196
     match (=) failed
     code:  assert {["hello", "world"], 0} = System.cmd("echo", ["-n", "hello\nworld"], into: [], lines: 3)
     left:  {["hello", "world"], 0}
     right: {["hello"], 0}
     stacktrace:
       test/elixir/system_test.exs:200: (test)
0
Post #31