fix(grammar): keep code out of the grammar checker #828

Merged
raisondetredev merged 1 commit from refs/pull/828/head into main 2026-08-08 18:39:18 +02:00
raisondetredev commented 2026-08-08 18:39:06 +02:00 (Migrated from codeberg.org)

A code block's source lives in the node's own delta — the same key a
paragraph uses, deliberately, because that is the schema the learning-path
importer writes. Segmentation walked it like any other text-bearing node, so
every fenced listing in a card or a note was posted to LanguageTool as prose
and came back covered in squiggles: an identifier is a spelling error, a
statement is a sentence without a verb, and } is missing punctuation. Inline
code had the same problem in miniature — a run marked as code is still text in
the paragraph around it, so setState() mid-sentence read as a typo.

Both are now excluded, by the two mechanisms the feature already had for
inline math.

A code node is skipped outright, subtree and all, and yields no segment —
nothing about it reaches the server. Inline-code runs are masked to
same-length spaces and recorded in GrammarSegment.maskedRanges, which the
controller already consults to drop any match touching a mask. Masking rather
than deleting is what preserves the invariant the overlay rests on: a
LanguageTool offset indexes the node's text 1:1, so it maps onto a Position
without remapping. A paragraph that is only a snippet now yields no segment at
all, like a paragraph that is only a formula.

The truthiness test the math path used privately is now shared as _isSet.
AppFlowy writes code: false when a mark is toggled off rather than dropping
the key, so a bare null-check would have masked text the author had explicitly
un-marked.

Only the explicit mark is exempt. A bare setState() typed into a plain run
is still prose as far as the checker is concerned, and still checked — the
signal being honoured here is the author's, not a guess about what looks like
code.

Signed-off-by: Tizian 「ティツィアーン」 raisondetredev@pm.me

A code block's source lives in the node's own `delta` — the same key a paragraph uses, deliberately, because that is the schema the learning-path importer writes. Segmentation walked it like any other text-bearing node, so every fenced listing in a card or a note was posted to LanguageTool as prose and came back covered in squiggles: an identifier is a spelling error, a statement is a sentence without a verb, and `}` is missing punctuation. Inline code had the same problem in miniature — a run marked as code is still text in the paragraph around it, so `setState()` mid-sentence read as a typo. Both are now excluded, by the two mechanisms the feature already had for inline math. A `code` node is skipped outright, subtree and all, and yields no segment — nothing about it reaches the server. Inline-code runs are masked to same-length spaces and recorded in `GrammarSegment.maskedRanges`, which the controller already consults to drop any match touching a mask. Masking rather than deleting is what preserves the invariant the overlay rests on: a LanguageTool offset indexes the node's text 1:1, so it maps onto a `Position` without remapping. A paragraph that is only a snippet now yields no segment at all, like a paragraph that is only a formula. The truthiness test the math path used privately is now shared as `_isSet`. AppFlowy writes `code: false` when a mark is toggled off rather than dropping the key, so a bare null-check would have masked text the author had explicitly un-marked. Only the explicit mark is exempt. A bare `setState()` typed into a plain run is still prose as far as the checker is concerned, and still checked — the signal being honoured here is the author's, not a guess about what looks like code. Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
project-halkyon/halkyon-learn!828
No description provided.