/nvim-lsp-file-operations

Neovim plugin that adds support for file operations using built-in LSP

Primary LanguageLuaApache License 2.0Apache-2.0

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 nvim-tree and neo-tree. But other integrations are possible.

Features

Full implementation of all workspace.fileOperations in the current lsp spec:

scala.refactoring.example.mp4

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

Installation

For Nvim-tree Users

use {
  "antosha417/nvim-lsp-file-operations",
  requires = {
    "nvim-lua/plenary.nvim",
    "nvim-tree/nvim-tree.lua",
  },
  config = function()
    require("lsp-file-operations").setup()
  end,
}

For Neo-tree Users

use {
  "antosha417/nvim-lsp-file-operations",
  requires = {
    "nvim-lua/plenary.nvim",
    "nvim-neo-tree/neo-tree.nvim",
  },
  config = function()
    require("lsp-file-operations").setup()
  end,
}

Using lazy.nvim

Note that the config function will let you skip the setup step.

For Nvim-tree Users

return {
  {
    "antosha417/nvim-lsp-file-operations",
    dependencies = {
      "nvim-lua/plenary.nvim",
      "nvim-tree/nvim-tree.lua",
    },
    config = function()
      require("lsp-file-operations").setup()
    end,
  },
}

For Neo-tree Users

return {
  {
    "antosha417/nvim-lsp-file-operations",
    dependencies = {
      "nvim-lua/plenary.nvim",
      "nvim-neo-tree/neo-tree.nvim",
    },
    config = function()
      require("lsp-file-operations").setup()
    end,
  },
}

Please note that the order that the plugins load in is important, neo-tree must load before nvim-lsp-file-operations for it to work, so nvim-lsp-file-operations depends on neo-tree and not the other way around.

Setup

require("lsp-file-operations").setup()

This is equivalent to:

require("lsp-file-operations").setup {
  -- used to see debug logs in file `vim.fn.stdpath("cache") .. lsp-file-operations.log`
  debug = false,
  -- select which file operations to enable
  operations = {
    willRenameFiles = true,
    didRenameFiles = true,
    willCreateFiles = true,
    didCreateFiles = true,
    willDeleteFiles = true,
    didDeleteFiles = true,
  },
  -- how long to wait (in milliseconds) for file rename information before cancelling
  timeout_ms = 10000,
}

Contributing

PRs are always welcome.