Skip to content

Commit

Permalink
Avoid negative line numbers in elvis diagnostics. (erlang-ls#1233)
Browse files Browse the repository at this point in the history
  • Loading branch information
ztion committed Mar 8, 2022
1 parent dc5ece1 commit 4e288d3
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion apps/els_lsp/src/els_elvis_diagnostics.erl
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,11 @@ format_item(_Name, []) ->
-spec diagnostic(any(), any(), integer(), [any()],
els_diagnostics:severity()) -> [map()].
diagnostic(Name, Msg, Ln, Info, Severity) ->
%% Avoid negative line numbers
DiagLine = make_protocol_line(Ln),
FMsg = io_lib:format(Msg, Info),
Range = els_protocol:range(#{from => {Ln, 1}, to => {Ln + 1, 1}}),
Range = els_protocol:range(#{ from => {DiagLine, 1}
, to => {DiagLine + 1, 1}}),
Message = els_utils:to_binary(FMsg),
[#{ range => Range
, severity => Severity
Expand All @@ -102,6 +105,12 @@ diagnostic(Name, Msg, Ln, Info, Severity) ->
, relatedInformation => []
}].

-spec make_protocol_line(Line :: number()) -> number().
make_protocol_line(Line) when Line =< 0 ->
1;
make_protocol_line(Line) ->
Line.

-spec get_elvis_config_path() -> file:filename_all().
get_elvis_config_path() ->
case els_config:get(elvis_config_path) of
Expand Down

0 comments on commit 4e288d3

Please sign in to comment.