From 2756730e759c748305e33fe784260131d92af067 Mon Sep 17 00:00:00 2001 From: Matt Leong Date: Wed, 27 Oct 2021 21:39:25 -0700 Subject: [PATCH] feat(lsp): show name change in notification --- lua/cosmic/core/theme/ui.lua | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lua/cosmic/core/theme/ui.lua b/lua/cosmic/core/theme/ui.lua index 6e8b223..b849f68 100644 --- a/lua/cosmic/core/theme/ui.lua +++ b/lua/cosmic/core/theme/ui.lua @@ -62,13 +62,17 @@ function M.rename() vim.notify(("Error running LSP query '%s': %s"):format(method, err), vim.log.levels.ERROR) return end + -- echo the resulting changes + local new_word = '' if result and result.changes then local msg = '' for f, c in pairs(result.changes) do + new_word = c[1].newText msg = msg .. ('%d changes -> %s'):format(#c, utils.get_relative_path(f)) .. '\n' end - msg = msg:sub(1, #msg - 1) + local currName = vim.fn.expand('') + msg = msg .. ('\n%s -> %s'):format(currName, new_word) vim.notify(msg, vim.log.levels.INFO) end end @@ -77,14 +81,14 @@ function M.rename() end function M._rename() - local newName = vim.trim(vim.fn.getline('.'):sub(5, -1)) + local new_name = vim.trim(vim.fn.getline('.'):sub(5, -1)) vim.cmd([[q!]]) local params = lsp.util.make_position_params() - local currName = vim.fn.expand('') - if not (newName and #newName > 0) or newName == currName then + local curr_name = vim.fn.expand('') + if not (new_name and #new_name > 0) or new_name == curr_name then return end - params.newName = newName + params.newName = new_name lsp.buf_request(0, 'textDocument/rename', params, handler) end end