Formatting doesn't work for a file outside editor project folder
malaire opened this issue · 3 comments
Environment
- Elixir & Erlang versions (elixir --version): Elixir 1.10.4 Erlang/OTP 23
- Operating system: Debian 10
- Editor or IDE name: Sublime Text 3
- LSP Client name: What is "LSP Client" ? Does this mean LSP-elixir?
Issue
LSP-elixir issue: sublimelsp/LSP-elixir#7
When opening Elixir file outside project-folder, right-clicking within it, and choosing "LSP > Format Document", it fails with exception:
lsp-elixir:
22:18:21.256 [error] Process #PID<0.125.0> raised an exception
** (FunctionClauseError) no function clause matching in String.downcase/2
(elixir 1.10.4) lib/string.ex:813: String.downcase(nil, :default)
(language_server 0.5.0) lib/language_server/providers/formatting.ex:35: ElixirLS.LanguageServer.Providers.Formatting.can_format?/2
(language_server 0.5.0) lib/language_server/providers/formatting.ex:10: ElixirLS.LanguageServer.Providers.Formatting.format/3
(language_server 0.5.0) lib/language_server/server.ex:564: anonymous fn/3 in ElixirLS.LanguageServer.Server.handle_request_async/2
Exception happens because project_dir
is nil
here:
It would be nice if this could be made to work - code formatting shouldn't rely on file being in a project. But if this is not possible, then at the very least this limitation should be documented.
Maybe related to #307 although the file in question is inside mix-project, just not inside editor-project.
We would accept a PR that improves this behavior (as long as it is readable and easily maintainable), but as you saw in #307 this is not currently a supported approach, and many other parts of ElixirLS will not work without a project (and associated projectDir).
Fixed by #562