elixir-sublime-syntax icon indicating copy to clipboard operation
elixir-sublime-syntax copied to clipboard

Mix Format: File triggers a full recompile

Open ocolot opened this issue 11 months ago β€’ 9 comments

Using Sublime Text 4169 on macOS 14.4 and asdf (elixir 1.16.1-otp-26, erlang 26.2.2), formatting a file triggers a full app recompile (and crash the web server started with mix phx.server in parallel). I guess the compilation in Sublime and in iTerm2 do not share the same compilation environment.

How to make sure Elixir Syntax uses the same compilation process as my default terminal?

Thanks

ocolot avatar Mar 18 '24 09:03 ocolot

Can you paste some logs? In what way does it crash the running process?

princemaple avatar Mar 18 '24 09:03 princemaple

It does not crash. It just takes seconds to recompile the whole Elixir project while it has already been compiled (server running in parallel).

What I do:

  • I start a server: mix phx.server
  • I format a file (the bottom drawer of Sublime Text opens and show the compilation (without cache) of the whole application)
  • I observe that my phoenix server is down when loading one of its webpage. Here is the error message:
Compilation errorConsole output is shown below.

** (RuntimeError) could not compile application: fala.

You must restart your server after changing the following files:

  * config/dev.exs
  * config/config.exs


    (phoenix 1.7.11) lib/phoenix/code_reloader/server.ex:236:
Phoenix.CodeReloader.Server.mix_compile_unless_stale_config/4
    (phoenix 1.7.11) lib/phoenix/code_reloader/server.ex:188:
Phoenix.CodeReloader.Server.mix_compile/5
    (phoenix 1.7.11) lib/phoenix/code_reloader/server.ex:74: anonymous
fn/4 in Phoenix.CodeReloader.Server.handle_call/3
    (phoenix 1.7.11) lib/phoenix/code_reloader/server.ex:295:
Phoenix.CodeReloader.Server.proxy_io/1
    (phoenix 1.7.11) lib/phoenix/code_reloader/server.ex:72:
Phoenix.CodeReloader.Server.handle_call/3
    (stdlib 5.2) gen_server.erl:1131: :gen_server.try_handle_call/4
    (stdlib 5.2) gen_server.erl:1160: :gen_server.handle_msg/6
    (stdlib 5.2) proc_lib.erl:241: :proc_lib.init_p_do_apply/3

On Mon, 18 Mar 2024 at 10:33, Po Chen @.***> wrote:

Can you paste some logs? In what way does it crash the running process?

β€” Reply to this email directly, view it on GitHub https://github.com/elixir-editors/elixir-sublime-syntax/issues/69#issuecomment-2003331727, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAPCQKAPVKNSLKXTWR567NDYY2YIJAVCNFSM6AAAAABE3F5VCKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMBTGMZTCNZSG4 . You are receiving this because you authored the thread.Message ID: @.***>

ocolot avatar Mar 18 '24 11:03 ocolot

If you did just format one of the config files, it's required to restart the app by phoenix. If you formatted some other files and saw this, then it's a bug.

princemaple avatar Mar 18 '24 12:03 princemaple

Thanks for your fast reply. I did not change the config. It’s a bug πŸ˜•

On Mon, 18 Mar 2024 at 13:10, Po Chen @.***> wrote:

If you did just format one of the config files, it's required to restart the app by phoenix. If you formatted some other files and saw this, then it's a bug.

β€” Reply to this email directly, view it on GitHub https://github.com/elixir-editors/elixir-sublime-syntax/issues/69#issuecomment-2003744997, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAPCQKDHSFQVRP7LOUFDEV3YY3KRVAVCNFSM6AAAAABE3F5VCKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMBTG42DIOJZG4 . You are receiving this because you authored the thread.Message ID: @.***>

ocolot avatar Mar 18 '24 13:03 ocolot

Does it always happen or only the first time?

princemaple avatar Mar 19 '24 02:03 princemaple

Always. I mean, whenever I recompile the server, it recompiles for formatting and vice-versa.

On Tue, 19 Mar 2024 at 03:12, Po Chen @.***> wrote:

Does it always happen or only the first time?

β€” Reply to this email directly, view it on GitHub https://github.com/elixir-editors/elixir-sublime-syntax/issues/69#issuecomment-2005613628, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAPCQKCHIFNAIOYPZAJY2QTYY6NJ5AVCNFSM6AAAAABE3F5VCKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMBVGYYTGNRSHA . You are receiving this because you authored the thread.Message ID: @.***>

ocolot avatar Mar 19 '24 18:03 ocolot

Yeah, I think the issue is that Sublime and iTerm2 don't share the same environment. The Phoenix server is (most likely) compiled and started by the asdf-installed version of Elixir. I don't know about macOS, but you should be able to start Sublime from that iTerm2 shell to give it the same environment. I hope that's an acceptable workaround for now.

I don't know what the proper solution would be yet. Maybe it is to make the mix_format palette command aware of the .tool-versions file or of asdf and run mix accordingly. Or maybe it's adding settings to the command so the user can configure mix_format for each project individually.

There's something related that I noticed: I'm not using asdf, but when I run the tests from the CLI and then from Sublime it still compiles everything again, even though the Elixir version is the same. Quite annoying! I wish I had fun investigating this, but at the moment I'm busy with other things that are more fun. :sweat_smile:

azizk avatar Mar 19 '24 20:03 azizk

Another option is use LSP and LSP-elixir, so that you use the language server to format the code, instead of using the current app environment, which triggers recompilation.

princemaple avatar Mar 20 '24 00:03 princemaple

Using the LSP formatter works as expected. Thanks for the advice.

On Wed, Mar 20, 2024 at 1:42β€―AM Po Chen @.***> wrote:

Another option is use LSP and LSP-elixir, so that you use the language server to format the code, instead of using the current app environment, which triggers recompilation.

β€” Reply to this email directly, view it on GitHub https://github.com/elixir-editors/elixir-sublime-syntax/issues/69#issuecomment-2008425292, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAPCQKFSNY2DDI7QGO3ESK3YZDLNRAVCNFSM6AAAAABE3F5VCKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMBYGQZDKMRZGI . You are receiving this because you authored the thread.Message ID: @.***>

ocolot avatar Mar 22 '24 17:03 ocolot