Use different workers for get completion items and get error markers.
This commit is contained in:
parent
819cda6f9b
commit
3abe956573
|
@ -18,22 +18,33 @@ var LanguageServiceFacade = /** @class */ (function () {
|
||||||
}, LanguageServiceFacade.timeout);
|
}, LanguageServiceFacade.timeout);
|
||||||
});
|
});
|
||||||
var result = LanguageServiceFacade.GetParseResult(str, parseReason);
|
var result = LanguageServiceFacade.GetParseResult(str, parseReason);
|
||||||
|
var workingWorker = (parseReason === ParseReason.GetCompletionWords ? LanguageServiceFacade.workingWorkerForCompletion : LanguageServiceFacade.workingWorkerForGettingError);
|
||||||
return Q.race([timeExceeded, result]).then(function (words) {
|
return Q.race([timeExceeded, result]).then(function (words) {
|
||||||
LanguageServiceFacade.workingWorker.terminate();
|
workingWorker.terminate();
|
||||||
return words;
|
return words;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
LanguageServiceFacade.timeout = 2000;
|
LanguageServiceFacade.timeout = 2000;
|
||||||
LanguageServiceFacade.workingWorker = null;
|
LanguageServiceFacade.workingWorkerForCompletion = null;
|
||||||
|
LanguageServiceFacade.workingWorkerForGettingError = null;
|
||||||
LanguageServiceFacade.GetParseResult = function (str, parseReason) {
|
LanguageServiceFacade.GetParseResult = function (str, parseReason) {
|
||||||
return Q.Promise(function (resolve) {
|
return Q.Promise(function (resolve) {
|
||||||
if (LanguageServiceFacade.workingWorker != null) {
|
var workingWorker = (parseReason === ParseReason.GetCompletionWords ? LanguageServiceFacade.workingWorkerForCompletion : LanguageServiceFacade.workingWorkerForGettingError);
|
||||||
LanguageServiceFacade.workingWorker.terminate();
|
// terminate the expired worker.
|
||||||
|
if (workingWorker != null) {
|
||||||
|
workingWorker.terminate();
|
||||||
}
|
}
|
||||||
var currentUrlWithoutQueryParamsAndHashRoute = window.location.protocol + "//" + window.location.host + window.location.pathname;
|
var currentUrlWithoutQueryParamsAndHashRoute = window.location.protocol + "//" + window.location.host + window.location.pathname;
|
||||||
var url = currentUrlWithoutQueryParamsAndHashRoute.replace(/\/[^\/]*$/, '/node_modules/@azure/cosmos-language-service/dist/worker/dist/LanguageServiceWorker.js');
|
var url = currentUrlWithoutQueryParamsAndHashRoute.replace(/\/[^\/]*$/, '/node_modules/@azure/cosmos-language-service/dist/worker/dist/LanguageServiceWorker.js');
|
||||||
LanguageServiceFacade.workingWorker = new Worker(url);
|
if (parseReason === ParseReason.GetCompletionWords) {
|
||||||
LanguageServiceFacade.workingWorker.onmessage = function (ev) {
|
LanguageServiceFacade.workingWorkerForCompletion = new Worker(url);
|
||||||
|
workingWorker = LanguageServiceFacade.workingWorkerForCompletion;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LanguageServiceFacade.workingWorkerForGettingError = new Worker(url);
|
||||||
|
workingWorker = LanguageServiceFacade.workingWorkerForGettingError;
|
||||||
|
}
|
||||||
|
workingWorker.onmessage = function (ev) {
|
||||||
var processedResults = [];
|
var processedResults = [];
|
||||||
var parseResults = ev.data;
|
var parseResults = ev.data;
|
||||||
if (parseReason === ParseReason.GetCompletionWords) {
|
if (parseReason === ParseReason.GetCompletionWords) {
|
||||||
|
@ -68,7 +79,7 @@ var LanguageServiceFacade = /** @class */ (function () {
|
||||||
code: str,
|
code: str,
|
||||||
reason: parseReason
|
reason: parseReason
|
||||||
};
|
};
|
||||||
LanguageServiceFacade.workingWorker.postMessage(source);
|
workingWorker.postMessage(source);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
return LanguageServiceFacade;
|
return LanguageServiceFacade;
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
{"version":3,"file":"LanguageServiceFacade.js","sourceRoot":"","sources":["../../src/facade/LanguageServiceFacade.ts"],"names":[],"mappings":";;AAAA,qBAAuB;AACvB,+CAAgE;AAEhE,IAAY,WAGX;AAHD,WAAY,WAAW;IACnB,yEAAsB,CAAA;IACtB,uDAAa,CAAA;AACjB,CAAC,EAHW,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAGtB;AAED;IAAA;IAqEA,CAAC;IAhEiB,mDAA6B,GAA3C,U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W,GAA8B,EAAC,WAAW,EAAG,gBAAgB,EAAC,CAAC;oBAC9E,OAAO,CAAC,WAAW,CAAC,CAAC;iBACxB;qBAAM,IAAI,WAAW,KAAK,WAAW,CAAC,SAAS,EAAE;oBAC9C,YAAY,CAAC,OAAO,CAAC,UAAC,GAAQ;wBAC1B,IAAM,IAAI,GAAuB;4BAC7B,QAAQ,EAAE,8BAAc,CAAC,KAAK;4BAC9B,OAAO,EAAE,GAAG,CAAC,OAAO;4BACpB,eAAe,EAAE,GAAG,CAAC,IAAI;4BACzB,WAAW,EAAE,GAAG,CAAC,MAAM;4BACvB,aAAa,EAAE,GAAG,CAAC,IAAI;4BACvB,SAAS,EAAE,GAAG,CAAC,MAAM;yBACxB,CAAC;wBACF,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;oBAChC,CAAC,CAAC,CAAC;oBACH,OAAO,CAAC,gBAAgB,CAAC,CAAC;iBAC7B;YACL,CAAC,CAAA;YAED,IAAM,MAAM,GAAG;gBACX,IAAI,EAAG,GAAG;gBACV,MAAM,EAAG,WAAW;aACvB,CAAC;YACF,aAAa,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QACtC,CAAC,CAAC,CAAC;IACP,CAAC,CAAA;IACL,4BAAC;CAAA,AAlFD,IAkFC;AAlFY,sDAAqB"}
|
|
@ -9,7 +9,8 @@ export enum ParseReason {
|
||||||
export class LanguageServiceFacade {
|
export class LanguageServiceFacade {
|
||||||
private static readonly timeout : number = 2000;
|
private static readonly timeout : number = 2000;
|
||||||
|
|
||||||
private static workingWorker : Worker = null;
|
private static workingWorkerForCompletion : Worker = null;
|
||||||
|
private static workingWorkerForGettingError : Worker = null;
|
||||||
|
|
||||||
public static GetLanguageServiceParseResult(str : string, parseReason : ParseReason) : Q.Promise<any> {
|
public static GetLanguageServiceParseResult(str : string, parseReason : ParseReason) : Q.Promise<any> {
|
||||||
const timeExceeded = Q.Promise<any>((resolve : any, reject : any) => {
|
const timeExceeded = Q.Promise<any>((resolve : any, reject : any) => {
|
||||||
|
@ -20,23 +21,35 @@ export class LanguageServiceFacade {
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = LanguageServiceFacade.GetParseResult(str, parseReason);
|
const result = LanguageServiceFacade.GetParseResult(str, parseReason);
|
||||||
|
let workingWorker = (parseReason === ParseReason.GetCompletionWords ? LanguageServiceFacade.workingWorkerForCompletion : LanguageServiceFacade.workingWorkerForGettingError);
|
||||||
return Q.race([timeExceeded, result]).then(function(words) {
|
return Q.race([timeExceeded, result]).then(function(words) {
|
||||||
LanguageServiceFacade.workingWorker.terminate();
|
workingWorker.terminate();
|
||||||
return words;
|
return words;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static GetParseResult = (str : string, parseReason : ParseReason) : Q.Promise<any> => {
|
private static GetParseResult = (str : string, parseReason : ParseReason) : Q.Promise<any> => {
|
||||||
return Q.Promise((resolve : any) => {
|
return Q.Promise((resolve : any) => {
|
||||||
if (LanguageServiceFacade.workingWorker != null) {
|
|
||||||
LanguageServiceFacade.workingWorker.terminate();
|
let workingWorker = (parseReason === ParseReason.GetCompletionWords ? LanguageServiceFacade.workingWorkerForCompletion : LanguageServiceFacade.workingWorkerForGettingError);
|
||||||
|
|
||||||
|
// terminate the expired worker.
|
||||||
|
if (workingWorker != null) {
|
||||||
|
workingWorker.terminate();
|
||||||
}
|
}
|
||||||
|
|
||||||
const currentUrlWithoutQueryParamsAndHashRoute: string = `${window.location.protocol}//${window.location.host}${window.location.pathname}`;
|
const currentUrlWithoutQueryParamsAndHashRoute: string = `${window.location.protocol}//${window.location.host}${window.location.pathname}`;
|
||||||
let url = currentUrlWithoutQueryParamsAndHashRoute.replace(/\/[^\/]*$/, '/node_modules/@azure/cosmos-language-service/dist/worker/dist/LanguageServiceWorker.js');
|
let url = currentUrlWithoutQueryParamsAndHashRoute.replace(/\/[^\/]*$/, '/node_modules/@azure/cosmos-language-service/dist/worker/dist/LanguageServiceWorker.js');
|
||||||
LanguageServiceFacade.workingWorker = new Worker(url);
|
|
||||||
|
|
||||||
LanguageServiceFacade.workingWorker.onmessage = (ev : MessageEvent) => {
|
if(parseReason === ParseReason.GetCompletionWords) {
|
||||||
|
LanguageServiceFacade.workingWorkerForCompletion = new Worker(url);
|
||||||
|
workingWorker = LanguageServiceFacade.workingWorkerForCompletion;
|
||||||
|
} else {
|
||||||
|
LanguageServiceFacade.workingWorkerForGettingError = new Worker(url);
|
||||||
|
workingWorker = LanguageServiceFacade.workingWorkerForGettingError;
|
||||||
|
}
|
||||||
|
|
||||||
|
workingWorker.onmessage = (ev : MessageEvent) => {
|
||||||
var processedResults: any[] = [];
|
var processedResults: any[] = [];
|
||||||
var parseResults: any[] = ev.data;
|
var parseResults: any[] = ev.data;
|
||||||
|
|
||||||
|
@ -72,7 +85,7 @@ export class LanguageServiceFacade {
|
||||||
code : str,
|
code : str,
|
||||||
reason : parseReason
|
reason : parseReason
|
||||||
};
|
};
|
||||||
LanguageServiceFacade.workingWorker.postMessage(source);
|
workingWorker.postMessage(source);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue