@@ -124,6 +124,16 @@ export function generateScopes(text: string, parsedFileName: path.ParsedPath) {
124124 ) ) ;
125125}
126126
127+ function validateTokenScopeExtension ( grammar : Grammar , token : vt . IToken ) {
128+ return ! token . scopes . some ( scope => ! isValidScopeExtension ( grammar , scope ) ) ;
129+ }
130+
131+ function isValidScopeExtension ( grammar : Grammar , scope : string ) {
132+ return scope . endsWith ( grammar . kind === GrammarKind . ts ? ".ts" : ".tsx" ) ||
133+ scope . endsWith ( ".jsdoc" ) ||
134+ scope . endsWith ( ".regexp" ) ;
135+ }
136+
127137function generateScopesWorker ( mainGrammar : Grammar , otherGrammar : Grammar | undefined , oriLines : string [ ] ) : string {
128138 let cleanLines : string [ ] = [ ] ;
129139 let baselineLines : string [ ] = [ ] ;
@@ -140,15 +150,16 @@ function generateScopesWorker(mainGrammar: Grammar, otherGrammar: Grammar | unde
140150 otherBaselines . push ( ">" + line ) ;
141151
142152 for ( let token of mainLineTokens ) {
143- writeTokenLine ( token , "" , "" , baselineLines ) ;
153+ writeTokenLine ( mainGrammar , token , baselineLines ) ;
144154 }
145155
146156 if ( otherGrammar ) {
147157 const otherLineTokens = tokenizeLine ( otherGrammar , line ) ;
148- if ( hasDiff ( mainLineTokens , otherLineTokens , hasDiffLineToken ) ) {
158+ if ( otherLineTokens . some ( token => ! validateTokenScopeExtension ( otherGrammar , token ) ) ||
159+ hasDiff ( mainLineTokens , otherLineTokens , hasDiffLineToken ) ) {
149160 foundDiff = true ;
150161 for ( let token of otherLineTokens ) {
151- writeTokenLine ( token , "" , "" , otherBaselines ) ;
162+ writeTokenLine ( otherGrammar , token , otherBaselines ) ;
152163 }
153164 }
154165 }
@@ -158,7 +169,7 @@ function generateScopesWorker(mainGrammar: Grammar, otherGrammar: Grammar | unde
158169 return getInputFile ( cleanLines ) + getBaseline ( mainGrammar , baselineLines ) + otherDiffBaseline ;
159170}
160171
161- function writeTokenLine ( token : vt . IToken , preTextForToken : string , postTextForToken : string , outputLines : string [ ] ) {
172+ function writeTokenLine ( grammar : Grammar , token : vt . IToken , outputLines : string [ ] ) {
162173 let startingSpaces = " " ;
163174 for ( let j = 0 ; j < token . startIndex ; j ++ ) {
164175 startingSpaces += " " ;
@@ -169,5 +180,5 @@ function writeTokenLine(token: vt.IToken, preTextForToken: string, postTextForTo
169180 locatingString += "^" ;
170181 }
171182 outputLines . push ( startingSpaces + locatingString ) ;
172- outputLines . push ( startingSpaces + preTextForToken + token . scopes . join ( ' ' ) + postTextForToken ) ;
183+ outputLines . push ( ` ${ startingSpaces } ${ token . scopes . join ( ' ' ) } ${ validateTokenScopeExtension ( grammar , token ) ? "" : " INCORRECT_SCOPE_EXTENSION" } ` ) ;
173184}
0 commit comments