Skip to content

Commit 552f59d

Browse files
committed
ux(radls, check): contextual rename errors + did-you-mean grammar
+ hover stutter Three small UX fixes that all touch user-facing strings. Contextual rename errors Previously the rename handler returned three generic sentinels: "not a valid Rad identifier", "name is already in scope", "the symbol under the cursor cannot be renamed". The user got no hint about which rule they broke. Now wrapped with the specific reason: - "not a valid Rad identifier: 1bad (identifiers can't start with a digit)" - "not a valid Rad identifier: if (this is a reserved Rad keyword)" - "name is already in scope: 'y' is already declared in this scope" - "name is already in scope: 'print' is already a built-in function" The sentinels stay exported and the wrapped errors still match via errors.Is, so anything keying off the existing constants keeps working. isValidRadIdentifier became validateRadIdentifier and returns a reason string on rejection. scopeHasName became scopeCollision and returns "declared in this scope" / "declared in an enclosing scope" / "" so the caller can build a more precise message. Did-you-mean Oxford-or grammar The old format was "did you mean one of 'X', 'Y'?" which reads awkwardly with two items (English says "X or Y" with two) and clunkily with three (no Oxford-or separator). New format mirrors rustc: - 1: "did you mean 'X'?" (unchanged) - 2: "did you mean 'X' or 'Y'?" - 3+ Oxford-or: "did you mean 'X', 'Y', or 'Z'?" emitUndefinedIdentifier in rts/check/binder.go now delegates the formatting to formatDidYouMean in suggestion.go. The radls code- action parser (extractDidYouMeanNames) was rewritten to pull single-quoted runs out of the message regardless of which separator shape was used - one parser handles all three cases and survives future grammar tweaks. Hover stutter for builtins formatIdentHover (and the decl-site fallback formatSymbolHover) were rendering builtins as "print: print(*_items: any) -> void" - a leading "name:" prefix that duplicates the signature's own function name. The prefix is useful for locals (`(local) x: int`) but pure noise for builtins. Now renders the signature alone, matching rust-analyzer's convention. Snapshots updated for: hover.snap BuiltinShowsSignatureAndDocs; rename.snap RenameToInvalidIdentifier / RenameToCollidingName / new reserved-keyword + unloaded-builtin cases; check.snap suggestion lines; core/testing/check_test.go inline expected strings.
1 parent fca8db5 commit 552f59d

19 files changed

Lines changed: 181 additions & 109 deletions

File tree

core/testing/check_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ L1:11: ERROR
2929
1 | hello = 2 a
3030
| ^ Undefined identifier 'a'
3131
| (code: RAD20028)
32-
= help: did you mean one of 'abs', 'map', 'max'?
32+
= help: did you mean 'abs', 'map', or 'max'?
3333
3434
L3:6: ERROR
3535
3636
3 | yes no
3737
| ^ Undefined identifier 'no'
3838
| (code: RAD20028)
39-
= help: did you mean one of 'now', 'int', 'pow'?
39+
= help: did you mean 'now', 'int', or 'pow'?
4040
4141
Reported 4 diagnostics.
4242
`
@@ -52,14 +52,14 @@ func Test_Check_UnknownFunctions(t *testing.T) {
5252
1 | foo()
5353
| ^ Undefined identifier 'foo'
5454
| (code: RAD20028)
55-
= help: did you mean one of 'floor', 'now', 'pow'?
55+
= help: did you mean 'floor', 'now', or 'pow'?
5656
5757
L3:1: ERROR
5858
5959
3 | qux()
6060
| ^ Undefined identifier 'qux'
6161
| (code: RAD20028)
62-
= help: did you mean one of 'max', 'sum'?
62+
= help: did you mean 'max' or 'sum'?
6363
6464
Reported 2 diagnostics.
6565
`

core/testing/snapshots/control_flow/catch.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ error[RAD20028]: Undefined identifier 'out'
356356
6 | return error(out)
357357
| ^^^
358358
|
359-
= help: did you mean one of 'count', 'int', 'sort'?
359+
= help: did you mean 'count', 'int', or 'sort'?
360360
= info: rad explain RAD20028
361361

362362

core/testing/snapshots/control_flow/defer.snap

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ error[RAD20028]: Undefined identifier 'asd'
7272
4 | print(asd)
7373
| ^^^
7474
|
75-
= help: did you mean one of 'abs', 'hash', 'rand'?
75+
= help: did you mean 'abs', 'hash', or 'rand'?
7676
= info: rad explain RAD20028
7777

7878

@@ -96,7 +96,7 @@ error[RAD20028]: Undefined identifier 'asd'
9696
4 | defer print("bye2")
9797
5 | print("hi")
9898
|
99-
= help: did you mean one of 'abs', 'hash', 'rand'?
99+
= help: did you mean 'abs', 'hash', or 'rand'?
100100
= info: rad explain RAD20028
101101

102102

@@ -121,7 +121,7 @@ error[RAD20028]: Undefined identifier 'asd'
121121
4 | defer exit(3) // this one executed before 'asd' error, so we should use its code
122122
5 | defer print("bye2")
123123
|
124-
= help: did you mean one of 'abs', 'hash', 'rand'?
124+
= help: did you mean 'abs', 'hash', or 'rand'?
125125
= info: rad explain RAD20028
126126

127127

@@ -146,7 +146,7 @@ error[RAD20028]: Undefined identifier 'asd'
146146
5 | defer print("bye2")
147147
6 | print("hi")
148148
|
149-
= help: did you mean one of 'abs', 'hash', 'rand'?
149+
= help: did you mean 'abs', 'hash', or 'rand'?
150150
= info: rad explain RAD20028
151151

152152

@@ -171,7 +171,7 @@ error[RAD20028]: Undefined identifier 'asd'
171171
4 | defer exit(0) // this is a clean exit, so we should use the error from 'asd'
172172
5 | defer print("bye2")
173173
|
174-
= help: did you mean one of 'abs', 'hash', 'rand'?
174+
= help: did you mean 'abs', 'hash', or 'rand'?
175175
= info: rad explain RAD20028
176176

177177

core/testing/snapshots/functions/fn.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ error[RAD20028]: Undefined identifier 'a'
4242
3 | a = 2
4343
4 | foo(10).print()
4444
|
45-
= help: did you mean one of 'b', 'abs', 'map'?
45+
= help: did you mean 'b', 'abs', or 'map'?
4646
= info: rad explain RAD20028
4747

4848

core/testing/snapshots/functions/fn_named.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ error[RAD20028]: Undefined identifier 'add'
4949
4 | fn add(x, y):
5050
5 | return x + y
5151
|
52-
= help: did you mean one of 'abs', 'rand', 'red'?
52+
= help: did you mean 'abs', 'rand', or 'red'?
5353
= info: rad explain RAD20028
5454

5555

core/testing/snapshots/misc/interpolation.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ error[RAD20028]: Undefined identifier 'var'
6565
2 | print("hello, {var}")
6666
| ^^^
6767
|
68-
= help: did you mean one of 'map', 'max', 'str'?
68+
= help: did you mean 'map', 'max', or 'str'?
6969
= info: rad explain RAD20028
7070

7171

core/testing/snapshots/misc/migration.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ error[RAD20028]: Undefined identifier 'get_default'
7575
3 | get_default(m, "b", 0)
7676
| ^^^^^^^^^^^
7777
|
78-
= help: did you mean one of 'get_args', 'get_env', 'get_path'?
78+
= help: did you mean 'get_args', 'get_env', or 'get_path'?
7979
= info: rad explain RAD20028
8080

8181

@@ -94,7 +94,7 @@ error[RAD20028]: Undefined identifier 'get_stash_dir'
9494
2 | get_stash_dir()
9595
| ^^^^^^^^^^^^^
9696
|
97-
= help: did you mean one of 'get_stash_path', 'get_path', 'load_stash_file'?
97+
= help: did you mean 'get_stash_path', 'get_path', or 'load_stash_file'?
9898
= info: rad explain RAD20028
9999

100100

@@ -114,7 +114,7 @@ error[RAD20028]: Undefined identifier 'get_default'
114114
3 | m.get_default("b", 0)
115115
| ^^^^^^^^^^^
116116
|
117-
= help: did you mean one of 'get_args', 'get_env', 'get_path'?
117+
= help: did you mean 'get_args', 'get_env', or 'get_path'?
118118
= info: rad explain RAD20028
119119

120120

core/testing/snapshots/misc/misc.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ error[RAD20028]: Undefined identifier 'usernme'
512512
4 | print(usernme)
513513
| ^^^^^^^
514514
|
515-
= help: did you mean one of 'username', 'user_name'?
515+
= help: did you mean 'username' or 'user_name'?
516516
= info: rad explain RAD20028
517517

518518

core/testing/snapshots/misc/scoping.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ error[RAD20028]: Undefined identifier 'i'
9090
6 | print("i", i)
9191
| ^
9292
|
93-
= help: did you mean one of 'dim', 'int', 'min'?
93+
= help: did you mean 'dim', 'int', or 'min'?
9494
= info: rad explain RAD20028
9595

9696

core/testing/snapshots/types/str_lexing.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ error[RAD20028]: Undefined identifier 'text'
475475
5 | print(text)
476476
| ^^^^
477477
|
478-
= help: did you mean one of 'exit', 'ceil', 'int'?
478+
= help: did you mean 'exit', 'ceil', or 'int'?
479479
= info: rad explain RAD20028
480480
481481

0 commit comments

Comments
 (0)