feat(lsp): show name change in notification
This commit is contained in:
parent
f7d9085a5f
commit
2756730e75
1 changed files with 9 additions and 5 deletions
|
@ -62,13 +62,17 @@ function M.rename()
|
||||||
vim.notify(("Error running LSP query '%s': %s"):format(method, err), vim.log.levels.ERROR)
|
vim.notify(("Error running LSP query '%s': %s"):format(method, err), vim.log.levels.ERROR)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- echo the resulting changes
|
-- echo the resulting changes
|
||||||
|
local new_word = ''
|
||||||
if result and result.changes then
|
if result and result.changes then
|
||||||
local msg = ''
|
local msg = ''
|
||||||
for f, c in pairs(result.changes) do
|
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'
|
msg = msg .. ('%d changes -> %s'):format(#c, utils.get_relative_path(f)) .. '\n'
|
||||||
end
|
end
|
||||||
msg = msg:sub(1, #msg - 1)
|
local currName = vim.fn.expand('<cword>')
|
||||||
|
msg = msg .. ('\n%s -> %s'):format(currName, new_word)
|
||||||
vim.notify(msg, vim.log.levels.INFO)
|
vim.notify(msg, vim.log.levels.INFO)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -77,14 +81,14 @@ function M.rename()
|
||||||
end
|
end
|
||||||
|
|
||||||
function M._rename()
|
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!]])
|
vim.cmd([[q!]])
|
||||||
local params = lsp.util.make_position_params()
|
local params = lsp.util.make_position_params()
|
||||||
local currName = vim.fn.expand('<cword>')
|
local curr_name = vim.fn.expand('<cword>')
|
||||||
if not (newName and #newName > 0) or newName == currName then
|
if not (new_name and #new_name > 0) or new_name == curr_name then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
params.newName = newName
|
params.newName = new_name
|
||||||
lsp.buf_request(0, 'textDocument/rename', params, handler)
|
lsp.buf_request(0, 'textDocument/rename', params, handler)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue