antosha417/nvim-lsp-file-operations

github github
lsp
stars 429
issues 5
subscribers 5
forks 25
CREATED

UPDATED


nvim-lsp-file-operations

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):

https://user-images.githubusercontent.com/14187674/211327507-39f21a74-0a43-43f0-ba3e-91109125286c.mp4


Features

Full implementation of all workspace.fileOperations for the current LSP spec:

If you have use cases for any other operations please open an issue.


Table of Contents


Installation

[!IMPORTANT] The order in which the plugins are loaded matters!

For example, neo-tree.nvim must load before nvim-lsp-file-operations for this to work, so nvim-lsp-file-operations depends on neo-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,
  },
}

Setup

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()
    )
  }
)

Contributing

PRs are always welcome.

This project uses StyLua. Please run stylua . before committing.


License

Apache-2.0