[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 25/27] docs/qapi-domain: implement error context reporting fix
From: |
John Snow |
Subject: |
[PATCH 25/27] docs/qapi-domain: implement error context reporting fix |
Date: |
Fri, 19 Apr 2024 00:38:13 -0400 |
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 | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/docs/sphinx/qapi-domain.py b/docs/sphinx/qapi-domain.py
index 074453193ce..7d8911c635f 100644
--- a/docs/sphinx/qapi-domain.py
+++ b/docs/sphinx/qapi-domain.py
@@ -21,7 +21,9 @@
from docutils import nodes
from docutils.parsers.rst import directives
+from docutils.statemachine import StringList
+import sphinx
from sphinx import addnodes
from sphinx.addnodes import desc_signature, pending_xref
from sphinx.directives import ObjectDescription
@@ -470,7 +472,27 @@ 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 sphinx.version_info[:3] >= (5, 3, 0) and 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.44.0
- [PATCH 07/27] docs/qapi-domain: add qapi:command directive, (continued)
- [PATCH 07/27] docs/qapi-domain: add qapi:command directive, John Snow, 2024/04/19
- [PATCH 08/27] docs/qapi-domain: add :since: directive option, John Snow, 2024/04/19
- [PATCH 09/27] docs/qapi-domain: add "Arguments:" field lists, John Snow, 2024/04/19
- [PATCH 11/27] docs/qapi-domain: add "Errors:" field lists, John Snow, 2024/04/19
- [PATCH 02/27] docs/qapi-domain: add qapi:module directive, John Snow, 2024/04/19
- [PATCH 12/27] docs/qapi-domain: add "Returns:" field lists, John Snow, 2024/04/19
- [PATCH 14/27] docs/qapi-domain: add qapi:alternate directive, John Snow, 2024/04/19
- [PATCH 18/27] docs/qapi-domain: add :deprecated: directive option, John Snow, 2024/04/19
- [PATCH 19/27] docs/qapi-domain: add :unstable: directive option, John Snow, 2024/04/19
- [PATCH 20/27] docs/qapi-domain: add :ifcond: directive option, John Snow, 2024/04/19
- [PATCH 25/27] docs/qapi-domain: implement error context reporting fix,
John Snow <=
- [PATCH 26/27] docs/qapi-domain: RFC patch - Add one last sample command, John Snow, 2024/04/19
- [PATCH 27/27] docs/qapi-domain: add CSS styling, John Snow, 2024/04/19
- [PATCH 24/27] docs/qapi-domain: add type cross-refs to field lists, John Snow, 2024/04/19
- Re: [PATCH 00/27] Add qapi-domain Sphinx extension, Markus Armbruster, 2024/04/19