Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with an 'uninitialised' git repository: "No mixfile found in project ... set elixirLS.projectDir in your settings" #364

Closed
2 tasks done
henrythebuilder opened this issue Sep 10, 2020 · 10 comments

Comments

@henrythebuilder
Copy link

Environment

  • Elixir & Erlang versions (elixir --version):
Erlang/OTP 23 [erts-11.0.3] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]
Elixir 1.11.0-dev (cce861e) (compiled with Erlang/OTP 23)
  • Operating system: Debian GNU/Linux 10 (buster)
  • Editor or IDE name (e.g. Emacs/VSCode): GNU Emacs 27.1
  • Editor Plugin/LSP Client name: eglot+elixir-ls (build from master (3a94455) as documented in Emacs Installation Instructions)

Troubleshooting

  • Restart your editor (which will restart ElixirLS) sometimes fixes issues
  • Stop your editor, remove the entire .elixir_ls directory, then restart your editor
    • NOTE: This will cause you to have to re-run the dialyzer build for your project

If you're experiencing high CPU usage, it is most likely Dialyzer building the PLTs; after it's done the CPU usage should go back to normal. You could also disable Dialyzer in the settings.

Reproduce step (no git)

  • Create a new Mix project with mix new empty
  • got to project dir (cd empty)
  • open a file in a subdir: es. emacs lib/empty.ex produce the error:
[eglot] Connected! Server `EGLOT (lib/elixir-mode)' now managing `elixir-mode' buffers in project `lib'.
[eglot] Server reports (type=1): No mixfile found in project. To use a subdirectory, set `elixirLS.projectDir` in your settings

with a new dir lib/.elixir_ls with only a .gitignore file

  • any file opened or created produce the error
  • remove .elixir_ls subdir does not remove error

Reproduce step (git init)

  • Create a new Mix project with mix new empty
  • got to project dir (cd empty)
  • initialise an empty repository with git init
  • open any project files
  • all work as expected 👍
[eglot] Connected! Server `EGLOT (empty/elixir-mode)' now managing `elixir-mode' buffers in project `empty'.
  • a new dir .elixir_ls found in the project root:
tree .elixir_ls/
.elixir_ls/
├── build
│   └── test
│       └── lib
│           └── empty
│               ├── consolidated
│               │   ├── Elixir.Collectable.beam
│               │   ├── Elixir.Enumerable.beam
│               │   ├── Elixir.IEx.Info.beam
│               │   ├── Elixir.Inspect.beam
│               │   ├── Elixir.List.Chars.beam
│               │   ├── Elixir.Phoenix.Param.beam
│               │   └── Elixir.String.Chars.beam
│               └── ebin
│                   ├── Elixir.Empty.beam
│                   └── empty.app
├── dialyzer_manifest_23.0.3_elixir-1.11.0-dev_test
└── dialyzer_tmp
@NobbZ
Copy link
Member

NobbZ commented Sep 10, 2020

If I recall correctly, eglot uses project.el to find the projects root and then start the LS in the context of that root.

If no project root is found, it will use the folder of the file you opened.

So you need a .git folder or anything else what is considered a project root by project.el, which as it seems is currently version control roots only.

Though I have to be honest, I wasn't able to find much about it by a quick search.

lsp-mode uses its own mechanism to find the project root and will always ask the user for confirmation after a root has been guessed. Also it will persist the users choice (if not one of the "ask again next time" options was selected).

So it seems as if you are required to always init your VCS before opening a project file when using eglot.

@henrythebuilder
Copy link
Author

Thanks for response,
I have been using elixirLS for a short time, i switched to eglot because i had problems with lsp-mode in emacs in the first few attempts, leaving out this small problem the integration into emacs and elixir projects works fine and now i know too little about these projects to go further in my investigations so i apologise for the false report and thanks for the support and for your work.

@henrythebuilder
Copy link
Author

... after some research on eglot project I found a possible workaround based on similar problem (joaotavora/eglot#98 end joaotavora/eglot#129 (comment))
A possible approach is to set the project root is via project-find-functions by add a 'mix.exs research function':

(defun elixir/find-mix-project (dir)
  "Try to locate a Elixir project root by 'mix.exs' above DIR."
  (let ((mix_root (locate-dominating-file dir "mix.exs")))
    (message "Found Elixir project root in '%s' starting from '%s'" mix_root dir)
    (if (stringp mix_root) `(transient . ,mix_root) nil)))

(add-hook 'project-find-functions 'elixir/find-mix-project nil nil)

This for now seam to work also without git dirs

Thanks again for suggestions

@axelson
Copy link
Member

axelson commented Sep 12, 2020

Since there doesn't appear to be anything to do here on the ElixirLS side I'm going to close this issue.

@axelson axelson closed this as completed Sep 12, 2020
@henrythebuilder
Copy link
Author

👍

@dimitarvp
Copy link

Just want to mention that I forgot to do git init in a project and then I got this error message, after which Emacs spent 15+ minutes searching my entire home directory (and it has ~3.3 million files) and eventually asking me if I want to watch all files in my entire home directory. After answering "No", it seems to resume operations normally, including allowing me to search all files inside the project (which correctly ignores GIT-ignored files). I use Spacemacs which in turn uses helm and projectile.

Even after I did git init and started doing commits, on restart my Spacemacs (using projectile) is still doing the same.

It's also not creating an .elixir_ls directory.

Is there a way to make Emacs or LSP to "forget" that the project started off misconfigured? Apparently that information persists.

@axelson
Copy link
Member

axelson commented Apr 29, 2021

@dimitarvp that sounds like an lsp-mode issue. It sounds like you might now have an entry for your home directory in your: https://emacs-lsp.github.io/lsp-mode/page/settings/mode/#lsp-session-file
I think you have to manually remove it from that file. Can't find anything about managing it in lsp-mode via functions.
Also you may have a ~/.elixir_ls directory that you probably want to remove.

@dimitarvp
Copy link

dimitarvp commented Apr 29, 2021

@axelson Removing my home directory entry from ~/.emacs.d/.lsp-session-v1 helped. And deleting ~/.elixir_ls. Thank you!

Apologies for posting in the wrong place. I suppose I was drawn to familiar faces. Still, not an excuse.

I am grateful for the assist.

@axelson
Copy link
Member

axelson commented Apr 30, 2021

You're welcome! I think I've ran into nearly the exact same situation before :)

@Gazler
Copy link

Gazler commented Sep 20, 2023

This file can also be in ~/.emacs.d/.cache/lsp for some emacs configurations (spacemacs).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants