-
Notifications
You must be signed in to change notification settings - Fork 1.9k
fix: Auto completion should use fully qualified syntax in case of ambiguity #18895 #21306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
1fbac0e to
0456716
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes auto-completion for trait methods accessed via type paths (e.g., Dog::). When a trait method is completed through a type qualifier, the completion now automatically rewrites it to use Universal Function Call Syntax (UFCS) in the form <Type as Trait>::method() to resolve ambiguity.
Key changes:
- Added UFCS detection and rewriting logic for trait method completions
- Extended call parentheses insertion to support qualified syntax with customizable replacement ranges
- Added regression test ensuring
Dog::baby_namecompletes to<Dog as Animal>::baby_name()
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| crates/ide-completion/src/tests/expression.rs | Added regression test for UFCS syntax in trait method completion |
| crates/ide-completion/src/render/function.rs | Implemented UFCS detection, rewriting logic, and helper utilities for qualified trait method completion |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Update crates/ide-completion/src/render/function.rs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> clippy
ea4b0af to
a4d805a
Compare
Veykril
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't fully qualify calls unless its necessary as outlined in the issue. The implementation here just always qualifies it which isn't quite what we want.
fix #18895
Updated the completion renderer to detect when a trait method is being completed via a type path and rewrite the edit to the UFCS form (
<Ty as Trait>::method) before emitting the completion item, including the new UfcsData/CallSnippetRewrite plumbing and trait-container detection in render_fn so both plain inserts and call-paren snippets respect the wider replacement range.Extended add_call_parens to accept the optional rewrite data, build snippets using the qualified call head, and emit a TextEdit that spans the entire qualifier when necessary.
Added helper utilities to compute the qualifier text/range, render the trait path, and decide when UFCS rewriting is appropriate so the logic stays isolated and testable.
Added a regression test that exercises completing Dog:: when only a trait implementation exists to ensure the completion now expands to
<Dog as Animal>::baby_name().