1 //! Extracts, resolves and rewrites links and intra-doc links in markdown documentation.
5 use std::convert::{TryFrom, TryInto};
8 use pulldown_cmark::{BrokenLink, CowStr, Event, InlineStr, LinkType, Options, Parser, Tag};
9 use pulldown_cmark_to_cmark::{cmark_with_options, Options as CmarkOptions};
14 db::HirDatabase, Adt, AsAssocItem, AssocItem, AssocItemContainer, Crate, HasAttrs, MacroDef,
18 defs::{Definition, NameClass, NameRefClass},
19 helpers::pick_best_token,
22 use syntax::{ast, match_ast, AstNode, SyntaxKind::*, SyntaxNode, TextRange, T};
25 doc_links::intra_doc_links::{parse_intra_doc_link, strip_prefixes_suffixes},
26 FilePosition, Semantics,
29 /// Weblink to an item's documentation.
30 pub(crate) type DocumentationLink = String;
32 /// Rewrite documentation links in markdown to point to an online host (e.g. docs.rs)
33 pub(crate) fn rewrite_links(db: &RootDatabase, markdown: &str, definition: Definition) -> String {
34 let mut cb = broken_link_clone_cb;
36 Parser::new_with_broken_link_callback(markdown, Options::ENABLE_TASKLISTS, Some(&mut cb));
38 let doc = map_links(doc, |target, title| {
39 // This check is imperfect, there's some overlap between valid intra-doc links
40 // and valid URLs so we choose to be too eager to try to resolve what might be
42 if target.contains("://") {
43 (target.to_string(), title.to_string())
46 // * path-based links: `../../module/struct.MyStruct.html`
47 // * module-based links (AKA intra-doc links): `super::super::module::MyStruct`
48 if let Some(rewritten) = rewrite_intra_doc_link(db, definition, target, title) {
51 if let Definition::ModuleDef(def) = definition {
52 if let Some(target) = rewrite_url_link(db, Either::Left(def), target) {
53 return (target, title.to_string());
57 (target.to_string(), title.to_string())
60 let mut out = String::new();
65 CmarkOptions { code_block_backticks: 3, ..Default::default() },
71 /// Remove all links in markdown documentation.
72 pub(crate) fn remove_links(markdown: &str) -> String {
73 let mut drop_link = false;
75 let opts = Options::ENABLE_TASKLISTS | Options::ENABLE_FOOTNOTES;
77 let mut cb = |_: BrokenLink| {
78 let empty = InlineStr::try_from("").unwrap();
79 Some((CowStr::Inlined(empty), CowStr::Inlined(empty)))
81 let doc = Parser::new_with_broken_link_callback(markdown, opts, Some(&mut cb));
82 let doc = doc.filter_map(move |evt| match evt {
83 Event::Start(Tag::Link(link_type, target, title)) => {
84 if link_type == LinkType::Inline && target.contains("://") {
85 Some(Event::Start(Tag::Link(link_type, target, title)))
91 Event::End(_) if drop_link => {
98 let mut out = String::new();
103 CmarkOptions { code_block_backticks: 3, ..Default::default() },
109 /// Retrieve a link to documentation for the given symbol.
110 pub(crate) fn external_docs(
112 position: &FilePosition,
113 ) -> Option<DocumentationLink> {
114 let sema = &Semantics::new(db);
115 let file = sema.parse(position.file_id).syntax().clone();
116 let token = pick_best_token(file.token_at_offset(position.offset), |kind| match kind {
117 IDENT | INT_NUMBER | T![self] => 3,
118 T!['('] | T![')'] => 2,
119 kind if kind.is_trivia() => 0,
122 let token = sema.descend_into_macros(token);
124 let node = token.parent()?;
125 let definition = match_ast! {
127 ast::NameRef(name_ref) => match NameRefClass::classify(sema, &name_ref)? {
128 NameRefClass::Definition(def) => def,
129 NameRefClass::FieldShorthand { local_ref: _, field_ref } => {
130 Definition::Field(field_ref)
133 ast::Name(name) => match NameClass::classify(sema, &name)? {
134 NameClass::Definition(it) | NameClass::ConstReference(it) => it,
135 NameClass::PatFieldShorthand { local_def: _, field_ref } => Definition::Field(field_ref),
141 get_doc_link(db, definition)
144 /// Extracts all links from a given markdown text returning the definition text range, link-text
145 /// and the namespace if known.
146 pub(crate) fn extract_definitions_from_docs(
147 docs: &hir::Documentation,
148 ) -> Vec<(TextRange, String, Option<hir::Namespace>)> {
149 Parser::new_with_broken_link_callback(
151 Options::ENABLE_TASKLISTS,
152 Some(&mut broken_link_clone_cb),
155 .filter_map(|(event, range)| match event {
156 Event::Start(Tag::Link(_, target, _)) => {
157 let (link, ns) = parse_intra_doc_link(&target);
159 TextRange::new(range.start.try_into().ok()?, range.end.try_into().ok()?),
169 pub(crate) fn resolve_doc_path_for_def(
170 db: &dyn HirDatabase,
173 ns: Option<hir::Namespace>,
174 ) -> Option<Either<ModuleDef, MacroDef>> {
176 Definition::ModuleDef(def) => match def {
177 hir::ModuleDef::Module(it) => it.resolve_doc_path(db, link, ns),
178 hir::ModuleDef::Function(it) => it.resolve_doc_path(db, link, ns),
179 hir::ModuleDef::Adt(it) => it.resolve_doc_path(db, link, ns),
180 hir::ModuleDef::Variant(it) => it.resolve_doc_path(db, link, ns),
181 hir::ModuleDef::Const(it) => it.resolve_doc_path(db, link, ns),
182 hir::ModuleDef::Static(it) => it.resolve_doc_path(db, link, ns),
183 hir::ModuleDef::Trait(it) => it.resolve_doc_path(db, link, ns),
184 hir::ModuleDef::TypeAlias(it) => it.resolve_doc_path(db, link, ns),
185 hir::ModuleDef::BuiltinType(_) => None,
187 Definition::Macro(it) => it.resolve_doc_path(db, link, ns),
188 Definition::Field(it) => it.resolve_doc_path(db, link, ns),
189 Definition::SelfType(_)
190 | Definition::Local(_)
191 | Definition::GenericParam(_)
192 | Definition::Label(_) => None,
196 pub(crate) fn doc_attributes(
197 sema: &Semantics<RootDatabase>,
199 ) -> Option<(hir::AttrsWithOwner, Definition)> {
202 ast::SourceFile(it) => sema.to_def(&it).map(|def| (def.attrs(sema.db), Definition::ModuleDef(hir::ModuleDef::Module(def)))),
203 ast::Module(it) => sema.to_def(&it).map(|def| (def.attrs(sema.db), Definition::ModuleDef(hir::ModuleDef::Module(def)))),
204 ast::Fn(it) => sema.to_def(&it).map(|def| (def.attrs(sema.db), Definition::ModuleDef(hir::ModuleDef::Function(def)))),
205 ast::Struct(it) => sema.to_def(&it).map(|def| (def.attrs(sema.db), Definition::ModuleDef(hir::ModuleDef::Adt(hir::Adt::Struct(def))))),
206 ast::Union(it) => sema.to_def(&it).map(|def| (def.attrs(sema.db), Definition::ModuleDef(hir::ModuleDef::Adt(hir::Adt::Union(def))))),
207 ast::Enum(it) => sema.to_def(&it).map(|def| (def.attrs(sema.db), Definition::ModuleDef(hir::ModuleDef::Adt(hir::Adt::Enum(def))))),
208 ast::Variant(it) => sema.to_def(&it).map(|def| (def.attrs(sema.db), Definition::ModuleDef(hir::ModuleDef::Variant(def)))),
209 ast::Trait(it) => sema.to_def(&it).map(|def| (def.attrs(sema.db), Definition::ModuleDef(hir::ModuleDef::Trait(def)))),
210 ast::Static(it) => sema.to_def(&it).map(|def| (def.attrs(sema.db), Definition::ModuleDef(hir::ModuleDef::Static(def)))),
211 ast::Const(it) => sema.to_def(&it).map(|def| (def.attrs(sema.db), Definition::ModuleDef(hir::ModuleDef::Const(def)))),
212 ast::TypeAlias(it) => sema.to_def(&it).map(|def| (def.attrs(sema.db), Definition::ModuleDef(hir::ModuleDef::TypeAlias(def)))),
213 ast::Impl(it) => sema.to_def(&it).map(|def| (def.attrs(sema.db), Definition::SelfType(def))),
214 ast::RecordField(it) => sema.to_def(&it).map(|def| (def.attrs(sema.db), Definition::Field(def))),
215 ast::TupleField(it) => sema.to_def(&it).map(|def| (def.attrs(sema.db), Definition::Field(def))),
216 ast::Macro(it) => sema.to_def(&it).map(|def| (def.attrs(sema.db), Definition::Macro(def))),
217 // ast::Use(it) => sema.to_def(&it).map(|def| (Box::new(it) as _, def.attrs(sema.db))),
223 fn broken_link_clone_cb<'a, 'b>(link: BrokenLink<'a>) -> Option<(CowStr<'b>, CowStr<'b>)> {
224 // These allocations are actually unnecessary but the lifetimes on BrokenLinkCallback are wrong
225 // this is fixed in the repo but not on the crates.io release yet
227 /*url*/ link.reference.to_owned().into(),
228 /*title*/ link.reference.to_owned().into(),
233 // BUG: For Option::Some
234 // Returns https://doc.rust-lang.org/nightly/core/prelude/v1/enum.Option.html#variant.Some
235 // Instead of https://doc.rust-lang.org/nightly/core/option/enum.Option.html
237 // This should cease to be a problem if RFC2988 (Stable Rustdoc URLs) is implemented
238 // https://github.com/rust-lang/rfcs/pull/2988
239 fn get_doc_link(db: &RootDatabase, definition: Definition) -> Option<String> {
240 let (target, frag) = match definition {
241 Definition::ModuleDef(def) => {
242 if let Some(assoc_item) = def.as_assoc_item(db) {
243 let def = match assoc_item.container(db) {
244 AssocItemContainer::Trait(t) => t.into(),
245 AssocItemContainer::Impl(i) => i.self_ty(db).as_adt()?.into(),
247 let frag = get_assoc_item_fragment(db, assoc_item)?;
248 (Either::Left(def), Some(frag))
250 (Either::Left(def), None)
253 Definition::Field(field) => {
254 let def = match field.parent_def(db) {
255 hir::VariantDef::Struct(it) => it.into(),
256 hir::VariantDef::Union(it) => it.into(),
257 hir::VariantDef::Variant(it) => it.into(),
259 (Either::Left(def), Some(format!("structfield.{}", field.name(db))))
261 Definition::Macro(makro) => (Either::Right(makro), None),
263 Definition::SelfType(_) => return None,
264 Definition::Local(_) | Definition::GenericParam(_) | Definition::Label(_) => return None,
267 let krate = crate_of_def(db, target)?;
268 let mut url = get_doc_base_url(db, &krate)?;
270 if let Some(path) = mod_path_of_def(db, target) {
271 url = url.join(&path).ok()?;
274 url = url.join(&get_symbol_filename(db, target)?).ok()?;
275 url.set_fragment(frag.as_deref());
280 fn rewrite_intra_doc_link(
285 ) -> Option<(String, String)> {
286 let (link, ns) = parse_intra_doc_link(target);
288 let resolved = resolve_doc_path_for_def(db, def, link, ns)?;
289 let krate = crate_of_def(db, resolved)?;
290 let mut url = get_doc_base_url(db, &krate)?;
292 if let Some(path) = mod_path_of_def(db, resolved) {
293 url = url.join(&path).ok()?;
296 let (resolved, frag) =
297 if let Some(assoc_item) = resolved.left().and_then(|it| it.as_assoc_item(db)) {
298 let resolved = match assoc_item.container(db) {
299 AssocItemContainer::Trait(t) => t.into(),
300 AssocItemContainer::Impl(i) => i.self_ty(db).as_adt()?.into(),
302 let frag = get_assoc_item_fragment(db, assoc_item)?;
303 (Either::Left(resolved), Some(frag))
307 url = url.join(&get_symbol_filename(db, resolved)?).ok()?;
308 url.set_fragment(frag.as_deref());
310 Some((url.into(), strip_prefixes_suffixes(title).to_string()))
313 /// Try to resolve path to local documentation via path-based links (i.e. `../gateway/struct.Shard.html`).
316 def: Either<ModuleDef, MacroDef>,
318 ) -> Option<String> {
319 if !(target.contains('#') || target.contains(".html")) {
323 let krate = crate_of_def(db, def)?;
324 let mut url = get_doc_base_url(db, &krate)?;
326 if let Some(path) = mod_path_of_def(db, def) {
327 url = url.join(&path).ok()?;
330 url = url.join(&get_symbol_filename(db, def)?).ok()?;
331 url.join(target).ok().map(Into::into)
334 fn crate_of_def(db: &RootDatabase, def: Either<ModuleDef, MacroDef>) -> Option<Crate> {
335 let krate = match def {
336 // Definition::module gives back the parent module, we don't want that as it fails for root modules
337 Either::Left(ModuleDef::Module(module)) => module.krate(),
338 Either::Left(def) => def.module(db)?.krate(),
339 Either::Right(def) => def.module(db)?.krate(),
344 fn mod_path_of_def(db: &RootDatabase, def: Either<ModuleDef, MacroDef>) -> Option<String> {
346 Either::Left(def) => def.canonical_module_path(db).map(|it| {
347 let mut path = String::new();
348 it.flat_map(|it| it.name(db)).for_each(|name| format_to!(path, "{}/", name));
351 Either::Right(def) => {
352 def.module(db).map(|it| it.path_to_root(db).into_iter().rev()).map(|it| {
353 let mut path = String::new();
354 it.flat_map(|it| it.name(db)).for_each(|name| format_to!(path, "{}/", name));
361 /// Rewrites a markdown document, applying 'callback' to each link.
363 events: impl Iterator<Item = Event<'e>>,
364 callback: impl Fn(&str, &str) -> (String, String),
365 ) -> impl Iterator<Item = Event<'e>> {
366 let mut in_link = false;
367 let mut link_target: Option<CowStr> = None;
369 events.map(move |evt| match evt {
370 Event::Start(Tag::Link(_, ref target, _)) => {
372 link_target = Some(target.clone());
375 Event::End(Tag::Link(link_type, target, _)) => {
377 Event::End(Tag::Link(
379 link_target.take().unwrap_or(target),
380 CowStr::Borrowed(""),
383 Event::Text(s) if in_link => {
384 let (link_target_s, link_name) = callback(&link_target.take().unwrap(), &s);
385 link_target = Some(CowStr::Boxed(link_target_s.into()));
386 Event::Text(CowStr::Boxed(link_name.into()))
388 Event::Code(s) if in_link => {
389 let (link_target_s, link_name) = callback(&link_target.take().unwrap(), &s);
390 link_target = Some(CowStr::Boxed(link_target_s.into()));
391 Event::Code(CowStr::Boxed(link_name.into()))
397 /// Get the root URL for the documentation of a crate.
400 /// https://doc.rust-lang.org/std/iter/trait.Iterator.html#tymethod.next
401 /// ^^^^^^^^^^^^^^^^^^^^^^^^^^
403 fn get_doc_base_url(db: &RootDatabase, krate: &Crate) -> Option<Url> {
404 let display_name = krate.display_name(db)?;
406 .get_html_root_url(db)
408 // Fallback to docs.rs. This uses `display_name` and can never be
409 // correct, but that's what fallbacks are about.
411 // FIXME: clicking on the link should just open the file in the editor,
412 // instead of falling back to external urls.
413 Some(format!("https://docs.rs/{krate}/*/", krate = display_name))
415 .and_then(|s| Url::parse(&s).ok()?.join(&format!("{}/", display_name)).ok())
418 /// Get the filename and extension generated for a symbol by rustdoc.
421 /// https://doc.rust-lang.org/std/iter/trait.Iterator.html#tymethod.next
422 /// ^^^^^^^^^^^^^^^^^^^
424 fn get_symbol_filename(
425 db: &dyn HirDatabase,
426 definition: Either<ModuleDef, MacroDef>,
427 ) -> Option<String> {
428 let res = match definition {
429 Either::Left(definition) => match definition {
430 ModuleDef::Adt(adt) => match adt {
431 Adt::Struct(s) => format!("struct.{}.html", s.name(db)),
432 Adt::Enum(e) => format!("enum.{}.html", e.name(db)),
433 Adt::Union(u) => format!("union.{}.html", u.name(db)),
435 ModuleDef::Module(m) => match m.name(db) {
436 Some(name) => format!("{}/index.html", name),
437 None => String::from("index.html"),
439 ModuleDef::Trait(t) => format!("trait.{}.html", t.name(db)),
440 ModuleDef::TypeAlias(t) => format!("type.{}.html", t.name(db)),
441 ModuleDef::BuiltinType(t) => format!("primitive.{}.html", t.name()),
442 ModuleDef::Function(f) => format!("fn.{}.html", f.name(db)),
443 ModuleDef::Variant(ev) => {
444 format!("enum.{}.html#variant.{}", ev.parent_enum(db).name(db), ev.name(db))
446 ModuleDef::Const(c) => format!("const.{}.html", c.name(db)?),
447 ModuleDef::Static(s) => format!("static.{}.html", s.name(db)?),
449 Either::Right(mac) => format!("macro.{}.html", mac.name(db)?),
454 /// Get the fragment required to link to a specific field, method, associated type, or associated constant.
457 /// https://doc.rust-lang.org/std/iter/trait.Iterator.html#tymethod.next
460 fn get_assoc_item_fragment(db: &dyn HirDatabase, assoc_item: hir::AssocItem) -> Option<String> {
461 Some(match assoc_item {
462 AssocItem::Function(function) => {
463 let is_trait_method =
464 function.as_assoc_item(db).and_then(|assoc| assoc.containing_trait(db)).is_some();
465 // This distinction may get more complicated when specialization is available.
466 // Rustdoc makes this decision based on whether a method 'has defaultness'.
467 // Currently this is only the case for provided trait methods.
468 if is_trait_method && !function.has_body(db) {
469 format!("tymethod.{}", function.name(db))
471 format!("method.{}", function.name(db))
474 AssocItem::Const(constant) => format!("associatedconstant.{}", constant.name(db)?),
475 AssocItem::TypeAlias(ty) => format!("associatedtype.{}", ty.name(db)),
481 use expect_test::{expect, Expect};
482 use ide_db::base_db::FileRange;
483 use itertools::Itertools;
485 use crate::{display::TryToNav, fixture};
490 fn external_docs_doc_url_crate() {
493 //- /main.rs crate:main deps:test
495 //- /lib.rs crate:test
498 expect![[r#"https://docs.rs/test/*/test/index.html"#]],
503 fn external_docs_doc_url_struct() {
508 expect![[r#"https://docs.rs/test/*/test/struct.Foo.html"#]],
513 fn external_docs_doc_url_struct_field() {
520 expect![[r##"https://docs.rs/test/*/test/struct.Foo.html#structfield.field"##]],
525 fn external_docs_doc_url_fn() {
530 expect![[r##"https://docs.rs/test/*/test/fn.foo.html"##]],
535 fn external_docs_doc_url_impl_assoc() {
543 expect![[r##"https://docs.rs/test/*/test/struct.Foo.html#method.method"##]],
549 const CONST$0: () = ();
552 expect![[r##"https://docs.rs/test/*/test/struct.Foo.html#associatedconstant.CONST"##]],
557 fn external_docs_doc_url_impl_trait_assoc() {
568 expect![[r##"https://docs.rs/test/*/test/struct.Foo.html#method.method"##]],
574 const CONST: () = ();
577 const CONST$0: () = ();
580 expect![[r##"https://docs.rs/test/*/test/struct.Foo.html#associatedconstant.CONST"##]],
592 expect![[r##"https://docs.rs/test/*/test/struct.Foo.html#associatedtype.Type"##]],
597 fn external_docs_doc_url_trait_assoc() {
604 expect![[r##"https://docs.rs/test/*/test/trait.Foo.html#tymethod.method"##]],
612 expect![[r##"https://docs.rs/test/*/test/trait.Foo.html#associatedconstant.CONST"##]],
620 expect![[r##"https://docs.rs/test/*/test/trait.Foo.html#associatedtype.Type"##]],
625 fn external_docs_trait() {
630 expect![[r#"https://docs.rs/test/*/test/trait.Trait.html"#]],
635 fn external_docs_module() {
642 expect![[r#"https://docs.rs/test/*/test/foo/bar/index.html"#]],
647 fn external_docs_reexport_order() {
651 pub use module::Item;
659 let bar: wrapper::It$0em;
662 expect![[r#"https://docs.rs/test/*/test/wrapper/module/struct.Item.html"#]],
667 fn test_trait_items() {
679 // ^^^^^ Trait::CONST
688 fn rewrite_html_root_url() {
691 #![doc(arbitrary_attribute = "test", html_root_url = "https:/example.com", arbitrary_attribute2)]
699 expect![[r#"[Foo](https://example.com/test/foo/struct.Foo.html)"#]],
704 fn rewrite_on_field() {
706 // [Foo](https://docs.rs/test/*/test/struct.Foo.html)
710 /// [Foo](struct.Foo.html)
714 expect![[r#"[Foo](struct.Foo.html)"#]],
719 fn rewrite_struct() {
725 expect![[r#"[Foo](https://docs.rs/test/*/test/struct.Foo.html)"#]],
732 expect![[r#"[`Foo`](https://docs.rs/test/*/test/struct.Foo.html)"#]],
736 /// [Foo](struct.Foo.html)
739 expect![[r#"[Foo](https://docs.rs/test/*/test/struct.Foo.html)"#]],
743 /// [struct Foo](struct.Foo.html)
746 expect![[r#"[struct Foo](https://docs.rs/test/*/test/struct.Foo.html)"#]],
755 expect![[r#"[my Foo](https://docs.rs/test/*/test/struct.Foo.html)"#]],
759 fn check_external_docs(ra_fixture: &str, expect: Expect) {
760 let (analysis, position) = fixture::position(ra_fixture);
761 let url = analysis.external_docs(position).unwrap().expect("could not find url for symbol");
763 expect.assert_eq(&url)
766 fn check_rewrite(ra_fixture: &str, expect: Expect) {
767 let (analysis, position) = fixture::position(ra_fixture);
768 let sema = &Semantics::new(&*analysis.db);
769 let (cursor_def, docs) = def_under_cursor(sema, &position);
770 let res = rewrite_links(sema.db, docs.as_str(), cursor_def);
771 expect.assert_eq(&res)
774 fn check_doc_links(ra_fixture: &str) {
775 let key_fn = |&(FileRange { file_id, range }, _): &_| (file_id, range.start());
777 let (analysis, position, mut expected) = fixture::annotations(ra_fixture);
778 expected.sort_by_key(key_fn);
779 let sema = &Semantics::new(&*analysis.db);
780 let (cursor_def, docs) = def_under_cursor(sema, &position);
781 let defs = extract_definitions_from_docs(&docs);
782 let actual: Vec<_> = defs
784 .map(|(_, link, ns)| {
785 let def = resolve_doc_path_for_def(sema.db, cursor_def, &link, ns)
786 .unwrap_or_else(|| panic!("Failed to resolve {}", link));
787 let nav_target = def.try_to_nav(sema.db).unwrap();
788 let range = FileRange {
789 file_id: nav_target.file_id,
790 range: nav_target.focus_or_full_range(),
794 .sorted_by_key(key_fn)
796 assert_eq!(expected, actual);
800 sema: &Semantics<RootDatabase>,
801 position: &FilePosition,
802 ) -> (Definition, hir::Documentation) {
803 let (docs, def) = sema
804 .parse(position.file_id)
806 .token_at_offset(position.offset)
810 .find_map(|it| node_to_def(sema, &it))
811 .expect("no def found")
813 let docs = docs.expect("no docs found for cursor def");
818 sema: &Semantics<RootDatabase>,
820 ) -> Option<Option<(Option<hir::Documentation>, Definition)>> {
823 ast::SourceFile(it) => sema.to_def(&it).map(|def| (def.docs(sema.db), Definition::ModuleDef(hir::ModuleDef::Module(def)))),
824 ast::Module(it) => sema.to_def(&it).map(|def| (def.docs(sema.db), Definition::ModuleDef(hir::ModuleDef::Module(def)))),
825 ast::Fn(it) => sema.to_def(&it).map(|def| (def.docs(sema.db), Definition::ModuleDef(hir::ModuleDef::Function(def)))),
826 ast::Struct(it) => sema.to_def(&it).map(|def| (def.docs(sema.db), Definition::ModuleDef(hir::ModuleDef::Adt(hir::Adt::Struct(def))))),
827 ast::Union(it) => sema.to_def(&it).map(|def| (def.docs(sema.db), Definition::ModuleDef(hir::ModuleDef::Adt(hir::Adt::Union(def))))),
828 ast::Enum(it) => sema.to_def(&it).map(|def| (def.docs(sema.db), Definition::ModuleDef(hir::ModuleDef::Adt(hir::Adt::Enum(def))))),
829 ast::Variant(it) => sema.to_def(&it).map(|def| (def.docs(sema.db), Definition::ModuleDef(hir::ModuleDef::Variant(def)))),
830 ast::Trait(it) => sema.to_def(&it).map(|def| (def.docs(sema.db), Definition::ModuleDef(hir::ModuleDef::Trait(def)))),
831 ast::Static(it) => sema.to_def(&it).map(|def| (def.docs(sema.db), Definition::ModuleDef(hir::ModuleDef::Static(def)))),
832 ast::Const(it) => sema.to_def(&it).map(|def| (def.docs(sema.db), Definition::ModuleDef(hir::ModuleDef::Const(def)))),
833 ast::TypeAlias(it) => sema.to_def(&it).map(|def| (def.docs(sema.db), Definition::ModuleDef(hir::ModuleDef::TypeAlias(def)))),
834 ast::Impl(it) => sema.to_def(&it).map(|def| (def.docs(sema.db), Definition::SelfType(def))),
835 ast::RecordField(it) => sema.to_def(&it).map(|def| (def.docs(sema.db), Definition::Field(def))),
836 ast::TupleField(it) => sema.to_def(&it).map(|def| (def.docs(sema.db), Definition::Field(def))),
837 ast::Macro(it) => sema.to_def(&it).map(|def| (def.docs(sema.db), Definition::Macro(def))),
838 // ast::Use(it) => sema.to_def(&it).map(|def| (Box::new(it) as _, def.attrs(sema.db))),