2018-11-26 15:46:04 +00:00
|
|
|
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
2020-11-13 14:24:13 +00:00
|
|
|
exports.LanguageServiceFacade = exports.ParseReason = void 0;
|
2018-11-26 15:46:04 +00:00
|
|
|
var Q = require("q");
|
2018-11-29 08:59:59 +00:00
|
|
|
var monaco_editor_1 = require("monaco-editor");
|
2018-11-26 15:46:04 +00:00
|
|
|
var ParseReason;
|
|
|
|
(function (ParseReason) {
|
|
|
|
ParseReason[ParseReason["GetCompletionWords"] = 1] = "GetCompletionWords";
|
|
|
|
ParseReason[ParseReason["GetErrors"] = 2] = "GetErrors";
|
|
|
|
})(ParseReason = exports.ParseReason || (exports.ParseReason = {}));
|
|
|
|
var LanguageServiceFacade = /** @class */ (function () {
|
|
|
|
function LanguageServiceFacade() {
|
|
|
|
}
|
|
|
|
LanguageServiceFacade.GetLanguageServiceParseResult = function (str, parseReason) {
|
|
|
|
var timeExceeded = Q.Promise(function (resolve, reject) {
|
|
|
|
var wait = setTimeout(function () {
|
2018-11-29 08:59:59 +00:00
|
|
|
var words = {};
|
2018-11-26 15:46:04 +00:00
|
|
|
resolve(words);
|
|
|
|
}, LanguageServiceFacade.timeout);
|
|
|
|
});
|
|
|
|
var result = LanguageServiceFacade.GetParseResult(str, parseReason);
|
2019-01-08 13:40:34 +00:00
|
|
|
var workingWorker = (parseReason === ParseReason.GetCompletionWords ? LanguageServiceFacade.workingWorkerForCompletion : LanguageServiceFacade.workingWorkerForGettingError);
|
2018-11-26 15:46:04 +00:00
|
|
|
return Q.race([timeExceeded, result]).then(function (words) {
|
2019-01-08 13:40:34 +00:00
|
|
|
workingWorker.terminate();
|
2018-11-26 15:46:04 +00:00
|
|
|
return words;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
LanguageServiceFacade.timeout = 2000;
|
2019-01-08 13:40:34 +00:00
|
|
|
LanguageServiceFacade.workingWorkerForCompletion = null;
|
|
|
|
LanguageServiceFacade.workingWorkerForGettingError = null;
|
2018-11-26 15:46:04 +00:00
|
|
|
LanguageServiceFacade.GetParseResult = function (str, parseReason) {
|
|
|
|
return Q.Promise(function (resolve) {
|
2019-01-08 13:40:34 +00:00
|
|
|
var workingWorker = (parseReason === ParseReason.GetCompletionWords ? LanguageServiceFacade.workingWorkerForCompletion : LanguageServiceFacade.workingWorkerForGettingError);
|
|
|
|
// terminate the expired worker.
|
|
|
|
if (workingWorker != null) {
|
|
|
|
workingWorker.terminate();
|
2018-11-26 15:46:04 +00:00
|
|
|
}
|
2018-11-29 08:59:59 +00:00
|
|
|
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');
|
2019-01-08 13:40:34 +00:00
|
|
|
if (parseReason === ParseReason.GetCompletionWords) {
|
|
|
|
LanguageServiceFacade.workingWorkerForCompletion = new Worker(url);
|
|
|
|
workingWorker = LanguageServiceFacade.workingWorkerForCompletion;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
LanguageServiceFacade.workingWorkerForGettingError = new Worker(url);
|
|
|
|
workingWorker = LanguageServiceFacade.workingWorkerForGettingError;
|
|
|
|
}
|
|
|
|
workingWorker.onmessage = function (ev) {
|
2018-11-26 15:46:04 +00:00
|
|
|
var processedResults = [];
|
2019-01-08 12:13:06 +00:00
|
|
|
var parseResults = ev.data;
|
2018-11-26 15:46:04 +00:00
|
|
|
if (parseReason === ParseReason.GetCompletionWords) {
|
2019-01-08 12:13:06 +00:00
|
|
|
parseResults.forEach(function (label) {
|
2018-11-26 15:46:04 +00:00
|
|
|
if (!!label) {
|
|
|
|
processedResults.push({
|
|
|
|
label: label,
|
2019-01-08 12:13:06 +00:00
|
|
|
insertText: label,
|
2018-11-29 08:59:59 +00:00
|
|
|
kind: monaco_editor_1.languages.CompletionItemKind.Keyword
|
2018-11-26 15:46:04 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2019-01-08 12:13:06 +00:00
|
|
|
var finalResult = { suggestions: processedResults };
|
|
|
|
resolve(finalResult);
|
2018-11-26 15:46:04 +00:00
|
|
|
}
|
|
|
|
else if (parseReason === ParseReason.GetErrors) {
|
2019-01-08 12:13:06 +00:00
|
|
|
parseResults.forEach(function (err) {
|
2018-11-26 15:46:04 +00:00
|
|
|
var mark = {
|
2018-11-29 08:59:59 +00:00
|
|
|
severity: monaco_editor_1.MarkerSeverity.Error,
|
2018-11-26 15:46:04 +00:00
|
|
|
message: err.Message,
|
|
|
|
startLineNumber: err.line,
|
|
|
|
startColumn: err.column,
|
|
|
|
endLineNumber: err.line,
|
|
|
|
endColumn: err.column
|
|
|
|
};
|
|
|
|
processedResults.push(mark);
|
|
|
|
});
|
2019-01-08 12:13:06 +00:00
|
|
|
resolve(processedResults);
|
2018-11-26 15:46:04 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
var source = {
|
|
|
|
code: str,
|
|
|
|
reason: parseReason
|
|
|
|
};
|
2019-01-08 13:40:34 +00:00
|
|
|
workingWorker.postMessage(source);
|
2018-11-26 15:46:04 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
return LanguageServiceFacade;
|
|
|
|
}());
|
|
|
|
exports.LanguageServiceFacade = LanguageServiceFacade;
|
|
|
|
//# sourceMappingURL=LanguageServiceFacade.js.map
|