Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the default erlang format for erlang_ls.config #1083

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Apply comments
sirikid committed Dec 25, 2021
commit a9cbbb447f4aea1fcc1bc73ebcef052871947f5f
46 changes: 35 additions & 11 deletions apps/els_core/src/els_config.erl
Original file line number Diff line number Diff line change
@@ -242,19 +242,43 @@ consult_config([], ReportMissingConfig) ->
{undefined, #{}};
consult_config([Path | Paths], ReportMissingConfig) ->
?LOG_INFO("Reading config file. path=~p", [Path]),
try consult_file(Path) of
[] -> {Path, #{}};
[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)
Result =
case filename:extension(Path) of
".yaml" ->
try_yaml(Path);
".config" ->
try_eterm(Path, _TryYaml = true)
end,
case Result of
{ok, Config} ->
{Path, Config};
{error, Class, Error} ->
?LOG_WARNING("Could not read config file: path=~p class=~p error=~p",
[Path, Class, Error]),
consult_config(Paths, ReportMissingConfig)
end.

-spec try_yaml(path()) -> {ok, map()} | {error, atom(), term()}.
try_yaml(Path) ->
try yamerl:decode_file(Path, [{map_node_format, map}]) of
[] ->
{ok, #{}};
[Config] ->
{ok, Config}
catch
Class:Error ->
?LOG_WARNING( "Could not read config file: path=~p class=~p error=~p"
, [Path, Class, Error]),
consult_config(Paths, ReportMissingConfig)
{error, Class, Error}
end.

-spec try_eterm(path(), boolean()) -> {ok, map()} | {error, atom(), term()}.
try_eterm(Path, TryYaml) ->
case consult_file(Path) of
{ok, Config} ->
{ok, maps:from_list(Config)};
{error, _} when TryYaml ->
try_yaml(Path);
{error, Reason} ->
{error, error, Reason}
end.

-spec consult_file(path()) -> [map()] | {ok, [term()]} | {error, term()}.