Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error when saving a file in an elixir project (elixirLS.projectDir)

Tags:

elixir

I have the following error when saving an elixir file with visual studio code

No mixfile found in project. To use a subdirectory, set elixirLS.projectDir in your settings

I have thus updated the User/settings.json (In windows) file such as

{
    "elixirLS.projectDir": "C:\\CodeTraining\\Elixir-intro"
}

But I still get the error

Any idea ?

By the way, I have the same error when using Ubuntu.

like image 447
Makoto Avatar asked Jul 03 '20 12:07

Makoto


2 Answers

ElixirLS requires mix project, it does not work properly with plain files. So start with creating the project

mix new intro
cd intro
code .

Now in intro folder ElixirLS would be happy. You still can create random elixir files and/or scripts there to play with.

like image 51
Aleksei Matiushkin Avatar answered Oct 02 '22 18:10

Aleksei Matiushkin


Since I landed here searching for an answer to this but for Vim, I'm gonna share what will fix the error on Vim

The error is caused by the language client incorrectly setting the project root based on the first file that you opened. For example, if you open mix.exs first, this is printed to the Vim output:

LanguageClient project root: /Users/joe/Downloads/test

However, if you open something else (like lib/test.ex) you get the following:

LanguageClient project root: /Users/joe/Downloads/test/lib

So, in order to fix this, add the following to your .vimrc:

let g:LanguageClient_rootMarkers = {
    \ 'elixir': ['mix.exs'],
    \ }

Or if you use coc.nvim, add this to your .vimrc instead

autocmd FileType elixir let b:coc_root_patterns = ['mix.exs']

This will correctly set the project root based on the location of mix.exs for the purposes of ElixirLS

like image 35
Kaka Ruto Avatar answered Oct 02 '22 18:10

Kaka Ruto