Skip to content

feat: rename references in intra-doc links - #23030

Open
so1ve wants to merge 1 commit into
rust-lang:masterfrom
so1ve:fix/12583
Open

feat: rename references in intra-doc links#23030
so1ve wants to merge 1 commit into
rust-lang:masterfrom
so1ve:fix/12583

Conversation

@so1ve

@so1ve so1ve commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

resolve #12583

One point worth noting is that I deliberately added an include_intra_doc_links option to control whether intra-doc links are included in usage search results. For now, I have enabled it only for rename, because I suspect that including documentation links in other features, such as Find References, could make their results too noisy. I have also deliberately left renaming links inside macros unsupported for now.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 4, 2026
@rustbot

rustbot commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@ChayimFriedman2 ChayimFriedman2 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This all seems exceedingly complicated way more than it needs to be.

All you need to do is to check for doc comments insideFindUsages::search() in the search loop, similar to what we do for goto def.

View changes since this review

.unwrap_or(s)
}

/// Extracts all intra-doc link occurrences from Markdown documentation.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// Extracts all intra-doc link occurrences from Markdown documentation.
/// Extracts all links from a given markdown text returning the definition text range, link-text
/// and the namespace if known.

You removed this and this is useful.

}

fn broken_link_clone_cb(link: BrokenLink<'_>) -> Option<(CowStr<'_>, CowStr<'_>)> {
Some((link.reference.clone(), link.reference))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Duplicated with doc_links.rs, you also removed the comment.

Comment on lines +14 to +15
const MARKDOWN_OPTIONS: Options =
Options::ENABLE_FOOTNOTES.union(Options::ENABLE_TABLES).union(Options::ENABLE_TASKLISTS);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also duplicated with doc_links.rs.

@so1ve

so1ve commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

Hmm. I made some changes locally but I have a question: should I inlcude intra docs in other usages like go to references?

@ChayimFriedman2

Copy link
Copy Markdown
Contributor

I think we should start with not. It's reasonable to do, but we'll want a config for it anyway, so not for this PR.

@so1ve

so1ve commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

The current implementation is indeed fairly complicated 🤔 However I noticed one issue: FindUsages has a fast path for short inherent associated unctions such as new and from

After the refactoring, in order to handle intra-doc links in the normal search loop, rename needs to bypass this fast path when intra-doc link search is enabled. Is that performance trade-off acceptable for this PR or should the fast path also be adapted to handle intra-doc links during rename?

@ChayimFriedman2

Copy link
Copy Markdown
Contributor

You don't need to disable this, you just need to also search doc comments (and string literals in #[doc = "..."]) in addition. Since text searching and parsing are very fast and not the bottleneck, this will not make the fast path slower.

@ChayimFriedman2

Copy link
Copy Markdown
Contributor

Actually, you don't even need an addition search - the existing short associated function path could find doclinks (textually) just as well.

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.

Update comments that reference refactored symbols

3 participants