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

Provide doc links at item definitions on source pages #89157

Closed

Conversation

GuillaumeGomez
Copy link
Member

@GuillaumeGomez GuillaumeGomez commented Sep 21, 2021

Part of #89095.

You can test it here.

We now generate links to an item documentation on its definition.

cc @rust-lang/rustdoc

@GuillaumeGomez GuillaumeGomez added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. A-rustdoc-ui Area: Rustdoc UI (generated HTML) A-rustdoc-js Area: Rustdoc's JS front-end labels Sep 21, 2021
@rust-highfive
Copy link
Collaborator

Some changes occurred in HTML/CSS/JS.

cc @GuillaumeGomez

@rust-highfive
Copy link
Collaborator

r? @ollie27

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 21, 2021
@jsha
Copy link
Contributor

jsha commented Sep 22, 2021 via email

@Manishearth
Copy link
Member

I really like @jsha's suggestion here! Having a context menu each time does seem awkward

@GuillaumeGomez
Copy link
Member Author

I don't understand what you're suggesting @jsha... Simpler: what would it look like?

If you click on a link to a definition, and want the doc view, it would be
two clicks, same as this popup solution. If you only wanted the source
view, it would be just one click.

The popup appears on hover too, so one click. But I remain very curious about what you're suggesting!

@camelid
Copy link
Member

camelid commented Sep 22, 2021

I believe jsha is suggesting that the source view would look something like this (where [docs] is a link to my_fn's docs page):

[docs]  1  fn my_fn() {
        2      println!("Hello, world!");
        3  }

It's an interesting idea, although I'm not sure how we'd fit it into the margin. Could you elaborate @jsha?

The popup appears on hover too, so one click. But I remain very curious about what you're suggesting!

IIUC, you have to click once to get the popup, and then click again to actually go to the destination, so it's two clicks.

@jsha
Copy link
Contributor

jsha commented Sep 22, 2021 via email

@GuillaumeGomez
Copy link
Member Author

What happens in case you multiple items on one line like:

fn foo(a: Foo, b: Bar, c: String) {

?

In this case we have three different items, so that might make it a bit weird/dense, no?

Or, we could put [docs] in the right margin, by analogy with [src] in the
doc view. We may also want to consider using an icon for both src and doc
links.

I don't think using the right margin in the source code viewer is a good idea because the width depends on the content currently.

@camelid
Copy link
Member

camelid commented Sep 22, 2021

What happens in case you multiple items on one line like:

fn foo(a: Foo, b: Bar, c: String) {

?

In this case we have three different items, so that might make it a bit weird/dense, no?

There's only one item, foo, so there would only be one link. If you clicked on Bar, you would be taken to Bar's definition in the source code, which would have its own [docs] link.

@camelid
Copy link
Member

camelid commented Sep 22, 2021

Or, we could put [docs] in the right margin, by analogy with [src] in the
doc view. We may also want to consider using an icon for both src and doc
links.

I don't think using the right margin in the source code viewer is a good idea because the width depends on the content currently.

I agree; it seems like it could make the UI confusing. The ... icon idea sounds interesting though.

@jsha
Copy link
Contributor

jsha commented Sep 22, 2021 via email

@camelid
Copy link
Member

camelid commented Sep 22, 2021

Yep, exactly. There is a possibility case of multiple items on one line, like:

struct Foo; struct Bar;

But that's unusual, and rustfmt would break it up anyhow. If we encounter such a case we should link to docs for the first one.

Hmm, that does seem likely uncommon, but maybe we could change the UI to avoid it altogether? E.g., we could have clicking on the Foo in struct Foo; give the same popup that the ... would. Although that might not be as clean and simple as it could be...

@camsteffen
Copy link
Contributor

I think I'd remove the code link highlighting.

Could you stylize the popup like this for consistency with the existing [src] feature?

[docs] [src]

@camelid
Copy link
Member

camelid commented Sep 22, 2021

I think I'd remove the code link highlighting.

Could you stylize the popup like this for consistency with the existing [src] feature?

[docs] [src]

Yeah, I was just using [docs] as a rough Markdown approximation :)

@GuillaumeGomez
Copy link
Member Author

GuillaumeGomez commented Sep 22, 2021

I definitely don't agree with your proposal @jsha, I find it very counter-intuitive. Currently in one click we have access to both documentation and source. What you suggest would be a "flow break" considering you'd have to switch between documentation and source page all the time, which would really be not great...

EDIT: And to comment on @camelid's explanations:

There's only one item, foo, so there would only be one link. If you clicked on Bar, you would be taken to Bar's definition in the source code, which would have its own [docs] link.

Then it's two clicks, and really not intuitive (why would I need to go to an item definition to get its documentation link?).

Could you stylize the popup like this for consistency with the existing [src] feature?

[docs] [src]

I like this suggestion! It'll make the popup smaller too.

I think I'd remove the code link highlighting.

It's part of the things that aren't set in stone for the moment. You can see some reflexion about it here.

@camelid @jsha: I'd really like if possible to keep the possibility to have access to both [docs] and [src] wherever we are looking in the documentation. Also, even if unlikely to have multiple declarations on a same line, it's still a possibility and I'd rather not expect all projects to use rustfmt (even if they should!).

@Manishearth
Copy link
Member

Stepping back a bit I think it's important to settle on the purpose of jump-to-def, because what I see here are conflicting purposes. Adding a context menu for every JTD click is also two actions (hover, then click) for an operation many here would want to be immediate. We need to figure out what problems we are solving, how we expect people to use this feature, and then use that to figure out which operations should and shouldn't be convenient.

In general we've had a lack of clarity on this part of this feature for a while and I suspect this will keep cropping up unless we do that work first.

@GuillaumeGomez
Copy link
Member Author

This is a good point. I like the idea to have access to both the documentation and the source from every item, but it slows down the browsing so I understand how that can be an issue. The other solution however (to put the documentation link on the definition) doesn't convince me in its current form. Oh well, we're not in a hurry so we can debate over this and try to reach the best solution for everyone.

@camsteffen
Copy link
Contributor

I suppose that, while browsing the docs, you're most likely going to see more docs next, and when browsing source, you're most likely going to navigate to more source next. So then, maybe a single click in source should navigate to the source, and the popup can just have docs (or both?). And probably add a small delay to the hover if not there already.

@jyn514
Copy link
Member

jyn514 commented Sep 23, 2021

Please do not make the target of the link timing sensitive. That a) is super frustrating when you mean to go to one place and instead go to another; b) makes it impossible to use the longer version on mobile; and c) makes it much more difficult for people with slow reaction times to use the faster link.

In fact I'm again any version of this that relies on hover for navigation because it will be completely broken on mobile.

@GuillaumeGomez
Copy link
Member Author

GuillaumeGomez commented Sep 23, 2021

Please do not make the target of the link timing sensitive.

@camsteffen: I agree with @jyn514: that sounds like a very bad idea.

In fact I'm again any version of this that relies on hover for navigation because it will be completely broken on mobile.

No, currently when you click or hover the link, it makes the popup appear (I thought about mobile devices as well ;) ). It's in the "What it does" explanation in the first comment. I did it this way because if JS is enabled, then we can make the popup appear, otherwise it'll simply click on the ink and go to the item's definition.

@camsteffen
Copy link
Contributor

camsteffen commented Sep 23, 2021

Please do not make the target of the link timing sensitive.

I don't see how that applies. The popup shows above the link. So a direct click is always to source regardless of whether the popup shows. There should be a very small delay (like .3 secs) so that when you drag your mouse across the screen there is not a firework show of popups. On mobile, a click can just open the popup.

@jsha
Copy link
Contributor

jsha commented Sep 24, 2021 via email

@GuillaumeGomez
Copy link
Member Author

No, I completely agree. I'm just not sure that it'll be obvious to people that to go to the item's docs, you need to go to its definition (even though I'm not a big fan, but I can live with it). My biggest issue is the UI suggested with [doc] in the right/left margin. The biggest issue with that is in case we have multiple definitions on a same line ; even though it's rare and unlikely, if there is a chance then it'll happen (declarations in macro for example?).

@JohnCSimon JohnCSimon removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 19, 2021
@JohnCSimon
Copy link
Member

Triage:
@GuillaumeGomez This PR has merge conflicts

@GuillaumeGomez GuillaumeGomez force-pushed the jump-to-def-extension branch from e76daa4 to dcc6221 Compare March 6, 2022 21:39
@rust-log-analyzer

This comment has been minimized.

@GuillaumeGomez GuillaumeGomez force-pushed the jump-to-def-extension branch from dcc6221 to 1553866 Compare March 6, 2022 22:22
@rust-log-analyzer

This comment has been minimized.

@GuillaumeGomez GuillaumeGomez force-pushed the jump-to-def-extension branch 3 times, most recently from ec67d7c to 0939431 Compare March 8, 2022 14:38
@GuillaumeGomez
Copy link
Member Author

Updated (and fixed the GUI tests).

@JohnCSimon JohnCSimon added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 11, 2022
@bors
Copy link
Contributor

bors commented Apr 30, 2022

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

@GuillaumeGomez
Copy link
Member Author

I'll fix the conflict once #96636 is merged.

@Dylan-DPC Dylan-DPC 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 Jun 2, 2022
@ojeda
Copy link
Contributor

ojeda commented Jun 8, 2022

Cross referencers like Elixir (see GuillaumeGomez/rfcs#1 (comment)) support references (i.e. uses) of an identifier (similar to "Search All References" in IDEs). Since we are discussing a link back to the doc view and how that would fit in the UI, mobile, etc., I thought it would be interesting to mention that other links may be useful in the future too.

For instance, if rustdoc gained at some point the ability to list references for an item like Elixir (e.g. https://elixir.bootlin.com/linux/latest/A/ident/list_head), then it would be nice to have a 2nd option in the doc view alongside the [source] link (e.g. a [references] link) and maybe a way to go to that directly from the source view too. They could also appear in the search results in a 4th tab too.

On the UI topic, I think having a contextual menu for desktop/laptop users for extra links on a given source view link (e.g. [references]) would still be nice -- functionality should still be available to mobile somehow (even if less ergonomic or requiring more steps), but as a desktop/laptop user I would nevertheless enjoy having the right-click menu for faster access and easier discovery of extra features.

@GuillaumeGomez GuillaumeGomez force-pushed the jump-to-def-extension branch from 0939431 to 1fa953e Compare June 17, 2022 15:06
@GuillaumeGomez
Copy link
Member Author

Finally took the time to fixed the merge conflicts.

@bors
Copy link
Contributor

bors commented Jun 24, 2022

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

@JohnCSimon
Copy link
Member

Ping from triage:
@GuillaumeGomez what is the status of this PR? Is it ready for review after the merge conflicts are resolved?

FYI: when a PR is ready for review, send a message containing
@rustbot ready to switch to S-waiting-on-review so the PR is in the reviewer's backlog.

@GuillaumeGomez
Copy link
Member Author

We first need to finish the RFC so closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustdoc-js Area: Rustdoc's JS front-end A-rustdoc-ui Area: Rustdoc UI (generated HTML) S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.