How to setup enviroment (Visual Studio Code, Power Shell)

Hello all,
I’m learning Elixir and thank you for your patience and also for the help received in other threads.

I use both a Mac and a PC laptop.
I would ask you for some suggestions on how could I setup a useful developing enviroment.

I started with Sublime Text, which I love, but I saw that many people use VS Code, where there a lot of tools.
So I moved to VS Code.

I read this article:

and downloaded some extensions.

It appears that a couple of extensions are incompatible:
Warning: mjmcloug.vscode-elixir is not compatible with ElixirLS, please uninstall mjmcloug.vscode-elixir

So I will unistall mjmcloug.vscode-elixir

I try to run the code in PowerShell (that is the default terminal in VS Code), but it doesn’t work.

The error message is in Italian (so it will be unuseful to copy and paste here), but it says that no application is associated with ex and exs: how can I fix this (I’m not neither expert
in PowerShell).

Any other suggestion about the way in which I can setup a productive enviroment?

Thank you in advance for your replies.

If you’re running on the Mac, you should certainly use bash instead of powershell. VSCode allows you to select the default shell. I would do that as a first step.

thank you for your reply.

Just to clarify:
I have two different environments, first one with Windows, the second one with Windows.

The PowerShell is in Windows, not on the Mac one.

On windows the experience is better if you use WSL but I do it all on the windows side when I’m making things to run on windows. I would suggest using windows terminal and installing powerline fonts. If you want tab completion and aren’t using WSL, start the shell with iex.bat --werl.

The only vscode extentions I’m using are elixir-ls and the dark elixir colour theme.

Thank you for your suggestions.
I installed WSL with Debian.
Still, I have some problems with users’ permissions and mount-points, but I’m fixing them.

here are the docs for windows terminal. I use ubuntu for WSL and have never had to worry about mount points or permissions. It all worked out of the box. You might want to check if you’re on WSL 1 or 2, and likely upgrade to 2 if you’re not there already, docs here.

Thank you for your reply.
Not completely sure right now where I have to put the files in.
Currently, I have:

  • WSL2;
  • Elixir in Debian inside WSL;
  • Postgres inside WSL Debian;
  • VS Code in Windows;
  • my project files inside WSL installation

But I missed something…

For example, I have these two annoying problems:

  • why I don’t have code color formatting?
  • why the files can’t run in vs code?

Are you starting VS Code from within the WSL terminal with code .?

Are the extensions installed within WSL? You have to install them twice, once in Windows and once in WSL. See how there are two sections for the extensions.

In WSL:

> elixir --version
Erlang/OTP 23 [erts-11.1] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [hipe]

Elixir 1.10.4 (compiled with Erlang/OTP 23)
> mkdir ~/code/testbed
> cd ~/code/testbed
> touch testbed.exs
> code .

After you’ve edited it, you should be able to run it with elixir testbed.exs. Honestly, I’ve never tried to run things from vscode but I’m sure its possible. This person shows how to setup debug. I generally play around in iex and run tests in a mix project.

Thank you for your help.

Almost done: I need also to install the extensions inside WSL. I did and it works.

I’m not doing this:

Are you starting VS Code from within the WSL terminal with code .?

Because I installed a Debian in WSL without graphical environment.

I’m running VS Code from Windows with Remote - WSL extension.
I think I did pretty all the setup needed.

Information more: how to enable code completion in VS Code (I mean with something similar to tab + shift or similar…)

Thank you in advance!

I’m not so lucky with this configuration.
This:

Are you starting VS Code from within the WSL terminal with code . ?

For now is not possible for a couple of system’s errors.

The Windows Environment variable has got the wrong path.
In addition, there is a known issue.

It was a long journey, but now it works.

Almost 2 years later, this is how I got things working using Visual Studio Community Edition 2022. I don’t use WSL2 as i find it too slow. This approach seems clumsy to me, hopefully someone will a more sane approach.

Install Microsoft C++ Build Tools intstruction from Exqlite.

Add the following to the powershell profile.ps1 script to make sure the build tools are available:

cmd.exe /c "call `"C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvars64.bat`" && set > %temp%\vcvars.txt"

Get-Content "$env:temp\vcvars.txt" | Foreach-Object {
  if ($_ -match "^(.*?)=(.*)$") {
    Set-Content "env:\$($matches[1])" $matches[2]
  }
}

Add the following to settings.json in Visual Studio Code:

{
  "terminal.integrated.profiles.windows": {
    "PowerShell": {
      "source": "PowerShell",
      "icon": "terminal-powershell"
    },
    "Command Prompt": {
      "path": [
        "${env:windir}\\Sysnative\\cmd.exe",
        "${env:windir}\\System32\\cmd.exe"
      ],
      "args": ["/k", "C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\VC\\Auxiliary\\Build\\vcvars64.bat"],
      "icon": "terminal-cmd"
    },
    "Git Bash": {
      "source": "Git Bash"
    }
  },
  "terminal.integrated.defaultProfile.windows": "Command Prompt",
}

Optionally to make the ElixirLS available in the powershell under elixir-ls, e.g. for Vim:

  1. Download ElixirLS and extract under C:\Program Files(x86)\elixir-ls
    2 Add the following to the powershell profile.ps1:
    Set-Alias -Name elixir-ls -Value "C:\Program Files (x86)\elixir-ls\language_server.bat"