Skip to content

Commit

Permalink
[#1098] More recordy name, usort list, no dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
robertoaloi committed Sep 30, 2021
1 parent e43534b commit 2856783
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
12 changes: 3 additions & 9 deletions apps/els_lsp/src/els_unused_record_fields_diagnostics.erl
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,13 @@ source() ->
find_unused_record_fields(Document) ->
Definitions = els_dt_document:pois(Document, [record_def_field]),
Usages = els_dt_document:pois(Document, [record_field]),
UsagesIds = [Id || #{id := Id} <- Usages],
UsagesIds = lists:usort([Id || #{id := Id} <- Usages]),
[POI || #{id := Id} = POI <- Definitions, not lists:member(Id, UsagesIds)].

-spec make_diagnostic(poi()) -> els_diagnostics:diagnostic().
make_diagnostic(#{id := POIId, range := POIRange}) ->
make_diagnostic(#{id := {RecName, RecField}, range := POIRange}) ->
Range = els_protocol:range(POIRange),
FullName =
case POIId of
{RecordName, RecordField} ->
els_utils:to_binary(
lists:flatten(io_lib:format("~p/~p", [RecordName, RecordField])));
Id -> atom_to_binary(Id, utf8)
end,
FullName = els_utils:to_binary(io_lib:format("#~p.~p", [RecName, RecField])),
Message = <<"Unused record field: ", FullName/binary>>,
Severity = ?DIAGNOSTIC_WARNING,
Source = source(),
Expand Down
2 changes: 1 addition & 1 deletion apps/els_lsp/test/els_diagnostics_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ unused_record_fields(Config) ->
els_mock_diagnostics:subscribe(),
ok = els_client:did_save(Uri),
Diagnostics = els_mock_diagnostics:wait_until_complete(),
Expected = [ #{ message => <<"Unused record field: unused_field/field_d">>
Expected = [ #{ message => <<"Unused record field: #unused_field.field_d">>
, range =>
#{ 'end' => #{character => 39, line => 5}
, start => #{character => 32, line => 5}
Expand Down

0 comments on commit 2856783

Please sign in to comment.