Skip to content

Commit

Permalink
Use file:consult/1 for erlang_ls.config
Browse files Browse the repository at this point in the history
  • Loading branch information
sirikid committed Dec 25, 2021
1 parent 658e8ff commit b0b7713
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
19 changes: 16 additions & 3 deletions apps/els_core/src/els_config.erl
Original file line number Diff line number Diff line change
Expand Up @@ -242,17 +242,30 @@ consult_config([], ReportMissingConfig) ->
{undefined, #{}};
consult_config([Path | Paths], ReportMissingConfig) ->
?LOG_INFO("Reading config file. path=~p", [Path]),
Options = [{map_node_format, map}],
try yamerl:decode_file(Path, Options) of
try consult_file(Path) of
[] -> {Path, #{}};
[Config] -> {Path, Config}
[Config] -> {Path, Config};
{ok, Config} -> {Path, maps:from_list(Config)};
{error, Reason} ->
?LOG_WARNING( "Could not read config file: path=~p class=~p error=~p"
, [Path, error, Reason]),
consult_config(Paths, ReportMissingConfig)
catch
Class:Error ->
?LOG_WARNING( "Could not read config file: path=~p class=~p error=~p"
, [Path, Class, Error]),
consult_config(Paths, ReportMissingConfig)
end.

-spec consult_file(path()) -> [map()] | {ok, [term()]} | {error, term()}.
consult_file(Path) ->
case string:find(Path, ".yaml", trailing) of
nomatch ->
file:consult(Path);
".yaml" ->
yamerl:decode_file(Path, [{map_node_format, map}])
end.

-spec report_missing_config() -> ok.
report_missing_config() ->
Msg =
Expand Down
18 changes: 8 additions & 10 deletions erlang_ls.config.sample
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
apps_dirs:
- "apps/*"
deps_dirs:
- "_build/default/lib/*"
- "_build/test/lib/*"
include_dirs:
- "apps"
- "apps/*/include"
- "_build/*/lib/"
- "_build/*/lib/*/include"
%% -*- mode: erlang; -*-

{"apps_dirs", ["apps/*"]}.

{"deps_dirs", ["_build/default/lib/*", "_build/test/lib/*"]}.

{"include_dirs",
["apps", "apps/*/include", "_build/*/lib", "_build/*/lib/*/include"]}.
10 changes: 10 additions & 0 deletions erlang_ls.yaml.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apps_dirs:
- "apps/*"
deps_dirs:
- "_build/default/lib/*"
- "_build/test/lib/*"
include_dirs:
- "apps"
- "apps/*/include"
- "_build/*/lib/"
- "_build/*/lib/*/include"

0 comments on commit b0b7713

Please sign in to comment.