@@ -502,7 +502,39 @@ def run(self) -> list[docutils_nodes.Node]:
502502 self .env .ref_context ["bzl:file" ] = file_label
503503 self .env .ref_context ["bzl:object_id_stack" ] = []
504504 self .env .ref_context ["bzl:doc_id_stack" ] = []
505- return []
505+
506+ _ , _ , basename = file_label .partition (":" )
507+ index_description = f"File { label } "
508+ absolute_label = repo + label
509+ self .env .get_domain ("bzl" ).add_object (
510+ _ObjectEntry (
511+ full_id = absolute_label ,
512+ display_name = absolute_label ,
513+ object_type = "obj" ,
514+ search_priority = 1 ,
515+ index_entry = domains .IndexEntry (
516+ name = basename ,
517+ subtype = _INDEX_SUBTYPE_NORMAL ,
518+ docname = self .env .docname ,
519+ anchor = "" ,
520+ extra = "" ,
521+ qualifier = "" ,
522+ descr = index_description ,
523+ ),
524+ ),
525+ alt_names = [
526+ # Allow xref //foo:bar.bzl
527+ file_label ,
528+ # Allow xref bar.bzl
529+ basename ,
530+ ],
531+ )
532+ index_node = addnodes .index (
533+ entries = [
534+ _index_node_tuple ("single" , f"File; { label } " , "" ),
535+ ]
536+ )
537+ return [index_node ]
506538
507539
508540class _BzlAttrInfo (sphinx_docutils .SphinxDirective ):
@@ -1493,7 +1525,7 @@ class _BzlDomain(domains.Domain):
14931525 "type" : domains .ObjType ("type" , "type" , "obj" ),
14941526 "typedef" : domains .ObjType ("typedef" , "typedef" , "type" , "obj" ),
14951527 # generic objs usually come from inventories
1496- "obj" : domains .ObjType ("object" , "obj" )
1528+ "obj" : domains .ObjType ("object" , "obj" ),
14971529 }
14981530
14991531 # This controls:
0 commit comments