Skip to content

Commit

Permalink
Fix crash in code actions
Browse files Browse the repository at this point in the history
  • Loading branch information
plux committed Oct 11, 2024
1 parent ed1daaa commit b3e9cbb
Showing 1 changed file with 36 additions and 26 deletions.
62 changes: 36 additions & 26 deletions apps/els_lsp/src/els_code_actions.erl
Original file line number Diff line number Diff line change
Expand Up @@ -138,19 +138,24 @@ define_macro(Uri, Range, _Data, [Macro0]) ->
[module, include, include_lib, define],
BeforeRange
),
#{range := #{to := {Line, _}}} = lists:last(els_poi:sort(POIs)),
[
make_edit_action(
Uri,
<<"Define ", Macro0/binary>>,
?CODE_ACTION_KIND_QUICKFIX,
NewText,
els_protocol:range(#{
to => {Line + 1, 1},
from => {Line + 1, 1}
})
)
].
case POIs of
[] ->
[];
_ ->
#{range := #{to := {Line, _}}} = lists:last(els_poi:sort(POIs)),
[
make_edit_action(
Uri,
<<"Define ", Macro0/binary>>,
?CODE_ACTION_KIND_QUICKFIX,
NewText,
els_protocol:range(#{
to => {Line + 1, 1},
from => {Line + 1, 1}
})
)
]
end.

-spec define_record(uri(), range(), binary(), [binary()]) -> [map()].
define_record(Uri, Range, _Data, [Record]) ->
Expand All @@ -163,19 +168,24 @@ define_record(Uri, Range, _Data, [Record]) ->
[module, include, include_lib, record],
BeforeRange
),
Line = end_line(lists:last(els_poi:sort(POIs))),
[
make_edit_action(
Uri,
<<"Define record ", Record/binary>>,
?CODE_ACTION_KIND_QUICKFIX,
NewText,
els_protocol:range(#{
to => {Line + 1, 1},
from => {Line + 1, 1}
})
)
].
case POIs of
[] ->
[];
_ ->
Line = end_line(lists:last(els_poi:sort(POIs))),
[
make_edit_action(
Uri,
<<"Define record ", Record/binary>>,
?CODE_ACTION_KIND_QUICKFIX,
NewText,
els_protocol:range(#{
to => {Line + 1, 1},
from => {Line + 1, 1}
})
)
]
end.

-spec end_line(els_poi:poi()) -> non_neg_integer().
end_line(#{data := #{value_range := #{to := {Line, _}}}}) ->
Expand Down

0 comments on commit b3e9cbb

Please sign in to comment.