Skip to content

workspace/willRenameFiles - destination file must exist before #2522

@przepompownia

Description

@przepompownia

I don't know how many LSP clients can send workspace/willRenameFiles request and handle the response. Neovim comes with no handler and I didn't find any plugin for it.

On the other side I can send such request and would see the response if it worked. In

$document = $this->locator->get($file);

I get TextDocumentNotFound because the new file doesn't exist yet. Is it intentional?

I check it with

local function willRenameCurrentBuffer(newPath)
  if not vim.startswith(newPath, '/') then
    newPath = vim.fs.joinpath(vim.uv.cwd(), newPath) -- replace vim.uv with vim.loop on <=0.9
  end
  local response = vim.lsp.buf_request_sync(0, 'workspace/willRenameFiles', {files = {{
    oldUri = vim.uri_from_bufnr(0), -- the current file
    newUri = vim.uri_from_fname(newPath)
  }}})

  vim.print(response)
end

vim.api.nvim_create_user_command('WillRenameCurrentBuffer', function (opts)
  willRenameCurrentBuffer(opts.args)
end, {nargs = 1, complete = 'file'})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions