Skip to content

eglot-rename: support textDocument/PrepareRename #1554

Description

@adonovan

The eglot-rename function uses symbol-at-point to find the "old" name of the symbol under the cursor. Though this follows Emacs tradition, it is not the intent of the LSP, which provides an RPC called prepareRename whose job is to ask the server for the name of the symbol under the cursor, or in other words, pop up a server-informed dialog. eglot should use it.

How might the two differ? Consider an import declaration import "example.com/foo/bar". If the server supports package renaming, it might respond with the value example.com/foo/bar, inviting the user to edit the complete package name, potentially changing path segments other than bar in order to affect a directory move to somewhere else in the tree.

As another example: some servers (e.g. gopls) exploit the fact that Rename is currently the only LSP operation that supports any form of dialog, no matter how limited. (This is something we would like to fix, and we are working on LSP support for more general dialog.) In the meantime, it is convenient to use the Rename dialog as a means to this end. For example, with gopls, "renaming" the func token of a function initiates the "permute parameters" refactoring, which allows the user to edit the list of parameter names. The server will then update the function and all calls to it based on the chosen permutation.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions