Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash in code actions #1565

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix crash in code actions
plux committed Oct 11, 2024
commit b3e9cbb8e9179008ee5823faae33916883ac6acb
62 changes: 36 additions & 26 deletions apps/els_lsp/src/els_code_actions.erl
Original file line number Diff line number Diff line change
@@ -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]) ->
@@ -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, _}}}}) ->