Skip to content

Conversation

mhanberg
Copy link
Member

@mhanberg mhanberg commented Jul 7, 2023

This adds a new CLI option to mix run that will skip loading the runtime.exs file.

This is useful when you want to load a VM with all of the project's code and dependencies, but don't want to actually start it in any way.

runtime.exs can use your project's dependencies, which might not be compiled yet if also using the --no-compile option.

Normally you can simply gate your entire runtime.exs file in a condition that checks for an environment variable, but in the case of developer tooling like a language server, you can't alter the code.


I'm not entirely sure if this is the best way to solve my problem, so I am interested in your thoughts here. I thought about
re-using the --no-start option to control whether the runtime.exs is executed, but I figured that is a backwards incompatible change, so I opted for a new option.

(If you think this is reasonable to include, I will add tests/docs)

For more context, I have run into a situation in Next LS where a user's runtime.exs fails due to the code not yet being compiled (because I are using the --no-compile flag).

I am intentionally not wanting any code to 'run', which is why I also pass the --no-start flag, which I think made me surprised that runtime.exs still ran.

LMKWYT

This adds a new CLI option to `mix run` that will skip loading the
runtime.exs file.

This is useful when you want to load a VM with all of the project's code
and dependencies, but don't want to actually start it in any way.

runtime.exs can use your project's dependencies, which might not be
compiled yet if also using the `--no-compile` option.

Normally you can simply gate your entire runtime.exs file in a condition
that checks for an environment variable, but in the case of developer
tooling like a language server, you can't alter the code.
@josevalim
Copy link
Member

@mhanberg what task are you invoking as the entry point? If you don't want it to not start nor compile, then maybe you should be calling only the loadpaths task and not any task that may start or compile code? For example, here is what we do for mix help:

    args = ["--no-elixir-version-check", "--no-deps-check", "--no-archives-check"]
    Mix.Task.run("loadpaths", args)
    Mix.Task.reenable("loadpaths")
    Mix.Task.reenable("deps.loadpaths")

@mhanberg
Copy link
Member Author

mhanberg commented Jul 7, 2023

The entry point (started as a port) is

args: [
        System.find_executable("elixir"),
            "--sname",
            sname,
            "-S",
            "mix",
            "run",
            "--no-halt",
            "--no-compile",
            "--no-start"
          ]

I'll try out loadpaths after work today, thanks!

@mhanberg
Copy link
Member Author

@josevalim i'll hopefully get some time to look into your suggestion tonight, I had a crazy weekend (wife broke her leg 🥵, she's doing well now).

thanks again!

@josevalim
Copy link
Member

No rush and a speedy recovery to her! By the way, we talked a bit about language servers yesterday during the stream: https://www.twitch.tv/videos/1868498801

@mhanberg
Copy link
Member Author

No rush and a speedy recovery to her!

Thanks!

By the way, we talked a bit about language servers yesterday during the stream: https://www.twitch.tv/videos/1868498801

Nice!

mhanberg added a commit to elixir-tools/next-ls that referenced this pull request Jul 12, 2023
This mix task does what we actually want, which is to load all of the
code paths and not start the app.

Fixes #97
Closes elixir-lang/elixir#12764
mhanberg added a commit to elixir-tools/next-ls that referenced this pull request Jul 12, 2023
This mix task does what we actually want, which is to load all of the
code paths and not start the app.

Fixes #97
Closes elixir-lang/elixir#12764
mhanberg added a commit to elixir-tools/next-ls that referenced this pull request Jul 12, 2023
This mix task does what we actually want, which is to load all of the
code paths and not start the app.

Fixes #97
Closes elixir-lang/elixir#12764
@mhanberg
Copy link
Member Author

Your approach of using loadpaths seems to work as expected, thanks!

@mhanberg mhanberg closed this Jul 12, 2023
mhanberg added a commit to elixir-tools/next-ls that referenced this pull request Jul 12, 2023
This mix task does what we actually want, which is to load all of the
code paths and not start the app.

Fixes #97
Closes elixir-lang/elixir#12764
@mhanberg mhanberg deleted the mh/no-runtime-exs branch July 12, 2023 02:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants