Commit 11c4588
committed
input: revise CustomHighlighter to token-name model + add example
Reshapes the trait per maintainer feedback on PR longbridge#2328:
- fn styles(&self, range: Range<usize>, cx: &App)
- -> Vec<(Range<usize>, HighlightStyle)>;
+ fn tokens(&self, range: Range<usize>)
+ -> Vec<(Range<usize>, SharedString)>;
The previous shape returned pre-resolved `HighlightStyle` and took
`&App`, forcing implementors to resolve theme tokens on the render
thread every frame. That bypassed upstream's own tree-sitter path,
which emits scope-name strings resolved through `HighlightTheme::style()`
at `highlighter.rs:719`.
Per Monaco Editor's design (referenced in review), tokenizers emit
named scopes; a separate theme map resolves names to styles. The trait
now constrains the hot path to a `SharedString` read so heavy parsing
can be arranged off-thread (subscribe to `InputEvent::Change`, cache,
hand back ranges on call) -- addressing the 200k-line performance
concern by construction.
Token names use upstream's existing scope vocabulary
(`"keyword"`, `"string"`, `"comment"`, `"variable.special"`, ...);
`.`-namespaced names fall back to their prefix via
`SyntaxColors::style`. Unrecognized names render with the default
style.
Adds a worked example at `crates/story/examples/editor.rs`
(`MarkerHighlighter`): tags `TODO` / `FIXME` / `XXX` / `HACK` /
`NOTE` markers with `keyword.special`, recomputed on
`InputEvent::Change`. A syntect or language-server consumer would
follow the same shape with a different parser inside `refresh()`.
Tests updated to the new method signature; both still verify
install / clear round-trip and tree-sitter composition through
`combine_highlights`.1 parent 08a737e commit 11c4588
4 files changed
Lines changed: 162 additions & 60 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
17 | 20 | | |
18 | 21 | | |
19 | 22 | | |
| |||
66 | 69 | | |
67 | 70 | | |
68 | 71 | | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
69 | 123 | | |
70 | 124 | | |
71 | 125 | | |
| |||
77 | 131 | | |
78 | 132 | | |
79 | 133 | | |
| 134 | + | |
80 | 135 | | |
81 | 136 | | |
82 | 137 | | |
| |||
690 | 745 | | |
691 | 746 | | |
692 | 747 | | |
| 748 | + | |
693 | 749 | | |
694 | 750 | | |
695 | 751 | | |
| |||
711 | 767 | | |
712 | 768 | | |
713 | 769 | | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
714 | 778 | | |
715 | 779 | | |
716 | 780 | | |
| |||
726 | 790 | | |
727 | 791 | | |
728 | 792 | | |
729 | | - | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
730 | 796 | | |
731 | 797 | | |
732 | 798 | | |
| |||
741 | 807 | | |
742 | 808 | | |
743 | 809 | | |
| 810 | + | |
744 | 811 | | |
745 | 812 | | |
746 | 813 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | | - | |
18 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
19 | 33 | | |
20 | 34 | | |
21 | 35 | | |
| |||
26 | 40 | | |
27 | 41 | | |
28 | 42 | | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
33 | 49 | | |
34 | 50 | | |
35 | | - | |
36 | | - | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
37 | 54 | | |
38 | | - | |
| 55 | + | |
| 56 | + | |
39 | 57 | | |
40 | | - | |
41 | | - | |
42 | | - | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
43 | 63 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1317 | 1317 | | |
1318 | 1318 | | |
1319 | 1319 | | |
1320 | | - | |
1321 | | - | |
1322 | | - | |
| 1320 | + | |
| 1321 | + | |
| 1322 | + | |
| 1323 | + | |
1323 | 1324 | | |
1324 | | - | |
| 1325 | + | |
| 1326 | + | |
| 1327 | + | |
| 1328 | + | |
| 1329 | + | |
| 1330 | + | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
1325 | 1337 | | |
1326 | 1338 | | |
1327 | 1339 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
658 | 658 | | |
659 | 659 | | |
660 | 660 | | |
661 | | - | |
662 | | - | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
663 | 664 | | |
664 | 665 | | |
665 | | - | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
666 | 669 | | |
667 | 670 | | |
668 | 671 | | |
| |||
3135 | 3138 | | |
3136 | 3139 | | |
3137 | 3140 | | |
3138 | | - | |
| 3141 | + | |
3139 | 3142 | | |
3140 | 3143 | | |
3141 | 3144 | | |
3142 | | - | |
3143 | | - | |
| 3145 | + | |
| 3146 | + | |
| 3147 | + | |
| 3148 | + | |
3144 | 3149 | | |
3145 | 3150 | | |
3146 | | - | |
3147 | | - | |
3148 | | - | |
3149 | | - | |
3150 | | - | |
3151 | | - | |
3152 | | - | |
3153 | | - | |
3154 | | - | |
3155 | | - | |
3156 | | - | |
3157 | | - | |
3158 | | - | |
3159 | | - | |
3160 | | - | |
3161 | | - | |
3162 | | - | |
3163 | | - | |
| 3151 | + | |
| 3152 | + | |
| 3153 | + | |
3164 | 3154 | | |
3165 | 3155 | | |
3166 | 3156 | | |
| |||
3177 | 3167 | | |
3178 | 3168 | | |
3179 | 3169 | | |
3180 | | - | |
3181 | | - | |
| 3170 | + | |
| 3171 | + | |
3182 | 3172 | | |
3183 | 3173 | | |
3184 | 3174 | | |
3185 | 3175 | | |
3186 | 3176 | | |
3187 | 3177 | | |
3188 | 3178 | | |
3189 | | - | |
3190 | | - | |
| 3179 | + | |
| 3180 | + | |
| 3181 | + | |
3191 | 3182 | | |
3192 | | - | |
3193 | | - | |
| 3183 | + | |
| 3184 | + | |
3194 | 3185 | | |
3195 | 3186 | | |
3196 | 3187 | | |
| |||
3204 | 3195 | | |
3205 | 3196 | | |
3206 | 3197 | | |
3207 | | - | |
| 3198 | + | |
3208 | 3199 | | |
3209 | | - | |
| 3200 | + | |
| 3201 | + | |
| 3202 | + | |
| 3203 | + | |
| 3204 | + | |
| 3205 | + | |
| 3206 | + | |
| 3207 | + | |
3210 | 3208 | | |
3211 | 3209 | | |
3212 | 3210 | | |
| |||
3223 | 3221 | | |
3224 | 3222 | | |
3225 | 3223 | | |
| 3224 | + | |
| 3225 | + | |
| 3226 | + | |
| 3227 | + | |
| 3228 | + | |
| 3229 | + | |
| 3230 | + | |
| 3231 | + | |
| 3232 | + | |
3226 | 3233 | | |
3227 | 3234 | | |
3228 | 3235 | | |
| |||
3245 | 3252 | | |
3246 | 3253 | | |
3247 | 3254 | | |
3248 | | - | |
| 3255 | + | |
3249 | 3256 | | |
3250 | 3257 | | |
3251 | 3258 | | |
3252 | 3259 | | |
3253 | 3260 | | |
3254 | 3261 | | |
3255 | | - | |
3256 | | - | |
3257 | | - | |
3258 | | - | |
3259 | | - | |
3260 | | - | |
| 3262 | + | |
| 3263 | + | |
3261 | 3264 | | |
3262 | 3265 | | |
3263 | 3266 | | |
| |||
0 commit comments