Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

mustakimali
Copy link
Contributor

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 take self and returns the type, Option or Result)

Signed-off-by: Mohammad Mustakim Ali mustakimali@users.noreply.github.com

Signed-off-by: Mohammad Mustakim Ali <mustakimali@users.noreply.github.com>
@rustbot
Copy link
Collaborator

rustbot commented Feb 11, 2023

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.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Feb 11, 2023
@mustakimali
Copy link
Contributor Author

Didn't mean to send the PR now, It's a draft PR :(

@Noratrieb Noratrieb added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 11, 2023
@rust-log-analyzer
Copy link
Collaborator

The job mingw-check failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
    Checking rustdoc v0.0.0 (/checkout/src/librustdoc)
error[E0308]: mismatched types
    --> src/librustdoc/clean/types.rs:1338:9
     |
1337 |     pub(crate) fn type_builder(&self) -> bool {
     |                                          ---- expected `bool` because of return type
1338 |         self.inputs.values.get(0).and_then(|v| v.to_self())
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found enum `Option`
     = note: expected type `bool`
     = note: expected type `bool`
                found enum `std::option::Option<clean::types::SelfTy>`
help: use `Option::is_some` to test if the `Option` has a value
     |
1338 |         self.inputs.values.get(0).and_then(|v| v.to_self()).is_some()

For more information about this error, try `rustc --explain E0308`.
error: could not compile `rustdoc` due to previous error
Build completed unsuccessfully in 0:01:51

@bors
Copy link
Contributor

bors commented Feb 19, 2023

☔ The latest upstream changes (presumably #108228) made this pull request unmergeable. Please resolve the merge conflicts.

@Dylan-DPC
Copy link
Member

@mustakimali any updates?

@mustakimali mustakimali closed this Sep 1, 2023
@mustakimali mustakimali deleted the builder-indicator branch September 1, 2023 19:29
@Dylan-DPC Dylan-DPC added S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 2, 2023
mustakimali added a commit to mustakimali/rust-analyzer that referenced this pull request Dec 13, 2023
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)
mustakimali added a commit to mustakimali/rust-analyzer that referenced this pull request Jan 15, 2024
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)
bors added a commit to rust-lang/rust-analyzer that referenced this pull request Feb 13, 2024
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)
@mustakimali
Copy link
Contributor Author

mustakimali commented Feb 17, 2024

@mustakimali any updates?

@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 rust-analyzer instead.

rust-lang/rust-analyzer#16117

@05storm26
Copy link

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 Constructors section for each type, would be useful to navigate the documentation and understand how a type should be created (by calling what method/function) in unknown/unfamiliar crates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants