smjonas / inc-rename.nvim

Incremental LSP renaming based on Neovim's command-preview feature.
MIT License
667 stars 9 forks source link

feat: add post_hook callback #14

Closed zegervdv closed 2 years ago

zegervdv commented 2 years ago

Adds a callback that is called after the rename and receives the results of the rename operation. Can be used to e.g. load the applied changes in the quickfix list:

require('inc-rename').setup {
  post_hook = function (result)
    local changed = {}
    for uri, changes in pairs(result.changes) do
      local bufnr = vim.uri_to_bufnr(uri)
      for _, edits in ipairs(changes) do
        table.insert(changed, {
          bufnr = bufnr,
          lnum = edits.range.start.line + 1,
          col = edits.range.start.character + 1,
          text = vim.api.nvim_buf_get_lines(bufnr, edits.range.start.line, edits.range.start.line + 1, false)[1],
        })
      end
    end
    vim.fn.setqflist(changed, 'r')
  end
}
smjonas commented 2 years ago

Nice, seems useful! Can you move the function call out of the if M.config.show_message then conditional? Please also add a short description to the customization section in the readme, then I'll merge.

zegervdv commented 2 years ago

Oops stupid mistake.

I'll add some docs too when I get back my computer.

zegervdv commented 2 years ago

Fixed

smjonas commented 2 years ago

Thank you!