@@ -125,28 +125,6 @@ function _tokenizeWithTheme(
125
125
let actual : ThemedToken [ ] = [ ]
126
126
const final : ThemedToken [ ] [ ] = [ ]
127
127
128
- const themeSettingsSelectors : ThemeSettingsSelectors [ ] = [ ]
129
- if ( options . includeExplanation ) {
130
- for ( const setting of theme . settings ) {
131
- let selectors : string [ ]
132
- switch ( typeof setting . scope ) {
133
- case 'string' :
134
- selectors = setting . scope . split ( / , / ) . map ( scope => scope . trim ( ) )
135
- break
136
- case 'object' :
137
- selectors = setting . scope
138
- break
139
- default :
140
- continue
141
- }
142
-
143
- themeSettingsSelectors . push ( {
144
- settings : setting ,
145
- selectors : selectors . map ( selector => selector . split ( / / ) ) ,
146
- } )
147
- }
148
- }
149
-
150
128
for ( let i = 0 , len = lines . length ; i < len ; i ++ ) {
151
129
const [ line , lineOffset ] = lines [ i ]
152
130
if ( line === '' ) {
@@ -201,6 +179,29 @@ function _tokenizeWithTheme(
201
179
}
202
180
203
181
if ( options . includeExplanation ) {
182
+ const themeSettingsSelectors : ThemeSettingsSelectors [ ] = [ ]
183
+
184
+ if ( options . includeExplanation !== 'scopeName' ) {
185
+ for ( const setting of theme . settings ) {
186
+ let selectors : string [ ]
187
+ switch ( typeof setting . scope ) {
188
+ case 'string' :
189
+ selectors = setting . scope . split ( / , / ) . map ( scope => scope . trim ( ) )
190
+ break
191
+ case 'object' :
192
+ selectors = setting . scope
193
+ break
194
+ default :
195
+ continue
196
+ }
197
+
198
+ themeSettingsSelectors . push ( {
199
+ settings : setting ,
200
+ selectors : selectors . map ( selector => selector . split ( / / ) ) ,
201
+ } )
202
+ }
203
+ }
204
+
204
205
token . explanation = [ ]
205
206
let offset = 0
206
207
while ( startIndex + offset < nextStartIndex ) {
@@ -213,7 +214,14 @@ function _tokenizeWithTheme(
213
214
offset += tokenWithScopesText . length
214
215
token . explanation . push ( {
215
216
content : tokenWithScopesText ,
216
- scopes : explainThemeScopes ( themeSettingsSelectors , tokenWithScopes . scopes ) ,
217
+ scopes : options . includeExplanation === 'scopeName'
218
+ ? explainThemeScopesNameOnly (
219
+ tokenWithScopes . scopes ,
220
+ )
221
+ : explainThemeScopesFull (
222
+ themeSettingsSelectors ,
223
+ tokenWithScopes . scopes ,
224
+ ) ,
217
225
} )
218
226
219
227
tokensWithScopesIndex ! += 1
@@ -233,17 +241,22 @@ function _tokenizeWithTheme(
233
241
}
234
242
}
235
243
236
- function explainThemeScopes (
244
+ function explainThemeScopesNameOnly (
245
+ scopes : string [ ] ,
246
+ ) : ThemedTokenScopeExplanation [ ] {
247
+ return scopes . map ( scope => ( { scopeName : scope } ) )
248
+ }
249
+
250
+ function explainThemeScopesFull (
237
251
themeSelectors : ThemeSettingsSelectors [ ] ,
238
252
scopes : string [ ] ,
239
253
) : ThemedTokenScopeExplanation [ ] {
240
254
const result : ThemedTokenScopeExplanation [ ] = [ ]
241
255
for ( let i = 0 , len = scopes . length ; i < len ; i ++ ) {
242
- const parentScopes = scopes . slice ( 0 , i )
243
256
const scope = scopes [ i ]
244
257
result [ i ] = {
245
258
scopeName : scope ,
246
- themeMatches : explainThemeScope ( themeSelectors , scope , parentScopes ) ,
259
+ themeMatches : explainThemeScope ( themeSelectors , scope , scopes . slice ( 0 , i ) ) ,
247
260
}
248
261
}
249
262
return result
0 commit comments