elixir-ls
elixir-ls copied to clipboard
Error - Cannot format file from current directory (Currently in deps/telemetry/deps/mimerl)")
If I change and save too fast. I see this error
Environment
-
Elixir & Erlang versions (elixir --version): Erlang/OTP 22 [erts-10.7.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe] Elixir 1.10.3 (compiled with Erlang/OTP 21)
-
Operating system: macOS Catalina 10.5.4
-
Editor or IDE name (e.g. Emacs/VSCode): Emacs 27.0.91
-
LSP Client name: elixir-lsp elixir-ls
Logs
Saving file /Users/anil/Code/elixir/web_projects/myapp/lib/myapp_web/controllers/page_controller.ex...
Error: (error "Cannot format file from current directory (Currently in deps/telemetry/deps/mimerl)")
Error: (error "Cannot format file from current directory (Currently in deps/telemetry)")
Skipping build because cwd changed from /Users/anil/Code/elixir/web_projects/myapp to /Users/anil/Code/elixir/web_projects/myapp/deps/telemetry
My thinking on how to handle this is to try to get the build lock, but if that takes more than 1 second or so, then just save the file without formatting.
It's also happening to me, but instead of changing the cwd to deps it's changing to a random app inside the umbrella.
I found it sometimes after build is done. This is trace output from vim-lsp:
Thu Jul 16 22:55:21 2020:["<---", 3, "elixir-ls", {"response": {"method": "window/logMessage", "jsonrpc": "2.0", "params": {"message": "==> lfc_server", "type": 4}}}]
Thu Jul 16 22:55:21 2020:["<---", 3, "elixir-ls", {"response": {"method": "window/logMessage", "jsonrpc": "2.0", "params": {"message": "Compiling 25 files (.erl)", "type":
4}}}]
Thu Jul 16 22:55:26 2020:["<---", 3, "elixir-ls", {"response": {"method": "window/logMessage", "jsonrpc": "2.0", "params": {"message": "Generated lfc_server app", "type": 4
}}}]
Thu Jul 16 22:55:34 2020:["<---", 3, "elixir-ls", {"response": {"method": "window/logMessage", "jsonrpc": "2.0", "params": {"message": "Compile took 327155 milliseconds", "
type": 3}}}]
Thu Jul 16 22:55:34 2020:["<---", 3, "elixir-ls", {"response": {"method": "window/logMessage", "jsonrpc": "2.0", "params": {"message": "[ElixirLS WorkspaceSymbols] Indexing
...", "type": 3}}}]
Thu Jul 16 22:55:34 2020:["<---", 3, "elixir-ls", {"response": {"method": "window/logMessage", "jsonrpc": "2.0", "params": {"message": "Skipping build because cwd changed f
rom /Users/thanabodee/src/git.myhost.com/myorg/theproject/myproject to /Users/thanabodee/src/git.myhost.com/myorg/theproject/lfc_server/dep
s/cowboy", "type": 4}}}]
It's seems like the build is broken some how and does not change directory back to project dir.
Anyone know how is this handled in VS Code? I have not seen such error there.
I found that the formatter will return this error when ElixirLS are still compiling the source. If your source contains small dependencies. I guess that we cannot get formatter opt during mix still compiling.
Not sure if it is related, but I can see this message in my ElixirLS - server log of VSCode too.
Request textDocument/formatting failed.
Message: Cannot format file from current directory (Currently in .)
Steps to reproduce:
- open new tab
- change language mode to Elixir
- write unformatted Elixir code, for example:
defmodule Bla do def x, do: nil end(do not save!) - run command "Format document"
I am not sure if formatting should work for unsaved file too, but I would assume yes. Correct me if I am wrong, please.
@stefanluptak this looks like a separate issue
Addressed in https://github.com/elixir-lsp/elixir-ls/pull/890 Requires elixir 1.15