Skip to content

Commit fe1e871

Browse files
princemapleaxelson
andauthored
Fix formatting on Windows (elixir-editors#375)
* Update formatting.ex (elixir-editors#1) Bring formatting back on Windows. Regression in 0.6.0 Create elixir.yml try without downcase fix cwd Revert test without downcase fix matching fix capture fix missing end r * normalize path * remove duplicate call * Delete elixir.yml Co-authored-by: Jason Axelson <[email protected]>
1 parent bd95bb7 commit fe1e871

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

apps/language_server/lib/language_server/providers/formatting.ex

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,14 @@ defmodule ElixirLS.LanguageServer.Providers.Formatting do
4141
# If in an umbrella project, the cwd might be set to a sub-app if it's being compiled. This is
4242
# fine if the file we're trying to format is in that app. Otherwise, we return an error.
4343
defp can_format?(file_uri, project_dir) do
44-
project_dir = project_dir |> String.downcase()
45-
file_path = file_uri |> SourceFile.path_from_uri() |> String.downcase()
46-
cwd = File.cwd!() |> String.downcase()
44+
file_path = file_uri |> SourceFile.path_from_uri() |> Path.absname()
4745

4846
not String.starts_with?(file_path, project_dir) or
49-
String.starts_with?(Path.absname(file_path), cwd)
47+
String.starts_with?(file_path, File.cwd!())
5048
end
5149

5250
def should_format?(file_uri, project_dir, inputs) when is_list(inputs) do
53-
file = String.trim_leading(file_uri, "file://")
51+
file_path = file_uri |> SourceFile.path_from_uri() |> Path.absname()
5452

5553
inputs
5654
|> Stream.flat_map(fn glob ->
@@ -60,7 +58,7 @@ defmodule ElixirLS.LanguageServer.Providers.Formatting do
6058
]
6159
end)
6260
|> Stream.flat_map(&Path.wildcard(&1, match_dot: true))
63-
|> Enum.any?(&(file == &1))
61+
|> Enum.any?(&(file_path == &1))
6462
end
6563

6664
def should_format?(_file_uri, _project_dir, _inputs), do: true

apps/language_server/lib/language_server/server.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ defmodule ElixirLS.LanguageServer.Server do
815815

816816
defp set_project_dir(%{project_dir: prev_project_dir, root_uri: root_uri} = state, project_dir)
817817
when is_binary(root_uri) do
818-
root_dir = SourceFile.path_from_uri(root_uri)
818+
root_dir = root_uri |> SourceFile.path_from_uri() |> Path.absname()
819819

820820
project_dir =
821821
if is_binary(project_dir) do

0 commit comments

Comments
 (0)