Skip to content

Commit

Permalink
Merge pull request #942 from erlang-ls/941-enable-diagnostics-by-default
Browse files Browse the repository at this point in the history
[#941] Enable diagnostics by default
  • Loading branch information
robertoaloi authored Mar 13, 2021
2 parents f2f3cd8 + 54d2c9f commit c5370bd
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 39 deletions.
2 changes: 1 addition & 1 deletion apps/els_lsp/src/els_bound_var_in_pattern_diagnostics.erl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

-spec is_default() -> boolean().
is_default() ->
false.
true.

-spec run(uri()) -> [els_diagnostics:diagnostic()].
run(Uri) ->
Expand Down
2 changes: 1 addition & 1 deletion apps/els_lsp/src/els_unused_includes_diagnostics.erl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

-spec is_default() -> boolean().
is_default() ->
false.
true.

-spec run(uri()) -> [els_diagnostics:diagnostic()].
run(Uri) ->
Expand Down
2 changes: 1 addition & 1 deletion apps/els_lsp/src/els_unused_macros_diagnostics.erl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

-spec is_default() -> boolean().
is_default() ->
false.
true.

-spec run(uri()) -> [els_diagnostics:diagnostic()].
run(Uri) ->
Expand Down
42 changes: 8 additions & 34 deletions apps/els_lsp/test/els_diagnostics_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,6 @@ end_per_suite(Config) ->
els_test_utils:end_per_suite(Config).

-spec init_per_testcase(atom(), config()) -> config().
init_per_testcase(bound_var_in_pattern, Config) ->
meck:new(els_bound_var_in_pattern_diagnostics, [passthrough, no_link]),
meck:expect(els_bound_var_in_pattern_diagnostics, is_default, 0, true),
els_mock_diagnostics:setup(),
els_test_utils:init_per_testcase(bound_var_in_pattern, Config);
init_per_testcase(TestCase, Config) when TestCase =:= code_reload orelse
TestCase =:= code_reload_sticky_mod ->
mock_rpc(),
Expand All @@ -93,16 +88,6 @@ init_per_testcase(TestCase, Config)
meck:expect(els_crossref_diagnostics, is_default, 0, true),
els_mock_diagnostics:setup(),
els_test_utils:init_per_testcase(TestCase, Config);
init_per_testcase(unused_includes, Config) ->
meck:new(els_unused_includes_diagnostics, [passthrough, no_link]),
meck:expect(els_unused_includes_diagnostics, is_default, 0, true),
els_mock_diagnostics:setup(),
els_test_utils:init_per_testcase(unused_includes, Config);
init_per_testcase(unused_macros, Config) ->
meck:new(els_unused_macros_diagnostics, [passthrough, no_link]),
meck:expect(els_unused_macros_diagnostics, is_default, 0, true),
els_mock_diagnostics:setup(),
els_test_utils:init_per_testcase(unused_includes, Config);
init_per_testcase(code_path_extra_dirs, Config) ->
meck:new(yamerl, [passthrough, no_link]),
Content = <<"code_path_extra_dirs:\n",
Expand All @@ -128,11 +113,6 @@ init_per_testcase(TestCase, Config) ->
els_test_utils:init_per_testcase(TestCase, Config).

-spec end_per_testcase(atom(), config()) -> ok.
end_per_testcase(bound_var_in_pattern, Config) ->
meck:unload(els_bound_var_in_pattern_diagnostics),
els_test_utils:end_per_testcase(bound_var_in_pattern, Config),
els_mock_diagnostics:teardown(),
ok;
end_per_testcase(TestCase, Config) when TestCase =:= code_reload orelse
TestCase =:= code_reload_sticky_mod ->
unmock_rpc(),
Expand All @@ -147,16 +127,6 @@ end_per_testcase(TestCase, Config)
els_test_utils:end_per_testcase(TestCase, Config),
els_mock_diagnostics:teardown(),
ok;
end_per_testcase(unused_includes, Config) ->
meck:unload(els_unused_includes_diagnostics),
els_test_utils:end_per_testcase(unused_includes, Config),
els_mock_diagnostics:teardown(),
ok;
end_per_testcase(unused_macros, Config) ->
meck:unload(els_unused_macros_diagnostics),
els_test_utils:end_per_testcase(unused_macros, Config),
els_mock_diagnostics:teardown(),
ok;
end_per_testcase(TestCase, Config)
when TestCase =:= code_path_extra_dirs orelse
TestCase =:= use_long_names ->
Expand Down Expand Up @@ -214,14 +184,16 @@ compiler(Config) ->
els_mock_diagnostics:subscribe(),
ok = els_client:did_save(Uri),
Diagnostics = els_mock_diagnostics:wait_until_complete(),
?assertEqual(4, length(Diagnostics)),
?assertEqual(5, length(Diagnostics)),
Warnings = [D || #{severity := ?DIAGNOSTIC_WARNING} = D <- Diagnostics],
Errors = [D || #{severity := ?DIAGNOSTIC_ERROR} = D <- Diagnostics],
?assertEqual(1, length(Warnings)),
?assertEqual(2, length(Warnings)),
?assertEqual(3, length(Errors)),
WarningRanges = [ Range || #{range := Range} <- Warnings],
ExpectedWarningRanges = [ #{'end' => #{character => 0, line => 7},
start => #{character => 0, line => 6}}
, #{'end' => #{character => 35, line => 3},
start => #{character => 0, line => 3}}
],
?assertEqual(ExpectedWarningRanges, WarningRanges),
ErrorRanges = [ Range || #{range := Range} <- Errors],
Expand Down Expand Up @@ -337,12 +309,14 @@ compiler_with_parse_transform_included(Config) ->
els_mock_diagnostics:subscribe(),
ok = els_client:did_save(Uri),
Diagnostics = els_mock_diagnostics:wait_until_complete(),
?assertEqual(1, length(Diagnostics)),
?assertEqual(2, length(Diagnostics)),
Warnings = [D || #{severity := ?DIAGNOSTIC_WARNING} = D <- Diagnostics],
?assertEqual(1, length(Warnings)),
?assertEqual(2, length(Warnings)),
WarningRanges = [ Range || #{range := Range} <- Warnings],
ExpectedWarningsRanges = [ #{ 'end' => #{character => 0, line => 7}
, start => #{character => 0, line => 6}}
, #{ 'end' => #{character => 32, line => 4}
, start => #{character => 0, line => 4}}
],
?assertEqual(ExpectedWarningsRanges, WarningRanges),
ok.
Expand Down
13 changes: 11 additions & 2 deletions apps/els_lsp/test/els_initialization_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,13 @@ initialize_diagnostics_custom(Config) ->
ConfigPath = filename:join(DataDir, "diagnostics_custom.config"),
InitOpts = #{ <<"erlang">> => #{ <<"config_path">> => ConfigPath }},
els_client:initialize(RootUri, InitOpts),
Expected = [<<"compiler">>, <<"crossref">>, <<"dialyzer">>],
Expected = [ <<"bound_var_in_pattern">>
, <<"compiler">>
, <<"crossref">>
, <<"dialyzer">>
, <<"unused_includes">>
, <<"unused_macros">>
],
Result = els_diagnostics:enabled_diagnostics(),
?assertEqual(Expected, Result),
ok.
Expand All @@ -141,10 +147,13 @@ initialize_diagnostics_invalid(Config) ->
InitOpts = #{ <<"erlang">> => #{ <<"config_path">> => ConfigPath }},
els_client:initialize(RootUri, InitOpts),
Result = els_diagnostics:enabled_diagnostics(),
Expected = [ <<"compiler">>
Expected = [ <<"bound_var_in_pattern">>
, <<"compiler">>
, <<"crossref">>
, <<"dialyzer">>
, <<"elvis">>
, <<"unused_includes">>
, <<"unused_macros">>
],
?assertEqual(Expected, Result),
ok.
Expand Down

0 comments on commit c5370bd

Please sign in to comment.