Skip to content

Fix LSP keyword rename on constructors; FailedParse config source#3033

Open
Louisvranderick wants to merge 4 commits intofacebook:mainfrom
Louisvranderick:fix/lsp-dataclass-keyword-rename
Open

Fix LSP keyword rename on constructors; FailedParse config source#3033
Louisvranderick wants to merge 4 commits intofacebook:mainfrom
Louisvranderick:fix/lsp-dataclass-keyword-rename

Conversation

@Louisvranderick
Copy link
Copy Markdown
Contributor

@Louisvranderick Louisvranderick commented Apr 6, 2026

Summary

Fixes #2496

Renaming a keyword at a call site (e.g. dataclass Foo(a=...)) could resolve the rename symbol to the class instead of the field parameter, so the client offered a rename that produced no edits. When load/parse failed for an on-disk pyrefly.toml, we still labeled the source as File, which misclassified config roots.

The LSP path adds keyword_argument_fallback_to_callee (on for go-to-definition, off for rename and find-refs), refines keyword targets against callee signatures (positional-only params and explicit __init__ on class calls), and returns null from prepare_rename when a keyword argument has no definitions. Config adds ConfigSource::FailedParse and treats it like a real config path for roots, discovery, and messaging.

Test Plan

  • Added/updated LSP unit tests (rename, definition, lsp_interaction prepareRename) and test_failed_parse_on_invalid_toml in pyrefly_config.
  • Ran python3 test.py --no-test --no-conformance --no-jsonschema and targeted cargo test for the new cases locally.

@meta-cla meta-cla bot added the cla signed label Apr 6, 2026
@github-actions github-actions bot added the size/l label Apr 6, 2026
Keyword arguments at call sites could resolve definitions to the callee
when refinement failed, which made prepare_rename advertise a symbol that
produced no edits (e.g. dataclass constructor keywords vs the class name).
Add optional callee fallback for go-to-definition only, refine constructor
keywords against __init__ and positional-only parameters, and return null from
prepare_rename when a keyword argument has no definitions.

Invalid pyrefly.toml on disk was classified as File after parse failure, which
broke discovery that distinguishes real config paths. Introduce
ConfigSource::FailedParse, treat it like File for roots and messaging, and
record the path when read_path fails.

Tests cover dataclass rename, FailedParse config, and definition on pos-only
params for invalid keyword calls.

Made-with: Cursor
Scrut config.md tests expected the old WARN line for invalid pyrefly.toml;
project mode now logs INFO like a normal config path. Remove duplicate
FailedParse patterns in dump-config, loader, and LSP so clippy stays clean
and semantics stay consistent (failed parse uses file-style paths, not
marker-style messaging).

Made-with: Cursor
@github-actions github-actions bot added size/l and removed size/l labels Apr 6, 2026
test_enum_class_value (issue facebook#1982) expected f(E.X) to match Literal[E.X] after literal member typing. Reverting that feature restores the general E branch; update the assertion accordingly.

Made-with: Cursor
@github-actions github-actions bot added size/xl and removed size/l labels Apr 6, 2026
@Arths17
Copy link
Copy Markdown
Contributor

Arths17 commented Apr 7, 2026

Hey @Louisvranderick, thanks for the hard work on this #2496 fix. I see you’re actively pushing commits and working through the logic as we speak, so I’ll stay tuned while the CI settles!

Just as a heads-up: I’m not a maintainer or official contributor yet just a developer following the project closely and looking to provide some extra eyes on the LSP side of things.

I did notice the recent revert on the enum literal member types; it’ll be interesting to see how that interacts with the new keyword_argument_fallback_to_callee flow. If that change was to avoid a regression elsewhere, I'm happy to help verify it against some complex TypedDict or Enum edge cases once the branch is stable.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Renaming dataclass property renames class name instead

2 participants