nvim-tree / nvim-tree/nvim-tree.lua

implement `didRenameFiles`

Open
#2,047 21 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

API PR please QOL
Dominant language
Lua
Stars
8.6k
Forks
639
Avg merge
1d 14h
Merged PRs (30d)
2

Description

I came up with this, it would be great if that was handled by default :)

https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_didRenameFiles

EDIT: fix wrong implementation and add WillRenameNode

local function make_rename_params(old_fname, new_fname)
    return {
        files = {
            {
                oldUri = vim.uri_from_fname(old_fname),
                newUri = vim.uri_from_fname(new_fname),
            },
        },
    }
end

local Event = api.events.Event
api.events.subscribe(Event.NodeRenamed, function(data)
    local clients = vim.lsp.get_active_clients()
    local params = make_rename_params(data.old_name, data.new_name)
    for _, client in ipairs(clients) do
        local didRename = vim.tbl_get(client, "server_capabilities", "workspace", "fileOperations", "didRename")
        if didRename ~= nil then
            client.notify("workspace/didRenameFiles", params)
        end
    end
end)

api.events.subscribe(Event.WillRenameNode, function(data)
    local clients = vim.lsp.get_active_clients()
    local params = make_rename_params(data.old_name, data.new_name)
    for _, client in ipairs(clients) do
        local willRename = vim.tbl_get(client, "server_capabilities", "workspace", "fileOperations", "willRename")
        if willRename ~= nil then
            local resp = client.request_sync("workspace/willRenameFiles", params, 1000)
            if resp and resp.result ~= nil then
                vim.lsp.util.apply_workspace_edit(resp.result, client.offset_encoding)
            end
        end
    end
end)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked LSP 3.17 workspace/didRenameFiles specification and the nvim-tree event APIs shown for NodeRenamed and WillRenameNode. Trace how active LSP clients and file-operation capabilities are exposed, then verify that rename notifications and pre-rename requests behave correctly, including workspace edits; done means the supported LSP rename operations work by default without breaking file renames.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua, neovim
Domain
devtools, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.