just d/l and installed elixir (win auto installer) and added the elixirls extension to vscode.
vscode recognizes my hello.ex file as elixir.
how do I compile/run my single line hello world via the ide?
just d/l and installed elixir (win auto installer) and added the elixirls extension to vscode.
vscode recognizes my hello.ex file as elixir.
how do I compile/run my single line hello world via the ide?
running “Hello, World!” is the hardest part in learning Elixir. Its a little crazy. But as soon as that is out of the way, I promise, It’ll be a fun ride.
If you created your project with mix new Hello
there is a module Hello
in lib
.
In there is a comment that tells you to run:
iex> Hello.hello()
:world
what it doesn’t tell you is, that you have to start iex
in this way
iex -S mix
You can also run the function directly
mix run -e Hello.hello
but you should add something that you can see on the console first, like
def hello do
IO.puts("hello")
end
Note: If there are processes involved (later!) you’ll need to add --no-halt
but then you’ll but build a Supervision-Tree (later!!) anyway (and you run an OTP-application and not just one function).
In the beginning I’d just put everything in tests and run
mix test
To run the test with a vscode-hotkey look here:
https://pragdave.me/blog/2018/06/13/visual-studio-code-elixir-tests.html
VScode is not an IDE, it tries to, but at the end it is “just” a smart editor.
Don’t try to rely on IDE features, learn to do things from the terminal.
mix
is easy to use.
To run a single file script, just do elixir script.ex
, its not how things usually are done though.
IDE or not, it doesn’t hurt to have a quick and easy way to run tests.
The easiest way (without changing vscode config) is:
mix test
# change some code
Ctrl+` <UP-KEY> <ENTER>
That is indeed true, and if I recall correctly recent versions of the LSP do allow for “run test” lenses. Not sure if they have to be activated first in VScode.
I am not sure if you can run full tests though, and also the question was not about running tests, but individual files. This is best to be done through the terminal.
thank you friend. whole heartedly recommend the elixir intro to include mix in the first page. whole heartedly recommend the mix first page to put the run command next to the “new” example. cheers.