Commit 552f59d
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
- snapshots
- control_flow
- functions
- misc
- types
- radls
- analysis
- lstesting/snapshots
- rts/check
- snapshots/parser_errors
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
| 39 | + | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | | - | |
| 55 | + | |
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
62 | | - | |
| 62 | + | |
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
356 | 356 | | |
357 | 357 | | |
358 | 358 | | |
359 | | - | |
| 359 | + | |
360 | 360 | | |
361 | 361 | | |
362 | 362 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
75 | | - | |
| 75 | + | |
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
99 | | - | |
| 99 | + | |
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
| |||
121 | 121 | | |
122 | 122 | | |
123 | 123 | | |
124 | | - | |
| 124 | + | |
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
| |||
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
149 | | - | |
| 149 | + | |
150 | 150 | | |
151 | 151 | | |
152 | 152 | | |
| |||
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
174 | | - | |
| 174 | + | |
175 | 175 | | |
176 | 176 | | |
177 | 177 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
| 45 | + | |
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
| 52 | + | |
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
68 | | - | |
| 68 | + | |
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
78 | | - | |
| 78 | + | |
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
| |||
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
97 | | - | |
| 97 | + | |
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
| |||
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
117 | | - | |
| 117 | + | |
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
512 | 512 | | |
513 | 513 | | |
514 | 514 | | |
515 | | - | |
| 515 | + | |
516 | 516 | | |
517 | 517 | | |
518 | 518 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
93 | | - | |
| 93 | + | |
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
475 | 475 | | |
476 | 476 | | |
477 | 477 | | |
478 | | - | |
| 478 | + | |
479 | 479 | | |
480 | 480 | | |
481 | 481 | | |
| |||
0 commit comments