Skip to content

Commit 9d13f52

Browse files
committed
Highlight single character errors.
1 parent 16577e2 commit 9d13f52

File tree

4 files changed

+40
-19
lines changed

4 files changed

+40
-19
lines changed

spec/errors/access_expected_field_2

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
component Main {
2+
fun render : String {
3+
"". word
4+
--------------------------------------------------------------------------------
5+
░ ERROR (ACCESS_EXPECTED_FIELD) ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
6+
7+
I was expecting the name of the accessed entity but I found "a space" instead:
8+
9+
┌ errors/access_expected_field_2:3:8
10+
├───────────────────────────────────
11+
1│ component Main {
12+
2│ fun render : String {
13+
3│ "". word
14+
│ ⌃

src/errorable.cr

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,11 @@ module Mint
8181
target =
8282
case value
8383
in Parser
84+
min =
85+
value.char == '\0' ? 0 : 1
86+
8487
SnippetData.new(
85-
to: value.position.offset + value.word.to_s.size,
88+
to: value.position.offset + [min, value.word.to_s.size].max,
8689
filename: value.file.relative_path,
8790
from: value.position.offset,
8891
input: value.file.contents)

src/parsers/connect_variable.cr

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,27 @@ module Mint
55
next unless name = variable_constant(track: false) ||
66
variable(track: false)
77

8-
whitespace
9-
if keyword! "as"
10-
whitespace
8+
target =
9+
parse do
10+
whitespace
11+
next unless keyword! "as"
12+
whitespace
1113

12-
next error :connect_variable_expected_as do
13-
block do
14-
text "The"
15-
bold "exposed name"
16-
text "of a connection"
17-
bold "must be specified, here is an example:"
18-
end
14+
next error :connect_variable_expected_as do
15+
block do
16+
text "The"
17+
bold "exposed name"
18+
text "of a connection"
19+
bold "must be specified, here is an example:"
20+
end
1921

20-
snippet "connect Store exposing { item as name }"
21-
expected "the exposed name", word
22-
snippet self
23-
end unless target = variable
24-
end
22+
snippet "connect Store exposing { item as name }"
23+
expected "the exposed name", word
24+
snippet self
25+
end unless variable = self.variable
26+
27+
variable
28+
end
2529

2630
Ast::ConnectVariable.new(
2731
from: start_position,

src/utils/terminal_snippet.cr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,16 @@ module Mint
3434
self[0, diff_from]
3535

3636
center =
37-
self[diff_from, diff_to].colorize.on(:white).fore(:red).to_s
37+
self[diff_from, diff_to]
3838

3939
right =
4040
self[diff_to, contents.size]
4141

4242
highlighted =
43-
left + center + right
43+
left + center.colorize.on(:white).fore(:red).to_s + right
4444

4545
arrows =
46-
(" " * left.size) + ("" * center.uncolorize.size)
46+
(" " * left.size) + ("" * center.size)
4747

4848
{highlighted, arrows}
4949
end

0 commit comments

Comments
 (0)