Skip to content

Commit

Permalink
Merge pull request #850 from define-null/defnull/elvis_path
Browse files Browse the repository at this point in the history
Provide elvis_path option
  • Loading branch information
robertoaloi committed Jan 8, 2021
2 parents d7caa7d + 121349e commit 9a41d0e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/els_config.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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()]
Expand Down Expand Up @@ -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),
Expand All @@ -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)),
Expand Down
13 changes: 11 additions & 2 deletions src/els_elvis_diagnostics.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.

0 comments on commit 9a41d0e

Please sign in to comment.