Skip to content

Commit

Permalink
feat: expose textmate worker
Browse files Browse the repository at this point in the history
  • Loading branch information
Loïc Mangeonjean committed Jun 5, 2023
1 parent ae68743 commit 0446e5f
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 5 deletions.
7 changes: 4 additions & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
"mp3": "always",
"json": "always",
"contribution": "always", // Hack for vscode .contribution.js files
"protocol": "always", // Hack for vscode .protocol.js files,
"net": "always", // Hack for vscode .net.js files,
"impl": "always" // Hack for vscode .impl.js files
"protocol": "always", // Hack for vscode .protocol.js files
"net": "always", // Hack for vscode .net.js files
"impl": "always", // Hack for vscode .impl.js files
"worker": "always"
}
]
},
Expand Down
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@
"types": "./dist/service-override/quickaccess.d.ts",
"default": "./dist/service-override/quickaccess.js"
},
"./workers/textMate.worker": {
"types": "./dist/workers/textMate.worker.d.ts",
"default": "./dist/workers/textMate.worker.js"
},
"./monaco": {
"types": "./dist/monaco.d.ts",
"default": "./dist/monaco.js"
Expand Down Expand Up @@ -164,6 +168,9 @@
"service-override/quickaccess": [
"./dist/service-override/quickaccess.d.ts"
],
"workers/textMate.worker": [
"./dist/workers/textMate.worker.d.ts"
],
"monaco": [
"./dist/monaco.d.ts"
],
Expand Down
3 changes: 2 additions & 1 deletion rollup/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,8 @@ const input = {
'service-override/debug': './src/service-override/debug.ts',
'service-override/preferences': './src/service-override/preferences.ts',
'service-override/views': './src/service-override/views.ts',
'service-override/quickaccess': './src/service-override/quickaccess.ts'
'service-override/quickaccess': './src/service-override/quickaccess.ts',
'workers/textMate.worker': './src/workers/textMate.worker.ts',
monaco: './src/monaco.ts',
...Object.fromEntries(
fs.readdirSync(DEFAULT_EXTENSIONS_PATH, { withFileTypes: true })
Expand Down
1 change: 1 addition & 0 deletions rollup/rollup.types.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export default rollup.defineConfig({
'./dist/types/src/service-override/preferences.d.ts',
'./dist/types/src/service-override/views.d.ts',
'./dist/types/src/service-override/quickaccess.d.ts',
'./dist/types/src/workers/textMate.worker.d.ts',
'./dist/types/src/monaco.d.ts',
'./dist/types/src/rollup-vsix-plugin.d.ts',
'./dist/types/src/rollup-extension-directory-plugin.d.ts'
Expand Down
16 changes: 16 additions & 0 deletions scripts/vscode.patch
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,19 @@ index 1111dabcbcd..08aa5052ee6 100644
}

isVisible(): boolean {
diff --git a/src/vs/workbench/services/textMate/browser/worker/textMate.worker.ts b/src/vs/workbench/services/textMate/browser/worker/textMate.worker.ts
index 67484e6ef40..636b27931eb 100644
--- a/src/vs/workbench/services/textMate/browser/worker/textMate.worker.ts
+++ b/src/vs/workbench/services/textMate/browser/worker/textMate.worker.ts
@@ -56,9 +56,8 @@ export class TextMateTokenizationWorker {
}

private async _loadTMGrammarFactory(grammarDefinitions: IValidGrammarDefinition[]): Promise<TMGrammarFactory> {
- const uri = this.createData.textmateMainUri;
- const vscodeTextmate = await import(uri);
- const vscodeOniguruma = await import(this.createData.onigurumaMainUri);
+ const vscodeTextmate = await import('vscode-textmate');
+ const vscodeOniguruma = await import('vscode-oniguruma');
const response = await fetch(this.createData.onigurumaWASMUri);

// Using the response directly only works if the server sets the MIME type 'application/wasm'.
3 changes: 2 additions & 1 deletion src/service-override/textmate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import getFileServiceOverride from './files'
import { registerServiceInitializeParticipant } from '../services'
import { registerAssets } from '../assets'
registerAssets({
'vscode-oniguruma/../onig.wasm': _onigWasm
'vscode-oniguruma/../onig.wasm': _onigWasm, // Path used inside service
'vs/../../node_modules/vscode-oniguruma/release/onig.wasm': _onigWasm // Path used inside worker
})

registerServiceInitializeParticipant(async (accessor) => {
Expand Down
6 changes: 6 additions & 0 deletions src/workers/textMate.worker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { IWorkerContext } from 'vs/editor/common/services/editorSimpleWorker'
import { ICreateData, TextMateTokenizationWorker } from 'vs/workbench/services/textMate/browser/worker/textMate.worker'
import { TextMateWorkerHost } from 'vs/workbench/services/textMate/browser/workerHost/textMateWorkerHost'
import { initialize } from 'vs/editor/editor.worker'

initialize((ctx: IWorkerContext<TextMateWorkerHost>, createData: ICreateData) => new TextMateTokenizationWorker(ctx, createData))
1 change: 1 addition & 0 deletions tsconfig.types.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"src/service-override/preferences.ts",
"src/service-override/views.ts",
"src/service-override/quickaccess.ts",
"src/workers/textMate.worker.ts",
"src/monaco.ts",
"src/rollup-vsix-plugin.ts",
"src/rollup-extension-directory-plugin.ts"
Expand Down

0 comments on commit 0446e5f

Please sign in to comment.