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

Formatting doesn't work for a file outside editor project folder #324

Closed
malaire opened this issue Jul 19, 2020 · 3 comments
Closed

Formatting doesn't work for a file outside editor project folder #324

malaire opened this issue Jul 19, 2020 · 3 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@malaire
Copy link

malaire commented Jul 19, 2020

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:

project_dir = project_dir |> String.downcase()

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.

@malaire
Copy link
Author

malaire commented Jul 19, 2020

Maybe related to #307 although the file in question is inside mix-project, just not inside editor-project.

@malaire malaire changed the title Formatting doesn't work for a file outside project folder Formatting doesn't work for a file outside editor project folder Jul 19, 2020
@axelson
Copy link
Member

axelson commented Jul 20, 2020

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).

@lukaszsamson lukaszsamson added enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed labels Nov 28, 2020
@lukaszsamson
Copy link
Collaborator

Fixed by #562

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants