diff mbox series

[v2,32/62] qapi/parser: adjust info location for doc body section

Message ID 20250309083550.5155-33-jsnow@redhat.com (mailing list archive)
State New
Headers show
Series docs: Add new QAPI transmogrifier | expand

Commit Message

John Snow March 9, 2025, 8:35 a.m. UTC
Instead of using the info object for the doc block as a whole (which
always points to the very first line of the block), update the info
pointer for each call to ensure_untagged_section when the existing
section is otherwise empty. This way, Sphinx error information will
match precisely to where the text actually starts.

For example, this patch will move the info pointer for the "Hello!"
untagged section ...

> ##       <-- from here ...
> # Hello! <-- ... to here.
> ##

Signed-off-by: John Snow <jsnow@redhat.com>
---
 scripts/qapi/parser.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Markus Armbruster March 9, 2025, 8:53 p.m. UTC | #1
John Snow <jsnow@redhat.com> writes:

> Instead of using the info object for the doc block as a whole (which
> always points to the very first line of the block), update the info
> pointer for each call to ensure_untagged_section when the existing
> section is otherwise empty. This way, Sphinx error information will
> match precisely to where the text actually starts.
>
> For example, this patch will move the info pointer for the "Hello!"
> untagged section ...
>
>> ##       <-- from here ...
>> # Hello! <-- ... to here.
>> ##
>
> Signed-off-by: John Snow <jsnow@redhat.com>

Here's my attempt to improve the commit message:

    qapi/parser: adjust info location for doc body section

    Instead of using the info object for the doc block as a whole (which
    always points to the very first line of the block), update the info
    pointer for each call to ensure_untagged_section when the existing
    section is otherwise empty. This way, Sphinx error information will
    match precisely to where the text actually starts.

    For example, this patch will move the info pointer for the "Hello!"
    untagged section ...

        ##       <-- from here ...
        # Hello! <-- ... to here.
        ##

    This doesn't seem to improve error reporting now.  It will with the
    QAPI doc transmogrifier I'm about to add.

    If I stick bad rST into qapi/block-core.json like this

         ##
         # @SnapshotInfo:
         #
        +# rST syntax error: *ahh!
        +#
         # @id: unique snapshot id
         #
         # @name: user chosen name

    the existing code's error message will point to the beginning of the
    doc comment, which is less than helpful.  The transmogrifier's
    message will point to the erroneous line, but to accomplish this, it
    needs this patch.

What do you think?
diff mbox series

Patch

diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py
index 64f0bb824ae..97def9f0e4f 100644
--- a/scripts/qapi/parser.py
+++ b/scripts/qapi/parser.py
@@ -686,7 +686,11 @@  def end(self) -> None:
     def ensure_untagged_section(self, info: QAPISourceInfo) -> None:
         if self.all_sections and not self.all_sections[-1].tag:
             # extend current section
-            self.all_sections[-1].text += '\n'
+            section = self.all_sections[-1]
+            if not section.text:
+                # Section is empty so far; update info to start *here*.
+                section.info = info
+            section.text += '\n'
             return
         # start new section
         section = self.Section(info)