Skip to content

Adding lsp rename capability#544

Draft
PMassicotte wants to merge 2 commits intomainfrom
feat/lsp-rename
Draft

Adding lsp rename capability#544
PMassicotte wants to merge 2 commits intomainfrom
feat/lsp-rename

Conversation

@PMassicotte
Copy link
Copy Markdown
Collaborator

This is implementing lsp rename into r_ls.

Here is a quick demo (I am using lspsaga for my rename UI):

Peek 2026-04-06 07-38

@jalvesaq
Copy link
Copy Markdown
Member

jalvesaq commented Apr 7, 2026

Thank you! I know that it's still a draft, and bugs are expected...

I tried to replace info in this code from nvimcom/R/bol.R:

    if (length(res) == 0 || (length(res) == 1 && res == "")) {
        res <- ""
    } else {
        if (is.null(pkg)) {
            info <- pkgname
            if (!is.na(funcmeth)) {
                if (info != "") {
                    info <- paste0(info, ", ")
                }
                info <- paste0(info, "function:", funcmeth, "()")
            }
            # TODO: Add the method name to the completion menu if (info != "")
        }
    }

With the cursor over the first occurrence of info, it asks twice for the new name, and only the second works. It renames the first three occurrences of info, but not the other three. Maybe this is correct... But then, I undid the changes and repeated the renaming procedure. This time, only the first info under the cursor was renamed.

@PMassicotte
Copy link
Copy Markdown
Collaborator Author

Thank you very much for sharing your experience. So here, all 6 instances should be renamed?d

@PMassicotte
Copy link
Copy Markdown
Collaborator Author

I replicated the R code into a lua function to see what lua-lsp would change

image

We see all the 6 instances highlighted.

With the code change I am about to push, we also have the same behaviour

image

Add support for renaming variables and functions across R projects.
Update documentation and configuration to reflect the new feature.
Enhance LSP functionality with a rename method for symbol references.
Refactor the function to better reflect its purpose of checking
if two definitions refer to the same R variable, considering R's
function-level scoping. Update references to this function across
the codebase to ensure consistent behavior.

test(rename): add test for renaming with reassignment in same scope

Add a test case to verify that renaming a symbol within the same
scope correctly updates all occurrences, including reassignments.
This ensures that the refactored function handles R's scoping rules
properly during rename operations.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants