This commit is contained in:
Steve Faulkner 2019-01-08 09:49:55 -05:00
commit 664562addb
3 changed files with 58 additions and 34 deletions

View File

@ -18,36 +18,50 @@ 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);
LanguageServiceFacade.workingWorker.onmessage = function (ev) {
var processedResults = [];
var results = ev.data;
if (parseReason === ParseReason.GetCompletionWords) { if (parseReason === ParseReason.GetCompletionWords) {
results.forEach(function (label) { LanguageServiceFacade.workingWorkerForCompletion = new Worker(url);
workingWorker = LanguageServiceFacade.workingWorkerForCompletion;
}
else {
LanguageServiceFacade.workingWorkerForGettingError = new Worker(url);
workingWorker = LanguageServiceFacade.workingWorkerForGettingError;
}
workingWorker.onmessage = function (ev) {
var processedResults = [];
var parseResults = ev.data;
if (parseReason === ParseReason.GetCompletionWords) {
parseResults.forEach(function (label) {
if (!!label) { if (!!label) {
processedResults.push({ processedResults.push({
label: label, label: label,
insertText: label,
kind: monaco_editor_1.languages.CompletionItemKind.Keyword kind: monaco_editor_1.languages.CompletionItemKind.Keyword
}); });
} }
}); });
var finalResult = { suggestions: processedResults };
resolve(finalResult);
} }
else if (parseReason === ParseReason.GetErrors) { else if (parseReason === ParseReason.GetErrors) {
results.forEach(function (err) { parseResults.forEach(function (err) {
var mark = { var mark = {
severity: monaco_editor_1.MarkerSeverity.Error, severity: monaco_editor_1.MarkerSeverity.Error,
message: err.Message, message: err.Message,
@ -58,15 +72,14 @@ var LanguageServiceFacade = /** @class */ (function () {
}; };
processedResults.push(mark); processedResults.push(mark);
}); });
resolve(processedResults);
} }
var completionItemList = { suggestions: processedResults };
resolve(completionItemList);
}; };
var source = { var source = {
code: str, code: str,
reason: parseReason reason: parseReason
}; };
LanguageServiceFacade.workingWorker.postMessage(source); workingWorker.postMessage(source);
}); });
}; };
return LanguageServiceFacade; return LanguageServiceFacade;

View File

@ -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,K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IAAI,WAAW,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"}

View File

@ -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,8 +21,9 @@ 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;
}); });
} }
@ -29,30 +31,42 @@ export class LanguageServiceFacade {
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) { let workingWorker = (parseReason === ParseReason.GetCompletionWords ? LanguageServiceFacade.workingWorkerForCompletion : LanguageServiceFacade.workingWorkerForGettingError);
LanguageServiceFacade.workingWorker.terminate();
// 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) => {
var processedResults: any = [];
var results : any[] = ev.data;
if(parseReason === ParseReason.GetCompletionWords) { if(parseReason === ParseReason.GetCompletionWords) {
results.forEach((label: string) => { 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 parseResults: any[] = ev.data;
if (parseReason === ParseReason.GetCompletionWords) {
parseResults.forEach((label: string) => {
if (!!label) { if (!!label) {
processedResults.push({ processedResults.push({
label: label, label: label,
insertText: label,
kind: languages.CompletionItemKind.Keyword kind: languages.CompletionItemKind.Keyword
}); });
} }
}); });
let finalResult : languages.CompletionList = {suggestions : processedResults};
resolve(finalResult);
} else if (parseReason === ParseReason.GetErrors) { } else if (parseReason === ParseReason.GetErrors) {
results.forEach((err: any) => { parseResults.forEach((err: any) => {
const mark: editor.IMarkerData = { const mark: editor.IMarkerData = {
severity: MarkerSeverity.Error, severity: MarkerSeverity.Error,
message: err.Message, message: err.Message,
@ -61,20 +75,17 @@ export class LanguageServiceFacade {
endLineNumber: err.line, endLineNumber: err.line,
endColumn: err.column endColumn: err.column
}; };
processedResults.push(mark);
processedResults.push(mark)
}); });
resolve(processedResults);
} }
let completionItemList : languages.CompletionList = {suggestions : processedResults};
resolve(completionItemList);
} }
const source = { const source = {
code : str, code : str,
reason : parseReason reason : parseReason
}; };
LanguageServiceFacade.workingWorker.postMessage(source); workingWorker.postMessage(source);
}); });
} }
} }