VSCode, language servers, and project-wide completions

Hey folks, new to VSCode and am trying to get it set up for Elixir. I’m having partial success, but can’t seem to get autocomplete working in dependencies.

I’ve been trying to navigate the wierd world of Elixir VSCode extensions. Seems like Elixir-LS Fork is the way to go, so I’ve installed that. Next I open one of my Ecto models, but here’s what doesn’t work:

  • Erasing part of an import/alias/use and trying to tab-complete it. This inserts spaces, not any submodules of the initial module.
  • Entering my schema, typing fiel and pressing tab.

Here’s what does:

  • Typing part of something from the Elixir standard library–“Pat”, for instance, then pressing Tab. This autocompletes to Path.
  • When I type fiel above and press Tab, file_changeset(arg1, arg2) is suggested. file_changeset is a function in my current module, and it does indeed accept two arguments, so this suggests that the server is in fact working and providing more than just word-based completion without context.

My expectation was that the language server would provide completions of symbols in my entire project. Is this inaccurate? Is there more work I need to do to enable this?

Also, FWIW, my project is a monorepo with the Elixir project in a subdirectory. I’m trying to organize it as a workspace, separating out the Java/Kotlin bits into their own workspace. I’m not sure how that affects anything, but theoretically Elixir is in its own isolated workspace. There are also no errors in the Elixir language server output, though the mix compile happens in some small number of MS, which should be much larger if I’m getting access to all my project’s symbols.

Am I misunderstanding how language servers work? Are they not intended to work project-wide? Any help greatly appreciated.

Thanks.

Have you seen this GitHub issue https://github.com/JakeBecker/elixir-ls/issues/37?
Also try this https://rok3.me/blog/my-elixir-visual-studio-code-setup/

Since @ndarilek is using ElixirLS Fork they should look at Issues · elixir-lsp/elixir-ls · GitHub instead.

I’d expect the first one to work. Does it work if you start the whole line over?

Can you explain what you mean by the second? %MyStruct{fiel▌} should auto-complete. Perhaps you’re running into the case described at Auto completion for struct fields Elixir ls ?

1 Like

You are right my bad i thought that elixir-ls is the fork but it appear’s that it is not.

Thanks @axelson for pointing out my mystake

1 Like

In general, the LS (fork and upstream) only works for mix projects. So if you do not have a mix.exs it won’t be able to help you.

And I’m not quite sure how the LS is initialised by the vscode plugin. If you are unlucky the mix.exs needs to be at the root of the VScode workspace.

This is exactly it, thanks.

My project is a Mix project. I set it up as a multi-workspace VSCode
project, though, and the files are in a subdirectory. When I opened the
project root directly in VSCode, the language server output showed it
compiling all my dependencies. Ultimately the compilation failed due to
unrelated issues, but given that it now builds everything and didn’t
before, I assume completion should work project-wide as expected.

Thanks. FOr those of you using VSCode for more complex projects, do you
generally open each different project in its own window so it’s at the
top-level? Or do you try structuring things into a single project? We
have some Elixir communicating with a Kotlin backend over GRPC, and I
was trying to set up both as a multi-root workspace, but I keep hitting
lots of odd problems and corner cases. So maybe I’m over-complicating
this, and opening each distinct subproject in its own window is the way
to go.

If you open up the project configuration there is an option for Elixir LS: Project Dir, if you set that to the subdirectory containing your mix project, it should work.