@@ -16,6 +16,7 @@ if (ipcMsgListener) {
16
16
* that could be expected to exist in the unpacked version of
17
17
* VS Code. The list may grow in the future.
18
18
*/
19
+ // tslint:disable-next-line:no-any
19
20
const requireNativeModules = ( mod : any ) : void => {
20
21
// tslint:disable-next-line:no-any
21
22
const nativeModules : ReadonlyArray < { id : string , module : any } > = [
@@ -32,13 +33,55 @@ const requireNativeModules = (mod: any): void => {
32
33
if ( id . slice ( 0 , 3 ) === "/./" ) {
33
34
id = id . slice ( 3 ) ;
34
35
}
36
+ // tslint:disable-next-line:no-any
35
37
const requireNativeModule = ( id : string ) : any => {
36
38
for ( let i = 0 ; i < nativeModules . length ; i ++ ) {
37
39
if ( id . slice ( - 1 * ( nativeModules [ i ] . id . length + 1 ) ) !== `/${ nativeModules [ i ] . id } ` ) {
38
40
continue ;
39
41
}
40
42
41
- return nativeModules [ i ] . module ;
43
+ const nativeModule = nativeModules [ i ] ;
44
+ if ( nativeModule . id === "vscode-textmate" ) {
45
+ /**
46
+ * Due to the way vscode-textmate requires modules,
47
+ * oniguruma is not bundled within it.
48
+ *
49
+ * We have to override the native getOnigLib func much
50
+ * like we do in the `web` bundle to target onigasm.
51
+ */
52
+ const vst = nativeModule . module as typeof import ( "../../../../lib/vscode/node_modules/vscode-textmate" ) ;
53
+ vst . Registry = class Registry extends vst . Registry {
54
+ // tslint:disable-next-line:no-any
55
+ public constructor ( opts : any ) {
56
+ super ( {
57
+ ...opts ,
58
+ // tslint:disable-next-line:no-any
59
+ getOnigLib : ( ) : Promise < any > => {
60
+ // tslint:disable-next-line:no-any
61
+ return new Promise < any > ( ( res ) : void => {
62
+ const oniguruma = require ( "../../../../lib/vscode/node_modules/oniguruma" ) ;
63
+
64
+ res ( {
65
+ // tslint:disable-next-line:only-arrow-functions no-any
66
+ createOnigScanner : function ( patterns : any ) : any {
67
+ return new oniguruma . OnigScanner ( patterns ) ;
68
+ } ,
69
+ // tslint:disable-next-line:only-arrow-functions no-any
70
+ createOnigString : function ( s : any ) : any {
71
+ const string = new oniguruma . OnigString ( s ) ;
72
+ string . content = s ;
73
+
74
+ return string ;
75
+ } ,
76
+ } ) ;
77
+ } ) ;
78
+ } ,
79
+ } ) ;
80
+ }
81
+ } ;
82
+ }
83
+
84
+ return nativeModule . module ;
42
85
}
43
86
throw new Error ( `Module '${ id } ' undefined. If you need this native module, file an issue on GitHub.` ) ;
44
87
} ;
0 commit comments