-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
rustdoc: Indicate struct can be created + fn #107926
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @jsha (or someone else) soon. Please see the contribution instructions for more information. |
Didn't mean to send the PR now, It's a draft PR :( |
The job Click to see the possible cause of the failure (guessed by this bot)
|
☔ The latest upstream changes (presumably #108228) made this pull request unmergeable. Please resolve the merge conflicts. |
@mustakimali any updates? |
When typing `MyType::` the completion items' order could be re-ordered based on how likely we want to select those: * Constructors: `new` like functions to be able to create the type, * Builder Methods: any builder methods available, * Constructors that take args: Any other function that creates `Self`, * Regular methods & associated functions (no change there) ![image](https://github.com/rust-lang/rust-analyzer/assets/1546896/54593b91-07b3-455a-8a71-8d203d4eaf4a) In this photo, the order is: * `new` constructor is first * `new_builder` second is a builder method * `aaaanew` is a constructor that takes arguments, is third and is irrespective of its alphabetical order among names. I've dropped my previous idea of highlighting these functions in the rustdoc (rust-lang/rust#107926)
When typing `MyType::` the completion items' order could be re-ordered based on how likely we want to select those: * Constructors: `new` like functions to be able to create the type, * Builder Methods: any builder methods available, * Constructors that take args: Any other function that creates `Self`, * Regular methods & associated functions (no change there) ![image](https://github.com/rust-lang/rust-analyzer/assets/1546896/54593b91-07b3-455a-8a71-8d203d4eaf4a) In this photo, the order is: * `new` constructor is first * `new_builder` second is a builder method * `aaaanew` is a constructor that takes arguments, is third and is irrespective of its alphabetical order among names. I've dropped my previous idea of highlighting these functions in the rustdoc (rust-lang/rust#107926)
feat: completion list suggests constructor like & builder methods first When typing `MyType::` the completion items' order could be re-ordered based on how likely we want to select those: * Constructors: `new` like functions to be able to create the type, * Constructors that take args: Any other function that creates `Self`, * Builder Methods: any builder methods available, * Regular methods & associated functions (no change there) ![image](https://github.com/rust-lang/rust-analyzer/assets/1546896/54593b91-07b3-455a-8a71-8d203d4eaf4a) In this photo, the order is: * `new` constructor is first * `new_builder` second is a builder method * `aaaanew` is a constructor that takes arguments, is third and is irrespective of its alphabetical order among names. --- Another Example using actix `HttpServer` shows preferring constructor without `self` arg first (the `new` method) ![image](https://github.com/rust-lang/rust-analyzer/assets/1546896/938d3fb0-3d7a-4427-ae2f-ec02a834ccbe) ![image](https://github.com/rust-lang/rust-analyzer/assets/1546896/2c13860c-efd1-459d-b25e-df8adb61bbd0) I've dropped my previous idea of highlighting these functions in the rustdoc (rust-lang/rust#107926)
@Dylan-DPC I wasn't sure if highlighting in the doc would be useful. So I quickly lost motivation and implemented something similar in the |
This would be really useful in rustdoc. Having something for this in rust-analyzer is really not a substitute for this. When you are reading the documentation of a type sometimes it is difficult to find out, how one should actually create an instance of that type from the documentation. Having a separate |
Visual hint to indicate the
Struct
that can be created from outside as well as highlight the functions that can be used as well (function that does not takeself
and returns the type,Option
orResult
)Signed-off-by: Mohammad Mustakim Ali mustakimali@users.noreply.github.com