[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH v2 30/35] docs/qapi-domain: implement error context reporting
From: |
John Snow |
Subject: |
[RFC PATCH v2 30/35] docs/qapi-domain: implement error context reporting fix |
Date: |
Thu, 12 Dec 2024 20:12:59 -0500 |
Sphinx 5.3.0 to Sphinx 6.2.0 has a bug where nested content in an
ObjectDescription content block has its error position reported
incorrectly due to an oversight when they added nested section support
to this directive.
(This bug is present in Sphinx's own Python and C domains; test it
yourself by creating a py:func directive and creating a syntax error in
the directive's content block.)
To avoid overriding and re-implementing the entirety of the run()
method, a workaround is employed where we parse the content block
ourselves in before_content(), then null the content block to make
Sphinx's own parsing a no-op. Then, in transform_content (which occurs
after Sphinx's nested parse), we simply swap our own parsed content tree
back in for Sphinx's.
It appears a little tricky, but it's the nicest solution I can find.
Signed-off-by: John Snow <jsnow@redhat.com>
---
docs/sphinx/qapi-domain.py | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/docs/sphinx/qapi-domain.py b/docs/sphinx/qapi-domain.py
index 8dbf0ee5e70..7cbf12d93f7 100644
--- a/docs/sphinx/qapi-domain.py
+++ b/docs/sphinx/qapi-domain.py
@@ -21,8 +21,10 @@
from docutils import nodes
from docutils.parsers.rst import directives
+from docutils.statemachine import StringList
from compat import keyword_node, nested_parse, space_node
+import sphinx
from sphinx import addnodes
from sphinx.addnodes import desc_signature, pending_xref
from sphinx.directives import ObjectDescription
@@ -509,7 +511,29 @@ def _validate_field(self, field: nodes.field) -> None:
)
logger.warning(msg, location=field)
+ def before_content(self) -> None:
+ # Work around a sphinx bug and parse the content ourselves.
+ self._temp_content = self.content
+ self._temp_offset = self.content_offset
+ self._temp_node = None
+
+ if (5, 3, 0) <= sphinx.version_info[:3] < (6, 2, 0):
+ self._temp_node = addnodes.desc_content()
+ self.state.nested_parse(
+ self.content, self.content_offset, self._temp_node
+ )
+ # Sphinx will try to parse the content block itself,
+ # Give it nothingness to parse instead.
+ self.content = StringList()
+ self.content_offset = 0
+
def transform_content(self, contentnode: addnodes.desc_content) -> None:
+ # Sphinx workaround: Inject our parsed content and restore state.
+ if self._temp_node:
+ contentnode += self._temp_node.children
+ self.content = self._temp_content
+ self.content_offset = self._temp_offset
+
self._add_infopips(contentnode)
self._merge_adjoining_field_lists(contentnode)
--
2.47.0
- [RFC PATCH v2 17/35] docs/qapi-domain: add returns-nodesc, (continued)
- [RFC PATCH v2 17/35] docs/qapi-domain: add returns-nodesc, John Snow, 2024/12/12
- [RFC PATCH v2 19/35] docs/qapi-domain: add qapi:alternate directive, John Snow, 2024/12/12
- [RFC PATCH v2 18/35] docs/qapi-domain: add qapi:enum directive, John Snow, 2024/12/12
- [RFC PATCH v2 20/35] docs/qapi-domain: add qapi:event directive, John Snow, 2024/12/12
- [RFC PATCH v2 22/35] docs/qapi-domain: add qapi:union and qapi:branch directives, John Snow, 2024/12/12
- [RFC PATCH v2 23/35] docs/qapi-domain: add :deprecated: directive option, John Snow, 2024/12/12
- [RFC PATCH v2 24/35] docs/qapi-domain: add :unstable: directive option, John Snow, 2024/12/12
- [RFC PATCH v2 26/35] docs/qapi-domain: add warnings for malformed field lists, John Snow, 2024/12/12
- [RFC PATCH v2 27/35] docs/qapi-domain: add type cross-refs to field lists, John Snow, 2024/12/12
- [RFC PATCH v2 25/35] docs/qapi-domain: add :ifcond: directive option, John Snow, 2024/12/12
- [RFC PATCH v2 30/35] docs/qapi-domain: implement error context reporting fix,
John Snow <=
- [RFC PATCH v2 28/35] docs/qapi-domain: add CSS styling, John Snow, 2024/12/12
- [RFC PATCH v2 29/35] docs/qapi-domain: warn when QAPI domain xrefs fail to resolve, John Snow, 2024/12/12
- [RFC PATCH v2 31/35] docs/qapi-domain: collapsible branches, John Snow, 2024/12/12
- [RFC PATCH v2 32/35] WIP: 3.x - XREF, John Snow, 2024/12/12
- [RFC PATCH v2 35/35] WIP: 3.x css theming for missing xref, John Snow, 2024/12/12
- [RFC PATCH v2 34/35] WIP: 3.x ObjectDesc compat, John Snow, 2024/12/12
- [RFC PATCH v2 33/35] WIP: 3.x ParserFix, John Snow, 2024/12/12
- [RFC PATCH v2 21/35] docs/qapi-domain: add qapi:struct directive, John Snow, 2024/12/12