11import * as vscode from 'vscode' ;
2+ import { createOnigScanner , createOnigString , FindOption } from 'vscode-oniguruma' ;
23import * as vscodeTextmate from "../textmate/main" ;
34// import * as vscodeTextmate from 'vscode-textmate';
45import { getScopeName , grammarLanguages , tokenizeFile } from "../TextMate" ;
@@ -7,7 +8,6 @@ import { stringify } from "../extension";
78import { IRawCaptures , IRawRule } from "../textmate/rawGrammar" ;
89import { getTrees , queryNode , toRange } from "../TreeSitter" ;
910import { getScopes , getSubScope } from "../themeScopeColors" ;
10- import { createOnigScanner , createOnigString , FindOption } from 'vscode-oniguruma' ;
1111import { ruleIdToNumber } from "../textmate/rule" ;
1212// import { ITextEditorOptions, EditorOpenSource, TextEditorSelectionSource } from "../extensions";
1313
@@ -680,20 +680,23 @@ const TreeDataProviderCall: vscode.TreeDataProvider<element> = {
680680 // vscode.window.showInformationMessage(`cachedRule ${JSON.stringify(ruleId, stringify)}\n${JSON.stringify(cachedRule, stringify)}`);
681681 const regexes : string [ ] = [ ] ;
682682 // vscode.window.showInformationMessage(`_cachedCompiledPatterns\n${JSON.stringify(cachedRule._cachedCompiledPatterns!._items, stringify)}`);
683- for ( const regexSource of cachedRule . _cachedCompiledPatterns ! . _items ) {
683+ const _items = cachedRule . _cachedCompiledPatterns ! . _items ;
684+ for ( const regexSource of _items ) {
684685 // https://github.com/microsoft/vscode-textmate/issues/126
685686 // https://github.com/microsoft/vscode/issues/119915
686687 // https://github.com/kkos/oniguruma/issues/198
687- if ( ! allowAnchorA ) {
688- regexSource . source . replaceAll ( '\\A' , '\\\uFFFF' ) ;
689- }
690- if ( ! allowAnchorG ) {
691- regexSource . source . replaceAll ( '\\G' , '\\\uFFFF' ) ;
688+ if ( typeof regexSource . source === 'string' ) {
689+ if ( ! allowAnchorA ) {
690+ regexSource . source . replaceAll ( '\\A' , '\\\uFFFF' ) ;
691+ }
692+ if ( ! allowAnchorG ) {
693+ regexSource . source . replaceAll ( '\\G' , '\\\uFFFF' ) ;
694+ }
692695 }
693696 // if (!allowAnchorZ) { // https://github.com/microsoft/vscode-textmate/blob/f03a6a8790af81372d0e81facae75554ec5e97ef/src/rule.ts#L603-L606
694697 // regexSource.source.replaceAll('\\z', '$(?!\\n)(?<!\\n)');
695698 // }
696- regexes . push ( regexSource . source ) ;
699+ regexes . push ( regexSource . source ! ) ;
697700 }
698701 const scanner = createOnigScanner ( regexes ) ;
699702
@@ -732,9 +735,10 @@ const TreeDataProviderCall: vscode.TreeDataProvider<element> = {
732735 scanner . dispose ( ) ;
733736
734737 // const regex = cachedRule._match?.source ?? (ruleId < 0 ? cachedRule._while?.source ?? cachedRule._end?.source : cachedRule._begin?.source);
738+ const matchedSource = onigMatch ? _items [ onigMatch . index ] . source : undefined ;
735739 const item = new vscode . TreeItem (
736740 // regex.substring(0, 50),
737- onigMatch ? cachedRule . _cachedCompiledPatterns ! . _items [ onigMatch . index ] . source . substring ( 0 , 50 ) : '<EOL>' ,
741+ onigMatch ? typeof matchedSource === 'string' ? matchedSource . substring ( 0 , 50 ) : matchedSource ! : '<EOL>' ,
738742 vscode . TreeItemCollapsibleState . Expanded ,
739743 ) ;
740744
@@ -766,16 +770,18 @@ const TreeDataProviderCall: vscode.TreeDataProvider<element> = {
766770 // https://github.com/microsoft/vscode-textmate/issues/126
767771 // https://github.com/microsoft/vscode/issues/119915
768772 // https://github.com/kkos/oniguruma/issues/198
769- if ( ! allowAnchorA ) {
770- regexSource . replaceAll ( '\\A' , '\\\uFFFF' ) ;
771- }
772- if ( ! allowAnchorG ) {
773- regexSource . replaceAll ( '\\G' , '\\\uFFFF' ) ;
773+ if ( typeof regexSource === 'string' ) {
774+ if ( ! allowAnchorA ) {
775+ regexSource . replaceAll ( '\\A' , '\\\uFFFF' ) ;
776+ }
777+ if ( ! allowAnchorG ) {
778+ regexSource . replaceAll ( '\\G' , '\\\uFFFF' ) ;
779+ }
774780 }
775781 // if (!allowAnchorZ) { // https://github.com/microsoft/vscode-textmate/blob/f03a6a8790af81372d0e81facae75554ec5e97ef/src/rule.ts#L603-L606
776782 // regexSource.source.replaceAll('\\z', '$(?!\\n)(?<!\\n)');
777783 // }
778- const scanner = createOnigScanner ( [ regexSource ] ) ;
784+ const scanner = createOnigScanner ( [ regexSource ! ] ) ;
779785
780786 const options : FindOption =
781787 ( allowAnchorA ? FindOption . None : FindOption . NotBeginString ) |
@@ -804,10 +810,10 @@ const TreeDataProviderCall: vscode.TreeDataProvider<element> = {
804810 const timeFixed = time . toFixed ( 3 ) ;
805811 scanner . dispose ( ) ;
806812
807- const label = regexSource . substring ( 0 , 50 ) ;
813+ const label = typeof regexSource === 'string' ? regexSource . substring ( 0 , 50 ) : regexSource ;
808814 const treeLabel : vscode . TreeItemLabel = {
809- label : label ,
810- highlights : onigMatch ? [ [ 0 , label . length ] ] : undefined ,
815+ label : label ! ,
816+ highlights : onigMatch ? [ [ 0 , label ? .length ?? 1 ] ] : undefined ,
811817 } ;
812818 const item = new vscode . TreeItem (
813819 treeLabel ,
@@ -817,7 +823,7 @@ const TreeDataProviderCall: vscode.TreeDataProvider<element> = {
817823 const ruleId = element . itemRule ! . ruleId ;
818824 const duplicateId = element . duplicateId ;
819825 item . id = `${ ruleId } ${ type == 'regex' ? '' : '_' } ${ duplicateId ? `_${ duplicateId } ` : '' } ` ;
820- item . description = `${ regexSource . length > 50 ? '...' : '' } ${ timeFixed } ms${ time >= 1 ? ' ⚠️' : '' } ${ duplicateId ? '‼️' : '' } ` ;
826+ item . description = `${ typeof regexSource === 'string' && regexSource . length > 50 ? '...' : '' } ${ timeFixed } ms${ time >= 1 ? ' ⚠️' : '' } ${ duplicateId ? '‼️' : '' } ` ;
821827 item . tooltip = `RuleId: ${ ruleId } \n${ onigMatch ?. captureIndices [ 0 ] . start } - ${ onigMatch ?. captureIndices [ 0 ] . end } ${ duplicateId ? `\nDuplicate Rule: ${ duplicateId } x` : '' } ` ;
822828 item . iconPath = new vscode . ThemeIcon ( 'regex' ) ;
823829
0 commit comments