Skip to content

Conversation

@asukaminato0721
Copy link
Contributor

@asukaminato0721 asukaminato0721 commented Dec 19, 2025

fix #11137

Docs now tracks file origins per line (with optional HirFileId) and an indent-trimming flag so we can map included Markdown back to its source file without mangling formatting.

Added logic in doc extraction to detect include_str! attributes, resolve the referenced file via AnchoredPath, read its contents, and append it to the aggregated docs while skipping indent stripping.

Updated helpers, tests, and data structures accordingly (including a new unit test ensuring include text preserves indentation).
Added a hover regression test proving that include_str! docs show up in IDE output.

image

@asukaminato0721 asukaminato0721 marked this pull request as ready for review December 19, 2025 18:55
Copilot AI review requested due to automatic review settings December 19, 2025 18:55
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 19, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds support for #[doc = include_str!(...)] attributes in hover documentation. Previously, rust-analyzer would silently ignore these attributes when displaying hover information; now it resolves the referenced file, reads its contents, and includes it in the documentation output while preserving the original formatting.

Key changes:

  • Extended DocsSourceMapLine to track file origins and indent-trimming preferences per line
  • Added logic to detect and process include_str! macro calls in doc attributes
  • Updated the VFS to watch Markdown files so they can be resolved and their changes tracked

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
crates/load-cargo/src/lib.rs Adds "md" extension to watched file types so Markdown files used in include_str! are tracked by the VFS
crates/ide/src/hover/tests.rs Adds regression test verifying that include_str! documentation appears in hover output
crates/hir-def/src/attrs.rs Core implementation: adds file origin tracking, extend_with_doc_include method, preserves indentation for included files, updates all call sites and tests to accommodate new structure fields

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

Support #[doc = include_str!(...)] in hover documentation

2 participants