From b0b77130db9e3e62de31ea12b03391920d1cc5be Mon Sep 17 00:00:00 2001 From: Ivan Sokolov Date: Sun, 12 Sep 2021 05:08:57 +0300 Subject: [PATCH] Use file:consult/1 for erlang_ls.config --- apps/els_core/src/els_config.erl | 19 ++++++++++++++++--- erlang_ls.config.sample | 18 ++++++++---------- erlang_ls.yaml.sample | 10 ++++++++++ 3 files changed, 34 insertions(+), 13 deletions(-) create mode 100644 erlang_ls.yaml.sample diff --git a/apps/els_core/src/els_config.erl b/apps/els_core/src/els_config.erl index 2fd3652ce..e22d73b8a 100644 --- a/apps/els_core/src/els_config.erl +++ b/apps/els_core/src/els_config.erl @@ -242,10 +242,14 @@ 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" @@ -253,6 +257,15 @@ consult_config([Path | Paths], ReportMissingConfig) -> 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 = diff --git a/erlang_ls.config.sample b/erlang_ls.config.sample index 45d1ea58b..5db83fa2f 100644 --- a/erlang_ls.config.sample +++ b/erlang_ls.config.sample @@ -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"]}. diff --git a/erlang_ls.yaml.sample b/erlang_ls.yaml.sample new file mode 100644 index 000000000..45d1ea58b --- /dev/null +++ b/erlang_ls.yaml.sample @@ -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"