diff --git a/apps/els_core/src/els_config.erl b/apps/els_core/src/els_config.erl index 2fd3652ce..9f64e3943 100644 --- a/apps/els_core/src/els_config.erl +++ b/apps/els_core/src/els_config.erl @@ -242,15 +242,43 @@ 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 - [] -> {Path, #{}}; - [Config] -> {Path, Config} + 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 file:consult(Path) of + {ok, Config} -> + {ok, maps:from_list(Config)}; + {error, _} when TryYaml -> + try_yaml(Path); + {error, Reason} -> + {error, error, Reason} end. -spec report_missing_config() -> ok. 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"