Skip to content

Commit 318112b

Browse files
wickedevclaude
andcommitted
fix: use 1-indexed line numbers in error/warning positions (#9)
Changed adjustLineOffset to always add +1 when adjusting positions, converting from 0-indexed grid rows to 1-indexed file line numbers. Before: position.row = gridRow + lineOffset (0-indexed) After: position.row = gridRow + lineOffset + 1 (1-indexed) This ensures warnings like "MisalignedClosingBorder" report the actual file line number users see in their editor, making debugging easier. Example for a misalignment on Line 5 with scene directive: - Grid row 3 (0-indexed in grid) - lineOffset = 1 (for @scene directive) - position.row = 3 + 1 + 1 = 5 (matches editor Line 5) Updated E2E-13 test to verify position.row = 5 for Line 5. Closes #9 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent c05458a commit 318112b

File tree

2 files changed

+23
-21
lines changed

2 files changed

+23
-21
lines changed

src/parser/Errors/ErrorTypes.res

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -217,18 +217,21 @@ let adjustCodeLineOffset = (code: errorCode, offset: int): errorCode => {
217217
* Adjust the line offset in an error's position.
218218
* Creates a new error with the position adjusted by the given offset.
219219
*
220+
* This function always adds +1 to convert from 0-indexed grid rows
221+
* to 1-indexed file line numbers, plus any offset for stripped directive lines.
222+
*
220223
* @param error - The error to adjust
221-
* @param offset - The number of lines to add to the row
222-
* @returns A new error with adjusted position
224+
* @param offset - The number of directive lines stripped before grid processing
225+
* @returns A new error with 1-indexed line position
223226
*/
224227
let adjustLineOffset = (error: t, offset: int): t => {
225-
if offset === 0 {
226-
error
227-
} else {
228-
{
229-
code: adjustCodeLineOffset(error.code, offset),
230-
severity: error.severity,
231-
context: error.context,
232-
}
228+
// Always add 1 to convert from 0-indexed to 1-indexed line numbers
229+
// offset accounts for stripped directive lines (e.g., @scene: login)
230+
// +1 converts from 0-indexed grid rows to 1-indexed file lines
231+
let totalOffset = offset + 1
232+
{
233+
code: adjustCodeLineOffset(error.code, totalOffset),
234+
severity: error.severity,
235+
context: error.context,
233236
}
234237
}

src/parser/__tests__/WyreframeParser_integration.test.res

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,22 +1022,21 @@ describe("E2E-13: Line number offset in warnings with scene directives (Issue #5
10221022
// We MUST have a misaligned warning for this test to be valid
10231023
t->expect(Array.length(misalignedWarnings))->Expect.toBe(1)
10241024

1025-
// Verify the line number is correct
1025+
// Verify the line number is correct (1-indexed)
10261026
switch misalignedWarnings->Array.get(0) {
10271027
| Some(warning) => {
10281028
switch warning.code {
10291029
| ErrorTypes.MisalignedClosingBorder({position, _}) => {
1030-
// Position.row is 0-indexed:
1031-
// - Line 1 (0-idx 0): @scene: login - directive, stripped
1032-
// - Line 2 (0-idx 1): empty - first content line, lineOffset = 1
1033-
// - Line 3 (0-idx 2): +---+ - grid row 1 (bounds.top)
1034-
// - Line 4 (0-idx 3): |...| - grid row 2
1035-
// - Line 5 (0-idx 4): misaligned - grid row 3
1036-
// - Line 6 (0-idx 5): +---+ - grid row 4 (bounds.bottom)
1030+
// Position.row is 1-indexed for user display:
1031+
// - Line 1: @scene: login (directive, stripped - lineOffset = 1)
1032+
// - Line 2: empty (first content line - grid row 0)
1033+
// - Line 3: +---+ (grid row 1)
1034+
// - Line 4: |...| (grid row 2)
1035+
// - Line 5: misaligned (grid row 3) ← warning points here
1036+
// - Line 6: +---+ (grid row 4)
10371037
//
1038-
// Grid row 3 + lineOffset 1 = row 4 (0-indexed)
1039-
// Which is Line 5 (1-indexed)
1040-
t->expect(position.row)->Expect.toBe(4)
1038+
// Formula: position.row = gridRow + lineOffset + 1 = 3 + 1 + 1 = 5
1039+
t->expect(position.row)->Expect.toBe(5)
10411040
}
10421041
| _ => t->expect(true)->Expect.toBe(false) // Should not reach here
10431042
}

0 commit comments

Comments
 (0)