I personally try to avoid duping vim code whenever possible and rely on the runtime in case the logic is changed in the future (bug fixes, etc). In my implementation I opted for reusing the runtime code by creating a temp buffer (with the original lines in its contents) and thus I am able to call vim.lsp.util.apply_text_edits directly:
Hi @aznhe21 and ty for this plugin!
I was recently acquainted with it as part of a feature request for my plugin https://github.com/ibhagwan/fzf-lua/issues/944.
As part of the implementation I reused your diff generation code (with proper credit in the commit/comments) https://github.com/ibhagwan/fzf-lua/commit/b3b05f9d438736bb1f88aa373476753ddf83f481.
While doing so I noticed you created your own version of
vim.lsp.util.apply_text_edits
that applies the edits to lines input (instead of the original buffer argument): https://github.com/aznhe21/actions-preview.nvim/blob/8f79029a36ab6807478f157538a91ccd4af5858f/lua/actions-preview/action.lua#L75I personally try to avoid duping vim code whenever possible and rely on the runtime in case the logic is changed in the future (bug fixes, etc). In my implementation I opted for reusing the runtime code by creating a temp buffer (with the original lines in its contents) and thus I am able to call
vim.lsp.util.apply_text_edits
directly:So instead of: https://github.com/aznhe21/actions-preview.nvim/blob/8f79029a36ab6807478f157538a91ccd4af5858f/lua/actions-preview/action.lua#L141-L149
I use:
Thought you might be interested should you decide to take a similar approach one day.
Hopefully this helps and thanks again!