nvim-lsp-file-operations is a Neovim plugin that adds support for file operations using built-in LSP support.
This plugin works by subscribing to events emitted by either of these plugins (other integrations may be added if needed):
Full implementation of all workspace.fileOperations for the current LSP spec:
workspace/DidCreateworkspace/DidDeleteworkspace/DidRename - Tested in:
workspace/WillCreateworkspace/WillDeleteworkspace/WillRename - Tested in:
If you have use cases for any other operations please open an issue.
[!IMPORTANT] The order in which the plugins are loaded matters!
For example,
neo-tree.nvimmust load beforenvim-lsp-file-operationsfor this to work, sonvim-lsp-file-operationsdepends onneo-tree.nvim, not the other way around!
require("pckr").add({
"antosha417/nvim-lsp-file-operations",
-- Uncomment whichever supported plugin(s) you use
-- requires = {
-- "nvim-tree/nvim-tree.lua",
-- "nvim-neo-tree/neo-tree.nvim",
-- "simonmclean/triptych.nvim"
-- },
config = function()
require("lsp-file-operations").setup()
end,
})
return {
{
"antosha417/nvim-lsp-file-operations",
-- Uncomment whichever supported plugin(s) you use
-- dependencies = {
-- "nvim-tree/nvim-tree.lua",
-- "nvim-neo-tree/neo-tree.nvim",
-- "simonmclean/triptych.nvim"
-- },
config = function()
require("lsp-file-operations").setup()
end,
},
}
require("lsp-file-operations").setup()
This is equivalent to:
require("lsp-file-operations").setup {
-- Used to see debug logs, located at `vim.fn.stdpath("cache") .. "/lsp-file-operations.log"`
debug = false,
-- Select which file operations to enable
operations = {
didCreateFiles = true,
didDeleteFiles = true,
didRenameFiles = true,
willCreateFiles = true,
willDeleteFiles = true,
willRenameFiles = true,
},
-- How long to wait (in milliseconds) for file rename information before cancelling
timeout_ms = 10000,
}
Some LSP servers also expect to be informed about the extended client capabilities. Follow any of the instructions below based on your Neovim version:
You can use vim.lsp.config() to set the global capabilities for every server:
-- Set global defaults for all servers
vim.lsp.config("*", {
capabilities = vim.tbl_deep_extend(
"force",
vim.lsp.protocol.make_client_capabilities(),
-- ANY OTHER CAPABILITIES. e.g. for `blink.cmp`, etc.
require("lsp-file-operations").default_capabilities()
)
})
If you use nvim-lspconfig you can configure the default client capabilities for all servers:
local lspconfig = require("lspconfig")
-- Set global defaults for all servers
lspconfig.util.default_config = vim.tbl_extend(
"force",
lspconfig.util.default_config,
{
capabilities = vim.tbl_deep_extend(
"force",
vim.lsp.protocol.make_client_capabilities(),
-- ANY OTHER CAPABILITIES. e.g. for `blink.cmp`, etc.
require("lsp-file-operations").default_capabilities()
)
}
)
PRs are always welcome.
This project uses StyLua. Please run stylua . before committing.