Skip to content

Commit 7066835

Browse files
committed
use safe expand
1 parent 7b6a3f5 commit 7066835

File tree

1 file changed

+14
-5
lines changed
  • apps/language_server/lib/language_server/mix_tasks

1 file changed

+14
-5
lines changed

apps/language_server/lib/language_server/mix_tasks/format.ex

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,11 @@ defmodule Mix.Tasks.ElixirLSFormat do
435435

436436
formatter_opts_and_subs = load_plugins(formatter_opts_and_subs, opts)
437437

438-
find_formatter_and_opts_for_file(Path.expand(file, cwd), cwd, formatter_opts_and_subs)
438+
find_formatter_and_opts_for_file(
439+
SourceFile.Path.expand(file, cwd),
440+
cwd,
441+
formatter_opts_and_subs
442+
)
439443
end
440444

441445
@doc false
@@ -558,7 +562,7 @@ defmodule Mix.Tasks.ElixirLSFormat do
558562
defp eval_subs_opts(subs, cwd, sources, opts) do
559563
{subs, sources} =
560564
Enum.flat_map_reduce(subs, sources, fn sub, sources ->
561-
cwd = Path.expand(sub, cwd)
565+
cwd = SourceFile.Path.expand(sub, cwd)
562566
{Path.wildcard(cwd), [Path.join(cwd, ".formatter.exs") | sources]}
563567
end)
564568

@@ -637,7 +641,8 @@ defmodule Mix.Tasks.ElixirLSFormat do
637641

638642
for file <- files do
639643
if file == :stdin do
640-
stdin_filename = Path.expand(Keyword.get(opts, :stdin_filename, "stdin.exs"), cwd)
644+
stdin_filename =
645+
SourceFile.Path.expand(Keyword.get(opts, :stdin_filename, "stdin.exs"), cwd)
641646

642647
{formatter, _opts} =
643648
find_formatter_and_opts_for_file(stdin_filename, cwd, {formatter_opts, subs})
@@ -657,7 +662,7 @@ defmodule Mix.Tasks.ElixirLSFormat do
657662

658663
map =
659664
for input <- List.wrap(formatter_opts[:inputs]),
660-
file <- Path.wildcard(Path.expand(input, cwd), match_dot: true),
665+
file <- Path.wildcard(SourceFile.Path.expand(input, cwd), match_dot: true),
661666
do: {file, {dot_formatter, formatter_opts}},
662667
into: %{}
663668

@@ -737,7 +742,11 @@ defmodule Mix.Tasks.ElixirLSFormat do
737742
defp stdin_or_wildcard("-"), do: [:stdin]
738743

739744
defp stdin_or_wildcard(path),
740-
do: path |> Path.expand() |> Path.wildcard(match_dot: true) |> Enum.filter(&File.regular?/1)
745+
do:
746+
path
747+
|> SourceFile.Path.expand()
748+
|> Path.wildcard(match_dot: true)
749+
|> Enum.filter(&File.regular?/1)
741750

742751
defp elixir_format(content, formatter_opts) do
743752
case Code.format_string!(content, formatter_opts) do

0 commit comments

Comments
 (0)