Skip to content

Rename parameters across files in keyword arguments#3290

Closed
asukaminato0721 wants to merge 1 commit into
facebook:mainfrom
asukaminato0721:2207-rename-across
Closed

Rename parameters across files in keyword arguments#3290
asukaminato0721 wants to merge 1 commit into
facebook:mainfrom
asukaminato0721:2207-rename-across

Conversation

@asukaminato0721

@asukaminato0721 asukaminato0721 commented May 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Part of #2207.

This PR fixes parameter rename across files when the external use is a keyword argument. For example, renaming param in:

# fileA.py
def test(param):
    return param

now also updates the caller-side keyword in another file:

# fileB.py
from fileA import test

result = test(param="hello")

The implementation adds keyword-argument references to the external reverse-dependency reference path. It does not rename keyword textually: each matching param= candidate resolves its callee, refines that callee back to the actual parameter definition, and only edits the keyword when the refined parameter range matches the parameter being renamed.

Relationship to branch 1583

Branch 1583 overlaps with this PR. It targets the same cross-file parameter-keyword rename behavior and adds a similar LSP regression fixture. It is broader than this PR because it also carries fallback logic around external-definition range/line matching.

This PR is the narrower version: it only wires parameter keyword-argument references into the existing external reverse-dependency lookup. If 1583 lands first, this branch should be rebased or dropped rather than landed independently with duplicate coverage.

Test Plan

cargo test rename::test_rename

python3 test.py --no-test --no-conformance --no-jsonschema

@meta-cla meta-cla Bot added the cla signed label May 2, 2026
@github-actions github-actions Bot added the size/m label May 2, 2026
@github-actions

github-actions Bot commented May 2, 2026

Copy link
Copy Markdown

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@asukaminato0721 asukaminato0721 marked this pull request as ready for review May 2, 2026 01:38
Copilot AI review requested due to automatic review settings May 2, 2026 01:38

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds cross-file rename support for function parameters by ensuring keyword argument usages in other files are treated as references, and introduces a regression test covering this behavior (part of IDE feature tracker #2207).

Changes:

  • Extend reference collection for externally-defined parameter symbols to include matching keyword-argument sites in other modules.
  • Refactor keyword-argument reference matching to rely on existing find_definition_for_keyword_argument results.
  • Add a new LSP interaction test fixture + test verifying parameter rename updates keyword arguments across files without touching unrelated calls.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pyrefly/lib/state/lsp.rs Include keyword-argument references when the parameter definition lives in a different module; refactor keyword-arg resolution plumbing.
pyrefly/lib/test/lsp/lsp_interaction/rename.rs Add regression test for cross-file parameter rename updating keyword arguments.
pyrefly/lib/test/lsp/lsp_interaction/test_files/rename_parameter_keywords_across_files/pyrefly.toml Configure test workspace search path for cross-file import resolution.
pyrefly/lib/test/lsp/lsp_interaction/test_files/rename_parameter_keywords_across_files/fileA.py Defines the target function/parameter for rename.
pyrefly/lib/test/lsp/lsp_interaction/test_files/rename_parameter_keywords_across_files/fileB.py Contains both a relevant keyword-arg call and an unrelated one to validate disambiguation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pyrefly/lib/state/lsp.rs
Comment on lines 3284 to 3288
&self,
handle: &Handle,
definition_range: TextRange,
definition_module: &Module,
expected_name: &Name,
Comment thread pyrefly/lib/state/lsp.rs
definition_range: TextRange,
definition_module: &Module,
expected_name: &Name,
) -> Option<Vec<TextRange>> {
@kinto0

kinto0 commented May 11, 2026

Copy link
Copy Markdown
Contributor

I think this is #1583 and I think you already have a PR open for this? #2484

@asukaminato0721

Copy link
Copy Markdown
Contributor Author

oh, this also handle the name in like comments, strings.

@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had recent activity for more than 2 weeks.

If you are still working on this this pull request, please add a comment or push new commits to keep it active. Otherwise, please unassign yourself and allow someone else to take over.

Thank you for your contributions!

@kinto0

kinto0 commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

oops - missed this. would you mind making the issue title / summary more clear as to why these are both necessary and if they don't overlap?

@github-actions github-actions Bot added size/m and removed size/m labels Jun 26, 2026
@asukaminato0721 asukaminato0721 changed the title fix rename across file #2207 Jun 26, 2026
@github-actions github-actions Bot removed the stale label Jun 27, 2026
@kinto0

kinto0 commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

so it looks like this branch will be rebased / dropped? can you combine these PRs or decide which one you want us to review?

@asukaminato0721

Copy link
Copy Markdown
Contributor Author

suppressed by #2484

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

4 participants