Issafalcon / lsp-overloads.nvim

Extends the native nvim-lsp handlers to allow easier navigation through method overloads.
MIT License
88 stars 4 forks source link

fix: wrap mapset() in nvim_buf_call #43

Closed AThePeanut4 closed 1 month ago

AThePeanut4 commented 2 months ago

From the vim docs for mapset():

mapset({mode}, {abbr}, {dict})                                        *mapset()*
mapset({dict})
        Restore a mapping from a dictionary, possibly returned by
        |maparg()| or |maplist()|.  A buffer mapping, when dict.buffer
        is true, is set on the current buffer; it is up to the caller
        to ensure that the intended buffer is the current buffer. This
        feature allows copying mappings from one buffer to another.

So since mapset() only restores mappings to the current buffer, previous mappings are not restored properly if the popup closes while the cursor is in another buffer. This can happen if e.g. switching to a different window while the popup is open or if the popup itself is focused and then closed with i.e. <C-w>q.

The fix is to temporarily set the current buffer by wrapping the call in vim.api.nvim_buf_call.

And then I also replaced the 0 and 1 arguments with false and true - luals was complaining about incorrect types.