elixir-lsp/elixir-ls

Missing support for opening single files outside mix project

lukaszsamson opened this issue · 10 comments

https://elixirforum.com/t/vscode-autocomplete-doesnt-work-for-mix-created-projects/32624/13?u=lukaszsamson

I'm not shure we should support it. If not then it needs to be addressed in the readme

Edit:
Due to numerous request and upcoming better support for .exs scripts in elixir 1.12 I think we should support it.
Here's the short list of issues that need to be taken care of:

  • remove the warning message
  • make sure basic current source file based completions work
  • investigate formatting support (#324)
  • investigate compiling & loading .exs file for better completions and diagnostic messages (tracked in #89)
  • investigate building and loading deps via Mix.install (tracked in #654)
  • vscode extension not working (elixir-lsp/vscode-elixir-ls#195)

Yeah, I agree. I think we'd just want to add a note to the README for now. It would probably be a considerable undertaking and impact many portions of the project.

There's an (arguably minor but legitimate) case for a mode where some elixir-ls functions work outside a project, without the "No Mixfile found" warning.
I've got a "howtos" project, basically snippets, templates, and howto READMEs for very diverse things. Eg. I have a GenServer "template" with the usual stuff I usually use, together with an application.ex. ElixirLS comes handy for these files with syntax highlighting, code formatting, and whatever works in this mode. I don't want a separate project for each (Elixir) template, these are really nothing more than bigger snippets.
The config option to disable the message, as suggested in the merged issue #435 may be the simplest solution. Note too that this use case is not related to the .exs cases where the warning usually turns up.

thbar commented

Mix.install/2 scripts are getting traction (e.g. https://github.com/wojtekmach/mix_install_examples), making this more relevant.

@lukaszsamson what do you think about marking this as fixed and extracting "investigate compiling & loading .exs file for better completions and diagnostic messages" and "investigate building and loading deps via Mix.install" to separate issues? I think those are different than supporting single files. Although I suppose in that case we should remove the "No Mixfile found" warning as @javobalazs mentions.

@axelson I extracted the issues and updated this one.

Although I suppose in that case we should remove the "No Mixfile found" warning as @javobalazs mentions.

The warning is already removed

I may be misunderstanding the result of this issue.

I created some exs files manually and wrote Elixir code in them. I've apparently set up elixir-ls successfully for Emacs:

[eglot] Connected! Server `ElixirLS' now managing `(elixir-mode)' buffers in project `advent-of-code-2022'.

When I open an exs file, I still see the error:

[eglot] Server reports (type=3): No mixfile found in project. To use a subdirectory, set `elixirLS.projectDir` in your settings

Why do I need a mixfile for code that is in a single file and not using any mix functionality? Is this not the issue discussed here? Should I open a new issue?

You are not opening a single file. You are opening a directory that is not a mix project hence you get the warning. Nothing is wrong here.

I am not sure I understand.

In detail I do:

  1. I do C-x C-f.
  2. tab-complete myself through the directories until the full filename is there
  3. press the return key
  4. Emacs open an exs file

How am I not opening a single file?

Good to know that it is just a warning though.

However, I do apparently see some linting from the language server, when I introduce syntax errors. Emacs does underline things and put red exclamation marks in the gutter. So the language server must be doing something and Emacs communicating with it. I still need to figure out completions though.

I guess all is as it should be then?

I guess all is as it should be then?

Yes. You open a directory with exs files that is not a mix project. Some mix projects have unusual directory layout and require special configuration. This warning is an attempts to discover such cases. Since you don't have a mix project you can disregard it.

Technically, what a language server considers one file is what it gets passed in initialize request rootUri. It it's a directory, then you open a directory. It it's a file then you open a single file.

OK thank you for confirming! Sorry for the confusion.