Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web: Load onigasm lazy #80642

Merged
merged 2 commits into from
Sep 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/vs/code/browser/workbench/workbench.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@

<!-- Prefetch to avoid waterfall -->
<link rel="prefetch" href="./static/node_modules/semver-umd/lib/semver-umd.js">
<link rel="prefetch" href="./static/node_modules/onigasm-umd/release/main.js"> <!-- TODO@ben TODO@alex: should be lazy -->
<link rel="prefetch" href="./static/node_modules/@microsoft/applicationinsights-web/dist/applicationinsights-web.js">
</head>

Expand Down
17 changes: 10 additions & 7 deletions src/vs/workbench/services/textMate/browser/textMateService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
import { ITextMateService } from 'vs/workbench/services/textMate/common/textMateService';
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { AbstractTextMateService } from 'vs/workbench/services/textMate/browser/abstractTextMateService';
import * as vscodeTextmate from 'vscode-textmate';
import * as onigasm from 'onigasm-umd';
import { IOnigLib } from 'vscode-textmate';
import { IModeService } from 'vs/editor/common/services/modeService';
import { IFileService } from 'vs/platform/files/common/files';
import { ILogService } from 'vs/platform/log/common/log';
Expand All @@ -34,21 +33,25 @@ export class TextMateService extends AbstractTextMateService {
return import('vscode-textmate');
}

protected _loadOnigLib(): Promise<vscodeTextmate.IOnigLib> | undefined {
protected _loadOnigLib(): Promise<IOnigLib> | undefined {
return loadOnigasm();
}
}

let onigasmPromise: Promise<vscodeTextmate.IOnigLib> | null = null;
async function loadOnigasm(): Promise<vscodeTextmate.IOnigLib> {
let onigasmPromise: Promise<IOnigLib> | null = null;
async function loadOnigasm(): Promise<IOnigLib> {
if (!onigasmPromise) {
onigasmPromise = doLoadOnigasm();
}
return onigasmPromise;
}

async function doLoadOnigasm(): Promise<vscodeTextmate.IOnigLib> {
const wasmBytes = await loadOnigasmWASM();
async function doLoadOnigasm(): Promise<IOnigLib> {
const [wasmBytes, onigasm] = await Promise.all([
loadOnigasmWASM(),
import('onigasm-umd')
]);

await onigasm.loadWASM(wasmBytes);
return {
createOnigScanner(patterns: string[]) { return new onigasm.OnigScanner(patterns); },
Expand Down