Skip to content

Commit fa35a3c

Browse files
committed
Use file:consult/1 for erlang_ls.config
1 parent 3ccf513 commit fa35a3c

File tree

3 files changed

+34
-13
lines changed

3 files changed

+34
-13
lines changed

apps/els_core/src/els_config.erl

+16-3
Original file line numberDiff line numberDiff line change
@@ -242,17 +242,30 @@ consult_config([], ReportMissingConfig) ->
242242
{undefined, #{}};
243243
consult_config([Path | Paths], ReportMissingConfig) ->
244244
?LOG_INFO("Reading config file. path=~p", [Path]),
245-
Options = [{map_node_format, map}],
246-
try yamerl:decode_file(Path, Options) of
245+
try consult_file(Path) of
247246
[] -> {Path, #{}};
248-
[Config] -> {Path, Config}
247+
[Config] -> {Path, Config};
248+
{ok, Config} -> {Path, maps:from_list(Config)};
249+
{error, Reason} ->
250+
?LOG_WARNING( "Could not read config file: path=~p class=~p error=~p"
251+
, [Path, error, Reason]),
252+
consult_config(Paths, ReportMissingConfig)
249253
catch
250254
Class:Error ->
251255
?LOG_WARNING( "Could not read config file: path=~p class=~p error=~p"
252256
, [Path, Class, Error]),
253257
consult_config(Paths, ReportMissingConfig)
254258
end.
255259

260+
-spec consult_file(path()) -> [map()] | {ok, [term()]} | {error, term()}.
261+
consult_file(Path) ->
262+
case string:find(Path, ".yaml", trailing) of
263+
nomatch ->
264+
file:consult(Path);
265+
".yaml" ->
266+
yamerl:decode_file(Path, [{map_node_format, map}])
267+
end.
268+
256269
-spec report_missing_config() -> ok.
257270
report_missing_config() ->
258271
Msg =

erlang_ls.config.sample

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
apps_dirs:
2-
- "apps/*"
3-
deps_dirs:
4-
- "_build/default/lib/*"
5-
- "_build/test/lib/*"
6-
include_dirs:
7-
- "apps"
8-
- "apps/*/include"
9-
- "_build/*/lib/"
10-
- "_build/*/lib/*/include"
1+
%% -*- mode: erlang; -*-
2+
3+
{"apps_dirs", ["apps/*"]}.
4+
5+
{"deps_dirs", ["_build/default/lib/*", "_build/test/lib/*"]}.
6+
7+
{"include_dirs",
8+
["apps", "apps/*/include", "_build/*/lib", "_build/*/lib/*/include"]}.

erlang_ls.yaml.sample

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apps_dirs:
2+
- "apps/*"
3+
deps_dirs:
4+
- "_build/default/lib/*"
5+
- "_build/test/lib/*"
6+
include_dirs:
7+
- "apps"
8+
- "apps/*/include"
9+
- "_build/*/lib/"
10+
- "_build/*/lib/*/include"

0 commit comments

Comments
 (0)