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

Add customWorkerFactory to customize tsworker directly #4035

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 2 additions & 0 deletions src/language/typescript/monaco.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import type * as mode from './tsMode';
import { typescriptVersion as tsversion } from './lib/typescriptServicesMetadata'; // do not import the whole typescriptServices here
import { languages, Emitter, IEvent, IDisposable, Uri } from '../../fillers/monaco-editor-core';
import { CustomTSWebWorkerFactory } from './tsWorker';

//#region enums copied from typescript to prevent loading the entire typescriptServices ---

Expand Down Expand Up @@ -166,6 +167,7 @@ export interface DiagnosticsOptions {
export interface WorkerOptions {
/** A full HTTP path to a JavaScript file which adds a function `customTSWorkerFactory` to the self inside a web-worker */
customWorkerPath?: string;
customWorkerFactory?: CustomTSWebWorkerFactory;
}

interface InlayHintsOptions {
Expand Down
5 changes: 4 additions & 1 deletion src/language/typescript/tsWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ export interface ICreateData {
compilerOptions: ts.CompilerOptions;
extraLibs: IExtraLibs;
customWorkerPath?: string;
customWorkerFactory?: CustomTSWebWorkerFactory;
inlayHintsOptions?: ts.UserPreferences;
}

Expand Down Expand Up @@ -497,9 +498,11 @@ export function create(ctx: worker.IWorkerContext, createData: ICreateData): Typ
);
}

TSWorkerClass = workerFactoryFunc(TypeScriptWorker, ts, libFileMap);
TSWorkerClass = workerFactoryFunc(TSWorkerClass, ts, libFileMap);
}
}
if (createData.customWorkerFactory)
TSWorkerClass = createData.customWorkerFactory(TSWorkerClass, ts, libFileMap);

return new TSWorkerClass(ctx, createData);
}
Expand Down
1 change: 1 addition & 0 deletions src/language/typescript/workerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export class WorkerManager {
compilerOptions: this._defaults.getCompilerOptions(),
extraLibs: this._defaults.getExtraLibs(),
customWorkerPath: this._defaults.workerOptions.customWorkerPath,
customWorkerFactory: this._defaults.workerOptions.customWorkerFactory,
inlayHintsOptions: this._defaults.inlayHintsOptions
}
});
Expand Down