ndreynolds / ratatouille

A TUI (terminal UI) kit for Elixir
MIT License
752 stars 39 forks source link

ElixirLS: error starting Ratatouille.Window #11

Closed ddowl closed 5 years ago

ddowl commented 5 years ago

Hello!

As I started up a project in VSCode I found that the ElixirLS plugin marks a copy-paste of the Counter example with this error:

** (exit) shutdown: failed to start child: Ratatouille.Window
    ** (EXIT) an exception was raised:
        ** (MatchError) no match of right hand side value: {:error, :already_running}
            lib/ratatouille/window.ex:104: Ratatouille.Window.init/1
            (stdlib) gen_server.erl:374: :gen_server.init_it/2
            (stdlib) gen_server.erl:342: :gen_server.init_it/6
            (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3

ratatouille-error

It seems like ElixirLS is compiling/running the example in the background to check for any errors, but it's not expecting the Ratatouille.run(Counter) at the end. This error goes away if I remove Ratatouille.run or import Ratatouille.View.

I'm not sure if this is due to this library, ElixirLS, or a misconfiguration on my end :man_shrugging:. Let me know if I should redirect this to ElixirLS!

ndreynolds commented 5 years ago

Hi @ddowl, thanks for reporting!

I think the issue is probably that the file extension there is .ex instead of .exs. I'm guessing that's why ElixirLS thinks it's safe to run that code. I don't see any problems with this in VS Code + ElixirLS as long as it's an Elixir script file.

It's also always possible to move the Ratatouille.run(...) to its own script file and leave the rest in the .ex file. I've just set the examples up like this for brevity.

Let me know if that solves the issue for you.

ddowl commented 5 years ago

Yep! ElixirLS won't execute Ratatouille.run when it's in a script file. I had no idea! I was getting around it by putting a run method in my module that just dispatches out, but I like your idea better. Thanks for the tip!