Skip to content
Projets

antosha417/nvim-lsp-file-operations

Voir sur GitHub

À propos

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

Autres projets

Comment ces chiffres sont mesurés

What you can do

  • workspace/DidCreate
  • workspace/DidDelete
  • lua-language-server
  • workspace/WillCreate

Progression mesurée des étoiles

in 24h
0
in 7 days
0
in 15 days
+1
in 1 month
Historique en cours

Variations nettes sur des périodes qui se chevauchent, pas des totaux quotidiens. Les mesures absentes restent vides. Les étoiles indiquent l’intérêt, pas la qualité.

README.md

Original

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

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

Avoid installing this plugin as a dependency for either nvim-tree.lua, neo-tree and/or triptych!

For example, neo-tree.nvim must already be loaded before nvim-lsp-file-operations for this to work, so nvim-lsp-file-operations depends on neo-tree.nvim, not the other way around!

pckr.nvim
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,
})
lazy.nvim
return {
  {
    "antosha417/nvim-lsp-file-operations",
    -- cmd = 'LFO', -- Uncomment this if you wish to lazy-load by using the `:LFO` user command

    -- 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,
  },
}
vim.pack
vim.pack.add({
  { src = "https://github.com/antosha417/nvim-lsp-file-operations" },

  -- Uncomment whichever supported plugin(s) you use
  -- { src = "https://github.com/nvim-tree/nvim-tree.lua" },
  -- { src = "https://github.com/nvim-neo-tree/neo-tree.nvim" },
  -- { src = "https://github.com/simonmclean/triptych.nvim" },
})

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

Setup

Simply call:

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

The default options are:

{
  -- If `true`, allows the plugin to handle auto-saving after making LSP operations
  auto_save = false,

  -- 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,
}

LSP Capabilities

Some LSP servers also expect to be informed about the extended client capabilities. Follow any of the instructions below based on your Neovim version:

Neovim v0.11 or later

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()
  )
})
Neovim older than v0.11

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

User Command

[!NOTE] The command comes with <Tab> completion aswell.

This plugin comes with the :LFO user command:

:LFO create <PATH/TO/FILE>                         " Create a file in the current workspace
:LFO delete <PATH/TO/FILE>                         " Delete a file in the current workspace
:LFO rename <PATH/TO/NEW_FILE>                     " Rename the current buffer's file to the new path
:LFO rename <PATH/TO/OLD_FILE> <PATH/TO/NEW_FILE>  " Rename an existing file path to a new path
:LFO log                                           " Opens log file in a new tab

API

You can also trigger any of these events manually from the main module. Credits to @Crysthamus as the implementation was based on theirs.

create()

You can now trigger a workspace event for file creation (willCreate and didCreate):

require("lsp-file-operations").create("<PATH/TO/FILE>")

delete()

You can now trigger a workspace event for file deletion (willDelete and didDelete):

require("lsp-file-operations").delete("<PATH/TO/FILE>")

rename()

You can now trigger a workspace event for file renaming (willRename and didRename):

-- Renames the current file
require("lsp-file-operations").rename(
  "<PATH/TO/NEW_FILE>" -- `new_name`
)

-- Renames the first file into the second one
require("lsp-file-operations").rename(
  "<PATH/TO/OLD_FILE>", -- `old_name`
  "<PATH/TO/NEW_FILE>" -- `new_name`
)

Contributing

PRs are always welcome.

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


Credits


License

Apache-2.0

Explorer des projets similaires

Chargement…