Skip to content

Conversation

@asukaminato0721
Copy link
Contributor

@asukaminato0721 asukaminato0721 commented Dec 20, 2025

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().

fix name
@asukaminato0721 asukaminato0721 marked this pull request as ready for review December 20, 2025 08:48
Copilot AI review requested due to automatic review settings December 20, 2025 08:48
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 20, 2025
Copy link

Copilot AI left a 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_name completes 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
@Veykril Veykril changed the title fix Auto completion should use fully qualified syntax in case of ambiguity #18895 fix: Auto completion should use fully qualified syntax in case of ambiguity #18895 Dec 21, 2025
Copy link
Member

@Veykril Veykril left a 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.

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

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Auto completion should use fully qualified syntax in case of ambiguity

3 participants