Skip to content

Commit 6c8542b

Browse files
committed
Fix vscode-textmate oniguruma
1 parent fbc8c05 commit 6c8542b

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

packages/server/src/vscode/bootstrapFork.ts

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ if (ipcMsgListener) {
1616
* that could be expected to exist in the unpacked version of
1717
* VS Code. The list may grow in the future.
1818
*/
19+
// tslint:disable-next-line:no-any
1920
const requireNativeModules = (mod: any): void => {
2021
// tslint:disable-next-line:no-any
2122
const nativeModules: ReadonlyArray<{ id: string, module: any }> = [
@@ -32,13 +33,55 @@ const requireNativeModules = (mod: any): void => {
3233
if (id.slice(0, 3) === "/./") {
3334
id = id.slice(3);
3435
}
36+
// tslint:disable-next-line:no-any
3537
const requireNativeModule = (id: string): any => {
3638
for (let i = 0; i < nativeModules.length; i++) {
3739
if (id.slice(-1 * (nativeModules[i].id.length + 1)) !== `/${nativeModules[i].id}`) {
3840
continue;
3941
}
4042

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;
4285
}
4386
throw new Error(`Module '${id}' undefined. If you need this native module, file an issue on GitHub.`);
4487
};

0 commit comments

Comments
 (0)