Skip to content

Commit 0efd958

Browse files
authored
Made .formatter.exs inputs relocatable (#846)
* Made .formatter.exs inputs relocatable The .formatter.exs defined paths via a wildcard, but this would only work if it was executed from the current directory. If it was run from the topmost directory, none of the paths would be found, and the inputs would only contain the `.exs` files in the current directory. I also removed config from the glob, as this is in an umbrella project, and umbrella apps have a centralized config which isn't in this directory. * Only append the formatter directory if the path is relative * Need to make the ignores absolute paths as well * Removed forwared slashes
1 parent 2b8b024 commit 0efd958

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

apps/language_server/.formatter.exs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1+
current_directory = Path.dirname(__ENV__.file)
2+
13
impossible_to_format = [
2-
"test/fixtures/token_missing_error/lib/has_error.ex",
3-
"test/fixtures/project_with_tests/test/error_test.exs"
4+
Path.join([current_directory, "test", "fixtures", "token_missing_error", "lib", "has_error.ex"]),
5+
Path.join([
6+
current_directory,
7+
"test",
8+
"fixtures",
9+
"project_with_tests",
10+
"test",
11+
"error_test.exs"
12+
])
413
]
514

615
deps =
@@ -29,8 +38,8 @@ proto_dsl = [
2938
inputs:
3039
Enum.flat_map(
3140
[
32-
"*.exs",
33-
"{lib,test,config}/**/*.{ex,exs}"
41+
Path.join(current_directory, "*.exs"),
42+
Path.join(current_directory, "{lib,test}/**/*.{ex,exs}")
3443
],
3544
&Path.wildcard(&1, match_dot: true)
3645
) -- impossible_to_format

apps/language_server/lib/language_server/experimental/code_mod/format.ex

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,13 @@ defmodule ElixirLS.LanguageServer.Experimental.CodeMod.Format do
115115

116116
inputs_apply? =
117117
Enum.any?(inputs, fn input_glob ->
118-
glob = Path.join(formatter_dir, input_glob)
118+
glob =
119+
if Path.type(input_glob) == :relative do
120+
Path.join(formatter_dir, input_glob)
121+
else
122+
input_glob
123+
end
124+
119125
PathGlobVendored.match?(document.path, glob, match_dot: true)
120126
end)
121127

0 commit comments

Comments
 (0)