Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 88cee43

Browse files
committed
sphinxdocs: allow files to be xref
1 parent 9cfdfd8 commit 88cee43

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

sphinxdocs/src/sphinx_bzl/bzl.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,40 @@ def run(self) -> list[docutils_nodes.Node]:
498498
self.env.ref_context["bzl:file"] = file_label
499499
self.env.ref_context["bzl:object_id_stack"] = []
500500
self.env.ref_context["bzl:doc_id_stack"] = []
501-
return []
501+
502+
_, _, basename = file_label.partition(":")
503+
index_description = f"File {label}"
504+
absolute_label = repo + label
505+
self.env.get_domain('bzl').add_object(
506+
_ObjectEntry(
507+
full_id = absolute_label,
508+
display_name = absolute_label,
509+
object_type = 'obj',
510+
search_priority = 1,
511+
index_entry=domains.IndexEntry(
512+
name=basename,
513+
subtype=_INDEX_SUBTYPE_NORMAL,
514+
docname=self.env.docname,
515+
anchor="",
516+
extra="",
517+
qualifier="",
518+
descr=index_description,
519+
)
520+
521+
),
522+
alt_names = [
523+
# Allow xref //foo:bar.bzl
524+
file_label,
525+
# Allow xref bar.bzl
526+
basename,
527+
]
528+
)
529+
index_node = addnodes.index(
530+
entries=[
531+
_index_node_tuple("single", f"File; {label}", ""),
532+
]
533+
)
534+
return [index_node]
502535

503536

504537
class _BzlAttrInfo(sphinx_docutils.SphinxDirective):

sphinxdocs/tests/sphinx_stardoc/sphinx_output_test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ def _doc_element(self, doc):
6464
("full_repo_aspect", "@testrepo//lang:aspect.bzl%myaspect", "aspect.html#myaspect"),
6565
("full_repo_target", "@testrepo//lang:relativetarget", "target.html#relativetarget"),
6666
("tag_class_attr_using_attr_role", "myext.mytag.ta1", "module_extension.html#myext.mytag.ta1"),
67+
("tag_class_attr_using_attr_role_just_attr_name", "ta1", "module_extension.html#myext.mytag.ta1"),
68+
("file_without_repo", "//lang:rule.bzl", "rule.html"),
69+
("file_with_repo", "@testrepo//lang:rule.bzl", "rule.html"),
6770
# fmt: on
6871
)
6972
def test_xrefs(self, text, href):

sphinxdocs/tests/sphinx_stardoc/xrefs.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,9 @@ Various tests of cross referencing support
4545
## Tag class refs
4646

4747
* tag class attribute using attr role: {attr}`myext.mytag.ta1`
48+
* tag class attribute, just attr name, attr role: {attr}`ta1`
49+
50+
## File refs
51+
52+
* without repo {obj}`//lang:rule.bzl`
53+
* with repo {obj}`@testrepo//lang:rule.bzl`

0 commit comments

Comments
 (0)