|
1 | 1 | from typing import TYPE_CHECKING |
2 | 2 |
|
3 | 3 | from docutils import nodes |
| 4 | +from sphinx import addnodes |
4 | 5 | from sphinx.util.logging import getLogger |
| 6 | +from sphinx.util.nodes import make_id |
5 | 7 |
|
6 | 8 | from sphinx_rust.sphinx_rust import load_enums, load_module, load_modules, load_structs |
7 | 9 |
|
8 | 10 | from ._core import ( |
9 | 11 | RustAutoDirective, |
10 | 12 | create_summary_table, |
| 13 | + create_xref, |
11 | 14 | parse_docstring, |
12 | 15 | ) |
13 | 16 |
|
14 | 17 | if TYPE_CHECKING: |
| 18 | + from sphinx_rust.domain import ObjType |
15 | 19 | from sphinx_rust.sphinx_rust import Enum, Module, Struct |
16 | 20 |
|
17 | 21 | LOGGER = getLogger(__name__) |
@@ -54,27 +58,45 @@ def run(self) -> list[nodes.Node]: |
54 | 58 |
|
55 | 59 | root = nodes.Element() |
56 | 60 |
|
| 61 | + desc = addnodes.desc() |
| 62 | + root += desc |
| 63 | + signature = addnodes.desc_signature( |
| 64 | + module.name, f'pub mod {module.name.split("::")[-1]};' |
| 65 | + ) |
| 66 | + desc += signature |
| 67 | + # desc += addnodes.desc_content("", nodes.paragraph("", )) |
| 68 | + node_id = make_id(self.env, self.doc, "", module.name) |
| 69 | + signature["ids"].append(node_id) |
| 70 | + self.doc.note_explicit_target(signature) |
| 71 | + self.rust_domain.note_object(module.name, "module", node_id, signature) |
| 72 | + |
57 | 73 | if module.docstring: |
58 | 74 | root += parse_docstring(self.env, self.doc, module.docstring) |
59 | 75 |
|
60 | 76 | items: list[Module | Struct | Enum] |
61 | | - for name, items in [ # type: ignore[assignment] |
62 | | - ("Modules", load_modules(self.cache_path, qualifier + "::")), |
63 | | - ("Structs", load_structs(self.cache_path, qualifier + "::")), |
64 | | - ("Enums", load_enums(self.cache_path, qualifier + "::")), |
| 77 | + objtype: ObjType |
| 78 | + for name, objtype, items in [ # type: ignore[assignment] |
| 79 | + ("Modules", "module", load_modules(self.cache_path, qualifier + "::")), |
| 80 | + ("Structs", "struct", load_structs(self.cache_path, qualifier + "::")), |
| 81 | + ("Enums", "enum", load_enums(self.cache_path, qualifier + "::")), |
65 | 82 | ]: |
66 | 83 | if items: |
67 | 84 | section = self.create_section(name) |
68 | 85 | root += section |
69 | 86 | rows = [ |
70 | 87 | ( |
71 | | - # TODO should be references not just text |
72 | | - [nodes.Text(item.name)], |
| 88 | + [ |
| 89 | + nodes.paragraph( |
| 90 | + "", |
| 91 | + "", |
| 92 | + create_xref(self.env.docname, item.name, objtype), |
| 93 | + ) |
| 94 | + ], |
73 | 95 | parse_docstring( |
74 | 96 | self.env, |
75 | 97 | self.doc, |
76 | 98 | # TODO the first line should only be a paragraph |
77 | | - item.docstring.splitlines()[0] if item.docstring else "\-", |
| 99 | + item.docstring.splitlines()[0] if item.docstring else r"\-", |
78 | 100 | ), |
79 | 101 | ) |
80 | 102 | for item in sorted(items, key=lambda m: m.name) |
|
0 commit comments