This repository has been archived on 2024-02-26. You can view files and clone it, but cannot push or open issues or pull requests.
cosmos-sql-language-service/dist/facade/LanguageServiceFacade.js

88 lines
4.3 KiB
JavaScript
Raw Normal View History

2018-11-26 15:46:04 +00:00
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Q = require("q");
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 () {
var words = {};
2018-11-26 15:46:04 +00:00
resolve(words);
}, LanguageServiceFacade.timeout);
});
var result = LanguageServiceFacade.GetParseResult(str, parseReason);
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) {
workingWorker.terminate();
2018-11-26 15:46:04 +00:00
return words;
});
};
LanguageServiceFacade.timeout = 2000;
LanguageServiceFacade.workingWorkerForCompletion = null;
LanguageServiceFacade.workingWorkerForGettingError = null;
2018-11-26 15:46:04 +00:00
LanguageServiceFacade.GetParseResult = function (str, parseReason) {
return Q.Promise(function (resolve) {
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
}
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');
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,
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 = {
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
};
workingWorker.postMessage(source);
2018-11-26 15:46:04 +00:00
});
};
return LanguageServiceFacade;
}());
exports.LanguageServiceFacade = LanguageServiceFacade;
//# sourceMappingURL=LanguageServiceFacade.js.map