Play nice with VSCode

#2 · closed · 4 comments

View on GitHub ↗

davemccrea

Thanks for a great resource! Do you have any tips on getting this setup to play nice with VSCode and the elixir-lsp? ``` an exception was raised: ** (Mix.Error) Can't continue due to errors on dependencies (mix 1.11.3) lib/mix.ex:436: Mix.raise/1 (mix 1.11.3) lib/mix/tasks/deps.loadpaths.ex:28: Mix.Tasks.Deps.Loadpaths.run/1 (mix 1.11.3) lib/mix/task.ex:394: Mix.Task.run_task/3 (mix 1.11.3) lib/mix/tasks/loadpaths.ex:37: Mix.Tasks.Loadpaths.run/1 (mix 1.11.3) lib/mix/task.ex:394: Mix.Task.run_task/3 (mix 1.11.3) lib/mix/tasks/compile.ex:113: Mix.Tasks.Compile.run/1 (mix 1.11.3) lib/mix/task.ex:394: Mix.Task.run_task/3 (language_server 0.7.0) lib/language_server/build.ex:199: ElixirLS.LanguageServer.Build.compile/0ElixirLS ``` I am assuming that the elixir-lsp in VSCode is looking at the `build_path` and `deps_path` in `mix.exs` and not finding anything. Thanks in advance.

Comments

nickjj

Hi, Have you configured VSCode to use remote containers? That's what lets VSCode know your workload is running within Docker. The docs for that are here: https://code.visualstudio.com/docs/remote/containers I don't use VSCode so I don't have it set up at the moment but I did try it out around a year ago and it worked with a similar project structure. I forgot which Elixir extension I used but it did pick everything up and autocomplete / everything else worked.

davemccrea

I hadn't heard of Remote Containers. Thanks for pointing me in the right direction!

nickjj

It boils down to adding a JSON file, installing the remote container extension and then saying yes when VSCode prompts you to open your code folder in a remote container. You'd add `.devcontainer/devcontainer.json` to the project: ```json { "name": "VSCode Remote", "dockerComposeFile": [ "../docker-compose.yml" ], "extensions": [ "jakebecker.elixir-ls" ], "service": "web", "workspaceFolder": "/app" } ``` Then launch VSCode and hit yes when it asks to use remote containers. The first time it loads it'll take a bit but after that it should be nearly instant, and then you should get autocomplete. I just tested it with the latest versions, it's all good. The `service` is web because it matches the `web` service in the `docker-compose.yml` file and the `workspaceFolder` matches the `WORKDIR` in the `Dockerfile`.

davemccrea

Works a charm - thanks again.