Skip to content

Commit 1dc4e6b

Browse files
committed
Better cursor display
1 parent ff9ab9c commit 1dc4e6b

3 files changed

Lines changed: 12 additions & 8 deletions

File tree

err_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ func TestEvalAstErrorPosition(t *testing.T) {
253253

254254
// The cursor should point to line 4 where undefined-var is
255255
// Format is typically: TestName§line…line,col…col
256-
if !strings.Contains(lines[0], 4") {
256+
if !strings.Contains(lines[0], L4") {
257257
t.Errorf("Error should reference line 4 where undefined-var is: %s", lines[0])
258258
}
259259

errorparsingunterminated_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func TestErrorParsingUnterminatedString(t *testing.T) {
2121
if err == nil {
2222
t.Fatalf("must throw error but returns %q", ast)
2323
}
24-
if err.Error() != 1…1,6…6: invalid token "hello` {
24+
if err.Error() != L1,C6: invalid token "hello` {
2525
t.Fatal(err)
2626
}
2727
}
@@ -31,7 +31,7 @@ func TestErrorParsingUnterminatedHexa(t *testing.T) {
3131
if err == nil {
3232
t.Fatalf("must throw error but returns %q", ast)
3333
}
34-
if err.Error() != 1…1,2…2: invalid token 0x` {
34+
if err.Error() != L1,C2: invalid token 0x` {
3535
t.Fatal(err)
3636
}
3737
}

types/positiontype.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,15 @@ func (cursor *Position) StringModule() string {
127127
func (cursor *Position) StringPosition() string {
128128
if cursor == nil {
129129
return ""
130-
}
131-
if cursor.Row < 0 {
130+
} else if cursor.Row < 0 {
132131
return ""
132+
} else if cursor.BeginRow == cursor.Row {
133+
if cursor.BeginCol == cursor.Col {
134+
return fmt.Sprintf("L%d,C%d", cursor.BeginRow, cursor.BeginCol)
135+
}
136+
return fmt.Sprintf("L%d,C%d…C%d", cursor.BeginRow, cursor.BeginCol, cursor.Col)
133137
}
134-
return fmt.Sprintf("%d…%d,%d…%d", cursor.BeginRow, cursor.Row, cursor.BeginCol, cursor.Col)
138+
return fmt.Sprintf("L%d…L%d,C%d…C%d", cursor.BeginRow, cursor.Row, cursor.BeginCol, cursor.Col)
135139
}
136140

137141
func (cursor *Position) StringPositionRow() string {
@@ -142,9 +146,9 @@ func (cursor *Position) StringPositionRow() string {
142146
return ""
143147
}
144148
if cursor.BeginRow != cursor.Row {
145-
return fmt.Sprintf("%d…%d", cursor.BeginRow, cursor.Row)
149+
return fmt.Sprintf("L%d…L%d", cursor.BeginRow, cursor.Row)
146150
}
147-
return fmt.Sprintf("%d", cursor.Row)
151+
return fmt.Sprintf("L%d", cursor.Row)
148152
}
149153

150154
func (cursor *Position) Includes(inside Position) bool {

0 commit comments

Comments
 (0)