Skip to content

Commit 88b3b0c

Browse files
committed
Add labels to web workers
1 parent 580436f commit 88b3b0c

5 files changed

Lines changed: 19 additions & 9 deletions

File tree

src/vs/base/worker/defaultWorkerFactory.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {logOnceWebWorkerWarning, IWorker, IWorkerCallback, IWorkerFactory} from
1010
import * as dom from 'vs/base/browser/dom';
1111

1212
function defaultGetWorkerUrl(workerId:string, label:string): string {
13-
return require.toUrl('./' + workerId);
13+
return require.toUrl('./' + workerId) + '#' + label;
1414
}
1515
var getWorkerUrl = flags.getCrossOriginWorkerScriptUrl || defaultGetWorkerUrl;
1616

@@ -130,10 +130,12 @@ export class DefaultWorkerFactory implements IWorkerFactory {
130130

131131
private static LAST_WORKER_ID = 0;
132132

133+
private _label: string;
133134
private _fallbackToIframe:boolean;
134135
private _webWorkerFailedBeforeError:any;
135136

136-
constructor(fallbackToIframe:boolean) {
137+
constructor(label:string, fallbackToIframe:boolean) {
138+
this._label = label;
137139
this._fallbackToIframe = fallbackToIframe;
138140
this._webWorkerFailedBeforeError = false;
139141
}
@@ -147,7 +149,7 @@ export class DefaultWorkerFactory implements IWorkerFactory {
147149
}
148150

149151
try {
150-
return new WebWorker(moduleId, workerId, 'service' + workerId, onMessageCallback, (err) => {
152+
return new WebWorker(moduleId, workerId, this._label || 'anonymous' + workerId, onMessageCallback, (err) => {
151153
logOnceWebWorkerWarning(err);
152154
this._webWorkerFailedBeforeError = err;
153155
onErrorCallback(err);
@@ -161,7 +163,7 @@ export class DefaultWorkerFactory implements IWorkerFactory {
161163
if (this._webWorkerFailedBeforeError) {
162164
throw this._webWorkerFailedBeforeError;
163165
}
164-
return new WebWorker(moduleId, workerId, 'service' + workerId, onMessageCallback, (err) => {
166+
return new WebWorker(moduleId, workerId, this._label || 'anonymous' + workerId, onMessageCallback, (err) => {
165167
logOnceWebWorkerWarning(err);
166168
this._webWorkerFailedBeforeError = err;
167169
onErrorCallback(err);

src/vs/editor/common/services/compatWorkerServiceMain.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class MainThreadCompatWorkerService implements ICompatWorkerService {
2727
constructor(
2828
@IModelService modelService: IModelService
2929
) {
30-
this._workerFactory = new DefaultWorkerFactory(true);
30+
this._workerFactory = new DefaultWorkerFactory('compatWorker', true);
3131
this._worker = null;
3232
this._workerCreatedPromise = new TPromise<void>((c, e, p) => {
3333
this._triggerWorkersCreatedPromise = c;

src/vs/editor/common/services/editorWorkerServiceImpl.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class WorkerManager extends Disposable {
106106
public withWorker(): TPromise<EditorWorkerClient> {
107107
this._lastWorkerUsedTime = (new Date()).getTime();
108108
if (!this._editorWorkerClient) {
109-
this._editorWorkerClient = new EditorWorkerClient(this._modelService);
109+
this._editorWorkerClient = new EditorWorkerClient(this._modelService, 'editorWorkerService');
110110
}
111111
return TPromise.as(this._editorWorkerClient);
112112
}
@@ -253,10 +253,10 @@ export class EditorWorkerClient extends Disposable {
253253
private _workerFactory: DefaultWorkerFactory;
254254
private _modelManager: EditorModelManager;
255255

256-
constructor(modelService: IModelService) {
256+
constructor(modelService: IModelService, label:string) {
257257
super();
258258
this._modelService = modelService;
259-
this._workerFactory = new DefaultWorkerFactory(/*do not use iframe*/false);
259+
this._workerFactory = new DefaultWorkerFactory(label, /*do not use iframe*/false);
260260
this._worker = null;
261261
this._modelManager = null;
262262
}

src/vs/editor/common/services/webWorker.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ export interface IWebWorkerOptions {
4747
* The data to send over when calling create on the module.
4848
*/
4949
createData?: any;
50+
/**
51+
* A label to be used to identify the web worker for debugging purposes.
52+
*/
53+
label?: string;
5054
}
5155

5256
class MonacoWebWorkerImpl<T> extends EditorWorkerClient implements MonacoWebWorker<T> {
@@ -56,7 +60,7 @@ class MonacoWebWorkerImpl<T> extends EditorWorkerClient implements MonacoWebWork
5660
private _foreignProxy: TPromise<T>;
5761

5862
constructor(modelService: IModelService, opts:IWebWorkerOptions) {
59-
super(modelService);
63+
super(modelService, opts.label);
6064
this._foreignModuleId = opts.moduleId;
6165
this._foreignModuleCreateData = opts.createData || null;
6266
this._foreignProxy = null;

src/vs/monaco.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,10 @@ declare module monaco.editor {
858858
* The data to send over when calling create on the module.
859859
*/
860860
createData?: any;
861+
/**
862+
* A label to be used to identify the web worker for debugging purposes.
863+
*/
864+
label?: string;
861865
}
862866

863867
/**

0 commit comments

Comments
 (0)