refactor!: use updated nvim APIs. From now on requires nvim 0.10
parent
01eeb090ea
commit
dbc30b7122
|
|
@ -4,20 +4,20 @@ local u = require("genghis.utils")
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
---Requests a 'workspace/willRenameFiles' on any running LSP client, that supports it
|
---Requests a 'workspace/willRenameFiles' on any running LSP client, that supports it
|
||||||
---stolen from https://github.com/LazyVim/LazyVim/blob/fecc5faca25c209ed62e3658dd63731e26c0c643/lua/lazyvim/util/init.lua#L304
|
---SOURCE https://github.com/LazyVim/LazyVim/blob/fecc5faca25c209ed62e3658dd63731e26c0c643/lua/lazyvim/util/init.lua#L304
|
||||||
---@param fromName string
|
---@param fromName string
|
||||||
---@param toName string
|
---@param toName string
|
||||||
function M.sendWillRenameToLsp(fromName, toName)
|
function M.sendWillRenameToLsp(fromName, toName)
|
||||||
local clients = vim.lsp.get_active_clients { bufnr = 0 }
|
local clients = vim.lsp.get_clients { bufnr = 0 }
|
||||||
for _, client in ipairs(clients) do
|
for _, client in ipairs(clients) do
|
||||||
if client:supports_method("workspace/willRenameFiles") then
|
if client.supports_method("workspace/willRenameFiles") then
|
||||||
local resp = client.request_sync("workspace/willRenameFiles", {
|
local response = client.request_sync("workspace/willRenameFiles", {
|
||||||
files = {
|
files = {
|
||||||
{ oldUri = vim.uri_from_fname(fromName), newUri = vim.uri_from_fname(toName) },
|
{ oldUri = vim.uri_from_fname(fromName), newUri = vim.uri_from_fname(toName) },
|
||||||
},
|
},
|
||||||
}, 1000)
|
}, 1000, 0)
|
||||||
if resp and resp.result ~= nil then
|
if response and response.result ~= nil then
|
||||||
vim.lsp.util.apply_workspace_edit(resp.result, client.offset_encoding)
|
vim.lsp.util.apply_workspace_edit(response.result, client.offset_encoding)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -26,16 +26,9 @@ end
|
||||||
---@nodiscard
|
---@nodiscard
|
||||||
---@return boolean
|
---@return boolean
|
||||||
function M.lspSupportsRenaming()
|
function M.lspSupportsRenaming()
|
||||||
-- INFO `client:supports_method()` seems to always return true, whatever is
|
local clients = vim.lsp.get_clients { bufnr = 0 }
|
||||||
-- supplied as argument. This does not affect `onRename`, but here we need to
|
|
||||||
-- check for the server_capabilities to properly identify whether our LSP
|
|
||||||
-- supports renaming or not.
|
|
||||||
-- TODO investigate if `client:supports_method()` works in nvim 0.10 or later
|
|
||||||
local clients = vim.lsp.get_active_clients { bufnr = 0 }
|
|
||||||
for _, client in ipairs(clients) do
|
for _, client in ipairs(clients) do
|
||||||
local workspaceCap = client.server_capabilities.workspace
|
if client.supports_method("workspace/willRenameFiles") then return true end
|
||||||
local supports = workspaceCap and workspaceCap.fileOperations and workspaceCap.fileOperations.willRename
|
|
||||||
if supports then return true end
|
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
@ -44,9 +37,7 @@ end
|
||||||
---@param newFilePath string
|
---@param newFilePath string
|
||||||
function M.moveFile(oldFilePath, newFilePath)
|
function M.moveFile(oldFilePath, newFilePath)
|
||||||
local renamed, _ = vim.loop.fs_rename(oldFilePath, newFilePath)
|
local renamed, _ = vim.loop.fs_rename(oldFilePath, newFilePath)
|
||||||
if renamed then
|
if renamed then return true end
|
||||||
return true
|
|
||||||
end
|
|
||||||
---try `fs_copyfile` to support moving across partitions
|
---try `fs_copyfile` to support moving across partitions
|
||||||
local copied, copiedError = vim.loop.fs_copyfile(oldFilePath, newFilePath)
|
local copied, copiedError = vim.loop.fs_copyfile(oldFilePath, newFilePath)
|
||||||
if copied then
|
if copied then
|
||||||
|
|
@ -58,7 +49,10 @@ function M.moveFile(oldFilePath, newFilePath)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
u.notify(("Failed to move %q to %q: %q"):format(oldFilePath, newFilePath, copiedError), "error")
|
u.notify(
|
||||||
|
("Failed to move %q to %q: %q"):format(oldFilePath, newFilePath, copiedError),
|
||||||
|
"error"
|
||||||
|
)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ local M = {}
|
||||||
|
|
||||||
---@param bufnr? number|"#"|"$"
|
---@param bufnr? number|"#"|"$"
|
||||||
function M.bwipeout(bufnr)
|
function M.bwipeout(bufnr)
|
||||||
bufnr = bufnr and vim.fn.bufnr(bufnr) or 0 ---@diagnostic disable-line: param-type-mismatch
|
bufnr = bufnr and vim.fn.bufnr(bufnr) or 0
|
||||||
vim.api.nvim_buf_delete(bufnr, { force = true })
|
vim.api.nvim_buf_delete(bufnr, { force = true })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -20,6 +20,7 @@ function M.notify(msg, level)
|
||||||
vim.notify(msg, vim.log.levels[level:upper()], { title = "nvim-genghis" })
|
vim.notify(msg, vim.log.levels[level:upper()], { title = "nvim-genghis" })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@nodiscard
|
||||||
---@param filepath string
|
---@param filepath string
|
||||||
---@return boolean
|
---@return boolean
|
||||||
function M.fileExists(filepath) return vim.loop.fs_stat(filepath) ~= nil end
|
function M.fileExists(filepath) return vim.loop.fs_stat(filepath) ~= nil end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue