Browse Source

docs/qapi_domain: add namespace support to FQN

This patch adds a namespace component to the "Fully Qualified Name", in
the form of "domain:module.name". As there are no namespace directives
or options yet, this component will simply be empty as of this patch.

Signed-off-by: John Snow <jsnow@redhat.com>
Message-ID: <20250313044312.189276-4-jsnow@redhat.com>
Acked-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
John Snow 5 tháng trước cách đây
mục cha
commit
74d40b011c
1 tập tin đã thay đổi với 27 bổ sung8 xóa
  1. 27 8
      docs/sphinx/qapi_domain.py

+ 27 - 8
docs/sphinx/qapi_domain.py

@@ -178,15 +178,18 @@ def get_index_text(self, name: Signature) -> Tuple[str, str]:
         # NB: this is used for the global index, not the QAPI index.
         # NB: this is used for the global index, not the QAPI index.
         return ("single", f"{name} (QMP {self.objtype})")
         return ("single", f"{name} (QMP {self.objtype})")
 
 
-    def _get_context(self) -> str:
+    def _get_context(self) -> Tuple[str, str]:
+        namespace = self.options.get(
+            "namespace", self.env.ref_context.get("qapi:namespace", "")
+        )
         modname = self.options.get(
         modname = self.options.get(
             "module", self.env.ref_context.get("qapi:module", "")
             "module", self.env.ref_context.get("qapi:module", "")
         )
         )
-        assert isinstance(modname, str)
-        return modname
+
+        return namespace, modname
 
 
     def _get_fqn(self, name: Signature) -> str:
     def _get_fqn(self, name: Signature) -> str:
-        modname = self._get_context()
+        namespace, modname = self._get_context()
 
 
         # If we're documenting a module, don't include the module as
         # If we're documenting a module, don't include the module as
         # part of the FQN; we ARE the module!
         # part of the FQN; we ARE the module!
@@ -195,6 +198,8 @@ def _get_fqn(self, name: Signature) -> str:
 
 
         if modname:
         if modname:
             name = f"{modname}.{name}"
             name = f"{modname}.{name}"
+        if namespace:
+            name = f"{namespace}:{name}"
         return name
         return name
 
 
     def add_target_and_index(
     def add_target_and_index(
@@ -227,13 +232,18 @@ def add_target_and_index(
                 )
                 )
 
 
     @staticmethod
     @staticmethod
-    def split_fqn(name: str) -> Tuple[str, str]:
+    def split_fqn(name: str) -> Tuple[str, str, str]:
+        if ":" in name:
+            ns, name = name.split(":")
+        else:
+            ns = ""
+
         if "." in name:
         if "." in name:
             module, name = name.split(".")
             module, name = name.split(".")
         else:
         else:
             module = ""
             module = ""
 
 
-        return (module, name)
+        return (ns, module, name)
 
 
     def _object_hierarchy_parts(
     def _object_hierarchy_parts(
         self, sig_node: desc_signature
         self, sig_node: desc_signature
@@ -251,7 +261,7 @@ def _toc_entry_name(self, sig_node: desc_signature) -> str:
             return ""
             return ""
 
 
         config = self.env.app.config
         config = self.env.app.config
-        modname, name = toc_parts
+        namespace, modname, name = toc_parts
 
 
         if config.toc_object_entries_show_parents == "domain":
         if config.toc_object_entries_show_parents == "domain":
             ret = name
             ret = name
@@ -259,6 +269,10 @@ def _toc_entry_name(self, sig_node: desc_signature) -> str:
                 "qapi:module", ""
                 "qapi:module", ""
             ):
             ):
                 ret = f"{modname}.{name}"
                 ret = f"{modname}.{name}"
+            if namespace and namespace != self.env.ref_context.get(
+                "qapi:namespace", ""
+            ):
+                ret = f"{namespace}:{ret}"
             return ret
             return ret
         if config.toc_object_entries_show_parents == "hide":
         if config.toc_object_entries_show_parents == "hide":
             return name
             return name
@@ -334,10 +348,15 @@ def handle_signature(self, sig: str, signode: desc_signature) -> Signature:
         As such, the only argument here is "sig", which is just the QAPI
         As such, the only argument here is "sig", which is just the QAPI
         definition name.
         definition name.
         """
         """
-        modname = self._get_context()
+        # No module or domain info allowed in the signature!
+        assert ":" not in sig
+        assert "." not in sig
 
 
+        namespace, modname = self._get_context()
         signode["fullname"] = self._get_fqn(sig)
         signode["fullname"] = self._get_fqn(sig)
+        signode["namespace"] = namespace
         signode["module"] = modname
         signode["module"] = modname
+
         sig_prefix = self.get_signature_prefix()
         sig_prefix = self.get_signature_prefix()
         if sig_prefix:
         if sig_prefix:
             signode += addnodes.desc_annotation(
             signode += addnodes.desc_annotation(