mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-06-23 17:28:57 +02:00
feat(mini.files): added lsp rename support to mini.files
This commit is contained in:
parent
fe341e6b97
commit
4ff51cd678
3 changed files with 30 additions and 13 deletions
|
@ -59,23 +59,12 @@ return {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
config = function(_, opts)
|
config = function(_, opts)
|
||||||
opts.event_handlers = opts.event_handlers or {}
|
|
||||||
|
|
||||||
local function on_move(data)
|
local function on_move(data)
|
||||||
local clients = vim.lsp.get_active_clients()
|
Util.on_rename(data.source, data.destination)
|
||||||
for _, client in ipairs(clients) do
|
|
||||||
if client:supports_method("workspace/willRenameFiles") then
|
|
||||||
local resp = client.request_sync("workspace/willRenameFiles", {
|
|
||||||
files = { { oldUri = vim.uri_from_fname(data.source), newUri = vim.uri_from_fname(data.destination) } },
|
|
||||||
}, 1000)
|
|
||||||
if resp and resp.result ~= nil then
|
|
||||||
vim.lsp.util.apply_workspace_edit(resp.result, client.offset_encoding)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local events = require("neo-tree.events")
|
local events = require("neo-tree.events")
|
||||||
|
opts.event_handlers = opts.event_handlers or {}
|
||||||
vim.list_extend(opts.event_handlers, {
|
vim.list_extend(opts.event_handlers, {
|
||||||
{ event = events.FILE_MOVED, handler = on_move },
|
{ event = events.FILE_MOVED, handler = on_move },
|
||||||
{ event = events.FILE_RENAMED, handler = on_move },
|
{ event = events.FILE_RENAMED, handler = on_move },
|
||||||
|
|
|
@ -53,5 +53,12 @@ return {
|
||||||
vim.keymap.set("n", "g.", toggle_dotfiles, { buffer = buf_id })
|
vim.keymap.set("n", "g.", toggle_dotfiles, { buffer = buf_id })
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
vim.api.nvim_create_autocmd("User", {
|
||||||
|
pattern = "MiniFilesActionRename",
|
||||||
|
callback = function(event)
|
||||||
|
require("lazyvim.util").on_rename(event.data.from, event.data.to)
|
||||||
|
end,
|
||||||
|
})
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
|
@ -299,4 +299,25 @@ function M.changelog()
|
||||||
vim.diagnostic.disable(float.buf)
|
vim.diagnostic.disable(float.buf)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param from string
|
||||||
|
---@param to string
|
||||||
|
function M.on_rename(from, to)
|
||||||
|
local clients = vim.lsp.get_active_clients()
|
||||||
|
for _, client in ipairs(clients) do
|
||||||
|
if client:supports_method("workspace/willRenameFiles") then
|
||||||
|
local resp = client.request_sync("workspace/willRenameFiles", {
|
||||||
|
files = {
|
||||||
|
{
|
||||||
|
oldUri = vim.uri_from_fname(from),
|
||||||
|
newUri = vim.uri_from_fname(to),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}, 1000)
|
||||||
|
if resp and resp.result ~= nil then
|
||||||
|
vim.lsp.util.apply_workspace_edit(resp.result, client.offset_encoding)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue