diff --git a/src/els_config.erl b/src/els_config.erl index 680fc54e3..1bcd4ad6e 100644 --- a/src/els_config.erl +++ b/src/els_config.erl @@ -48,7 +48,8 @@ | plt_path | root_uri | search_paths - | code_reload. + | code_reload + | elvis_config_path. -type path() :: file:filename(). -type state() :: #{ apps_dirs => [path()] @@ -101,6 +102,7 @@ do_initialize(RootUri, Capabilities, {ConfigPath, Config}) -> CtRunTest = maps:get("ct-run-test", Config, #{}), CodePathExtraDirs = maps:get("code_path_extra_dirs", Config, []), ok = add_code_paths(CodePathExtraDirs, RootPath), + ElvisConfigPath = maps:get("elvis_config_path", Config, undefined), %% Passed by the LSP client ok = set(root_uri , RootUri), @@ -117,6 +119,7 @@ do_initialize(RootUri, Capabilities, {ConfigPath, Config}) -> , Runtime)), ok = set('ct-run-test', maps:merge( els_config_ct_run_test:default_config() , CtRunTest)), + ok = set(elvis_config_path, ElvisConfigPath), %% Calculated from the above ok = set(apps_paths , project_paths(RootPath, AppsDirs, false)), ok = set(deps_paths , project_paths(RootPath, DepsDirs, false)), diff --git a/src/els_elvis_diagnostics.erl b/src/els_elvis_diagnostics.erl index 3ee246d87..3c594ca2d 100644 --- a/src/els_elvis_diagnostics.erl +++ b/src/els_elvis_diagnostics.erl @@ -36,9 +36,8 @@ run(Uri) -> RelFile -> %% Note: elvis_core:rock_this requires a file path relative to the %% project root, formatted as a string. - RootPath = els_uri:path(els_config:get(root_uri)), try - Filename = filename:join([RootPath, "elvis.config"]), + Filename = get_elvis_config_path(), Config = elvis_config:from_file(Filename), elvis_core:rock_this(RelFile, Config) of @@ -96,3 +95,13 @@ diagnostic(_File, Name, Msg, Ln, Info) -> , message => Message , relatedInformation => [] }]. + +-spec get_elvis_config_path() -> file:filename_all(). +get_elvis_config_path() -> + case els_config:get(elvis_config_path) of + undefined -> + RootPath = els_uri:path(els_config:get(root_uri)), + filename:join([RootPath, "elvis.config"]); + FilePath -> + FilePath + end.