Skip to content

[FEATURE] Report the line of unresolved references - #1401

Open
linawolf wants to merge 3 commits into
mainfrom
task/link-node-line-numbers
Open

linawolf wants to merge 3 commits into
mainfrom
task/link-node-line-numbers

Conversation

@linawolf

@linawolf linawolf commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

[FEATURE] Report the line of unresolved references

Warnings about references that cannot be resolved only name the file,
which makes them hard to find in large documents. Links are resolved
long after parsing, when the line is no longer known, and text roles
only receive the DocumentParserContext, which has no line.

Link nodes now carry their source location, like DirectiveNode does
since 00e6fab, and the reference resolvers include it in their
warnings. It is set centrally by the InlineParser for every link an
inline rule or text role returns, so rules and text roles added by
extensions are covered without changes, and extensions like
render-guides can use it for their own link warnings.

Signed-off-by: linawolf
Assisted-By: Claude Opus 5.5 (1M context) noreply@anthropic.com

Depends on #1402, which makes the line numbers absolute; until
it is merged, this PR also contains its commit.

Warnings logged while parsing report a currentLineNumber that is only
right at the top level of a document. Nested BlockContexts received
their parent's iterator key as offset, which counts from the start of
the parent's content, not from the start of the file. Inside a
directive, list, definition list or table the reported line was
relative to that block, and paragraphs counted their offset twice: a
directive in a list item on line 8 was reported as line 3.

BlockContext's lineOffset now always is the number of lines in the file
before its content, including leading blank lines LinesIterator strips,
and every production passes the absolute offset of its sub-content. A
directive without content is located at its own line. Grid table cells
are located at the table's first line, as rows don't keep the lines
they were parsed from.

This is groundwork for reporting the line of unresolved references.

Signed-off-by: linawolf
Assisted-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Addresses review feedback on #1402: BlockContext needed the number of
lines of its iterator and got it by copying them out with toArray().
LinesIterator now implements Countable, so the count is asked for
directly.

The new LinesIteratorTest also showed that a blank document reported
one leading line removed, from the newline prepareDocument() appends.
A blank document has no first line to map, so it now reports none.

Signed-off-by: linawolf
Assisted-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Warnings about references that cannot be resolved only name the file,
which makes them hard to find in large documents. Links are resolved
long after parsing, when the line is no longer known, and text roles
only receive the DocumentParserContext, which has no line.

Link nodes now carry their source location, like DirectiveNode does
since 00e6fab, and the reference resolvers include it in their
warnings. It is set centrally by the InlineParser for every link an
inline rule or text role returns, so rules and text roles added by
extensions are covered without changes, and extensions like
render-guides can use it for their own link warnings.

Signed-off-by: linawolf
Assisted-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@linawolf
linawolf force-pushed the task/link-node-line-numbers branch from c4d7776 to 93d6346 Compare October 1, 2026 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant