Skip to content

Implement find references and rename for locals #3111

Open

Description

@yedhink

Description

Ruby LSP Information

VS Code Version

1.97.0-insider

Ruby LSP Extension Version

0.8.19

Ruby LSP Server Version

0.23.7

Ruby LSP Add-ons

  • Ruby LSP Rails
  • RuboCop

Ruby Version

3.4.1

Ruby Version Manager

rbenv

Installed Extensions

Click to expand
  • catppuccin-vsc (3.16.0)
  • dotenv (1.0.1)
  • prettier-vscode (11.0.0)
  • ruby-extensions-pack (0.1.12)
  • ruby-lsp (0.8.19)
  • sorbet-vscode-extension (0.3.37)
  • vim (1.29.0)
  • vscode-eslint (3.0.10)
  • vscode-mdx (1.8.13)
  • vscode-ruby (0.28.0)

Ruby LSP Settings

Click to expand
Workspace
{}
User
{
  "enabledFeatures": {
    "codeActions": true,
    "diagnostics": true,
    "documentHighlights": true,
    "documentLink": true,
    "documentSymbols": true,
    "foldingRanges": true,
    "formatting": true,
    "hover": true,
    "inlayHint": true,
    "onTypeFormatting": true,
    "selectionRanges": true,
    "semanticHighlighting": true,
    "completion": true,
    "codeLens": true,
    "definition": true,
    "workspaceSymbol": true,
    "signatureHelp": true,
    "typeHierarchy": true
  },
  "featuresConfiguration": {},
  "addonSettings": {},
  "rubyVersionManager": {
    "identifier": "auto"
  },
  "customRubyCommand": "",
  "formatter": "auto",
  "linters": null,
  "bundleGemfile": "",
  "testTimeout": 30,
  "branch": "",
  "pullDiagnosticsOn": "both",
  "useBundlerCompose": false,
  "bypassTypechecker": false,
  "rubyExecutablePath": "",
  "indexing": {},
  "erbSupport": true,
  "featureFlags": {}
}

Reproduction steps

Image

Add the following test case in Rails 8 and try to rename the variable password:

  def test_password_is_not_too_short
    password = "w" * (User::MIN_PASSWORD_LENGTH - 1)
    @user.password = password

    @user.password_confirmation = password
  end

Getting the error message The element can't be renamed.

Neovim

Same issue in neovim. But message is different though:

Image
ruby-lsp --version: 0.23.6

Question

I am not sure if this is a bug. Maybe this is a limitation of Ruby-lsp. Please close the issue if this issue is scoped to be fixed as part of the roadmap or if it cannot be fixed.

Activity

  1. added
    bugSomething isn't working
    vscodeThis pull request should be included in the VS Code extension's release notes
    on Jan 30, 2025
  2. vinistock commented on Jan 30, 2025

    @vinistock
    Member

    Thank you for the report. This is not a bug, we just haven't implemented reference tracking for locals yet. I'll change the title and labels to make that clearer, since we don't have an issue for this created yet.

  3. added
    enhancementNew feature or request
    pinnedThis issue or pull request is pinned and won't be marked as stale
    serverThis pull request should be included in the server gem's release notes
    and removed
    bugSomething isn't working
    vscodeThis pull request should be included in the VS Code extension's release notes
    on Jan 30, 2025
  4. changed the title [-]Getting `The element can't be renamed` message when trying to rename a variable in both VSCode as well as Neovim[/-] [+]Implement find references and rename for locals[/+] on Jan 30, 2025
  5. andyw8 commented on Jan 30, 2025

    @andyw8
    Contributor

    We can also update the docs: #3113

  6. qertoip commented on Apr 14, 2025

    @qertoip

    Coming from JetBrains IDEs this feature not present feels like I lost my left hand ;-)

    I am renaming my locals and methods all day long.

    Would love to see this added!

  7. percygrunwald commented on Jan 6, 2026

    @percygrunwald

    Presuming that this would also allow Go to Definition to work for locals as well. At the moment, attempting to go to a definition of a variable shows No definition found for '...':

    Image

    For comparison, with the Pylance extension the editor exhibits the expected behavior of jumping to the variable definition:

    Image

    If not, I'm happy to create a separate issue for this expected behavior. Thanks!

  8. Mohith26 commented on Nov 4, 2026

    @Mohith26

    I'd like to take this one. Plan, since it touches a few requests:

    • A small Prism visitor (Requests::Support::LocalVariableFinder) that groups every local occurrence by its declaring scope using the depth Prism already stores on local variable nodes. Def/class/module/singleton class are hard boundaries, blocks and lambdas see their parents. It covers parameters of all kinds, block locals, multi-assign/for/rescue targets, pattern matching, regexp named captures and { name: } shorthands.
    • References, rename and prepare rename use it when the cursor is on a local and only look at the current document. Definition jumps to the parameter or first assignment (skipped in typed: true files, where Sorbet already handles it).
    • Rename validates the new name with Prism, refuses names already used by another local or a bare method call in a visible scope, keeps the key for shorthands ({ name: } becomes { name: new_name }), and refuses keyword parameters since callers pass them by name.

    It doesn't depend on the index, so it should carry over to the Rubydex branch with only the small hooks in each request changing. Happy to adjust if you'd rather scope it differently.

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

    enhancementNew feature or requesthelp-wantedExtra attention is neededpinnedThis issue or pull request is pinned and won't be marked as staleserverThis pull request should be included in the server gem's release notes

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions