Skip to content

rustdoc edit links #2985

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions text/0000-doc-edit-links.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
- Feature Name: `doc_edit_links`
- Start Date: 2020-09-10
- RFC PR: [rust-lang/rfcs#0000](https://github.com/rust-lang/rfcs/pull/0000)
- Rust Issue: [rust-lang/rust#0000](https://github.com/rust-lang/rust/issues/0000)

# Summary
[summary]: #summary
Add an Edit icon next to rustdoc items to link to a relevant online editor.


# Motivation
[motivation]: #motivation

This is the `rustdoc` part of https://github.com/rust-lang/docs.rs/issues/1007.

Currently, rustdoc provides a `[src]` button,
which only links to the corresponding source render from rustdoc.
In case readers of a documentation would like to provide a quick fix
on either the code or a typo in the documentation,
it is necessary to:

1. Find the repository on GitHub (already provided by docs.rs header),
2. Identify the subdirectory in repository for the crate (in case the repository is complex)
3. Identify the corresponding file (by peeking the address in `[src]`)
4. Identify the corresponding line (sometimes same as `[src]`, sometimes moved)
5. Click the `E` hotkey on GitHub, or corresponding hotkey in other git tree browsers

This complexity increases barrier to contribute quick fixes.
This RFC adds the capability to generate links based on source file and line,
which can allow crates.io/docs.rs to elide steps 2, 3, 5 and sometimes 4 as well.

# Guide-level explanation
[guide-level-explanation]: #guide-level-explanation

`rustdoc` accepts an option `--edit-link-format` with value in a `std::fmt`-alike syntax.
If this option is passed, next to each `[src]` button,
a pen icon (alt text "Edit") with a hyperlink to the edit link is inserted.
The value of option is replaced with the following rules:

- `{file}` with the `src` path relative to the crate (using forward slashes even on Windows)
- `{start_line}` with the *starting* line number of the linked source
- `{end_line}` with the *ending* (inclusive) line of the linked source

For example, `libstd` would be documented with the following arguments:

```
--edit-link-format "https://github.com/rust-lang/rust/edit/master/libstd/{file}#L{start_line}-L{end_line}"
```

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing a reference-level explanation. Consider addressing what the UI would look like for this.

# Drawbacks
[drawbacks]: #drawbacks

This increases complexity of the documentation page, especially with mobile devices.
Good UX design is required to prevent bloating the content.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should really be part of the RFC, not deferred until later. Certainly no one on the rustdoc team has the bandwidth to design it.


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This RFC will only show the links on new docs.rs pages, not existing builds. Can you add that as a drawback?

# Alternatives
[alternatives]: #alternatives

It is also possible to perform this with JavaScript on behalf of docs.rs only.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wouldn't have to be with JavaScript, docs.rs already rewrites pages on the backend: https://github.com/rust-lang/docs.rs/blob/master/src/utils/html.rs


Pros:

- *May* support previous crate builds
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to expand on why this is 'May'. The difficulty I forsee is changes in HTML page structure, but since the links always say '[src]' that could be mitigated somewhat. It highly depends where the buttons end up going, which is one more reason I think the design should be part of the RFC.


Cons:

- Does not support self-hosted non-docs.rs builds
- `rustdoc` output is unstable and may not be forward-compatible

# Future possibilities
[future-possibilities]: #future-possibilities

docs.rs could use the new flags in all new generated documentation.