Skip to content

LSP rename: missing RenameFile operation in documentChanges #1366

@przepompownia

Description

@przepompownia

Currently when I try to rename some class form LSP client I have to rename its file manually. For a simple class with no references the server sends to the client WorkspaceEdit with a single TextDocumentEdit (as I guess from its format) inside documentChanges. It's enough to change the file content by some client's response handler. The original name remains untouched.

After dumping such example edit in Lua format

{ -- WorkspaceEdit
  documentChanges = {
  { -- TextDocumentEdit
      edits = {
      {
          newText = "Arctgx\\PhpactorTestEnv",
          range = {
            ['end'] = {
              character = 32,
              line = 2
            },
            start = {
              character = 10,
              line = 2
            }
          }
        },
      {
          newText = "V",
          range = {
            ['end'] = {
              character = 7,
              line = 4
            },
            start = {
              character = 6,
              line = 4
            }
          }
        }
      },
      textDocument = {
        uri = "file:///home/arctgx/dev/arctgx/phpactor-test-env/src/Z.php",
        version = 7
      }
    },
  },
}

and adding RenameFile and applying such simulated response on the client side

local out = { -- WorkspaceEdit
  documentChanges = {
    { -- RenameFile
        kind = 'rename',
        oldUri = "file:///home/arctgx/dev/arctgx/phpactor-test-env/src/Z.php",
        newUri = "file:///home/arctgx/dev/arctgx/phpactor-test-env/src/V.php",
      },
  { -- TextDocumentEdit
      edits = {
      {
          newText = "Arctgx\\PhpactorTestEnv",
          range = {
            ['end'] = {
              character = 32,
              line = 2
            },
            start = {
              character = 10,
              line = 2
            }
          }
        },
      {
          newText = "V",
          range = {
            ['end'] = {
              character = 7,
              line = 4
            },
            start = {
              character = 6,
              line = 4
            }
          }
        }
      },
      textDocument = {
        uri = "file:///home/arctgx/dev/arctgx/phpactor-test-env/src/V.php",
        version = 7
      }
    },
  },
}
vim.lsp.util.apply_workspace_edit(out, vim.lsp.get_client_by_id(1).offset_encoding)

I get the expected change. It suggests that RenameFile should be added to documentChanges.

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