@mojir/lits 2.1.16 → 2.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/cli.js +107 -1
- package/dist/cli/src/AutoCompleter/AutoCompleter.d.ts +17 -0
- package/dist/cli/src/Lits/Lits.d.ts +2 -0
- package/dist/index.esm.js +106 -0
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +106 -0
- package/dist/index.js.map +1 -1
- package/dist/lits.iife.js +106 -0
- package/dist/lits.iife.js.map +1 -1
- package/dist/src/AutoCompleter/AutoCompleter.d.ts +17 -0
- package/dist/src/Lits/Lits.d.ts +2 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/testFramework.esm.js +106 -0
- package/dist/testFramework.esm.js.map +1 -1
- package/dist/testFramework.js +106 -0
- package/dist/testFramework.js.map +1 -1
- package/package.json +1 -1
package/dist/testFramework.js
CHANGED
|
@@ -14802,6 +14802,102 @@ var Parser = /** @class */ (function () {
|
|
|
14802
14802
|
return Parser;
|
|
14803
14803
|
}());
|
|
14804
14804
|
|
|
14805
|
+
var autoCompleteTokenTypes = [
|
|
14806
|
+
'Operator',
|
|
14807
|
+
'ReservedSymbol',
|
|
14808
|
+
'Symbol',
|
|
14809
|
+
];
|
|
14810
|
+
var litsCommands = new Set(__spreadArray(__spreadArray([], __read(normalExpressionKeys), false), __read(specialExpressionKeys), false));
|
|
14811
|
+
// TODO: replace with get suggestions function
|
|
14812
|
+
var AutoCompleter = /** @class */ (function () {
|
|
14813
|
+
function AutoCompleter(tokenStream, params) {
|
|
14814
|
+
this.searchPrefix = '';
|
|
14815
|
+
this.suggestions = [];
|
|
14816
|
+
this.suggestionIndex = null;
|
|
14817
|
+
if (!tokenStream) {
|
|
14818
|
+
return;
|
|
14819
|
+
}
|
|
14820
|
+
var lastToken = tokenStream.tokens.at(-1);
|
|
14821
|
+
if (!lastToken) {
|
|
14822
|
+
return;
|
|
14823
|
+
}
|
|
14824
|
+
var _a = __read(lastToken, 2), tokenType = _a[0], tokenValue = _a[1];
|
|
14825
|
+
if (!autoCompleteTokenTypes.includes(tokenType)) {
|
|
14826
|
+
return;
|
|
14827
|
+
}
|
|
14828
|
+
this.searchPrefix = tokenValue.toLowerCase();
|
|
14829
|
+
this.generateSuggestions(params);
|
|
14830
|
+
}
|
|
14831
|
+
AutoCompleter.prototype.getNextSuggestion = function () {
|
|
14832
|
+
if (this.suggestions.length === 0) {
|
|
14833
|
+
return null;
|
|
14834
|
+
}
|
|
14835
|
+
if (this.suggestionIndex === null) {
|
|
14836
|
+
this.suggestionIndex = 0;
|
|
14837
|
+
}
|
|
14838
|
+
else {
|
|
14839
|
+
this.suggestionIndex += 1;
|
|
14840
|
+
if (this.suggestionIndex >= this.suggestions.length) {
|
|
14841
|
+
this.suggestionIndex = 0;
|
|
14842
|
+
}
|
|
14843
|
+
}
|
|
14844
|
+
return {
|
|
14845
|
+
suggestion: this.suggestions[this.suggestionIndex],
|
|
14846
|
+
searchPattern: this.searchPrefix,
|
|
14847
|
+
};
|
|
14848
|
+
};
|
|
14849
|
+
AutoCompleter.prototype.getPreviousSuggestion = function () {
|
|
14850
|
+
if (this.suggestions.length === 0) {
|
|
14851
|
+
return null;
|
|
14852
|
+
}
|
|
14853
|
+
if (this.suggestionIndex === null) {
|
|
14854
|
+
this.suggestionIndex = this.suggestions.length - 1;
|
|
14855
|
+
}
|
|
14856
|
+
else {
|
|
14857
|
+
this.suggestionIndex -= 1;
|
|
14858
|
+
if (this.suggestionIndex < 0) {
|
|
14859
|
+
this.suggestionIndex = this.suggestions.length - 1;
|
|
14860
|
+
}
|
|
14861
|
+
}
|
|
14862
|
+
return {
|
|
14863
|
+
suggestion: this.suggestions[this.suggestionIndex],
|
|
14864
|
+
searchPattern: this.searchPrefix,
|
|
14865
|
+
};
|
|
14866
|
+
};
|
|
14867
|
+
AutoCompleter.prototype.getSuggestions = function () {
|
|
14868
|
+
return __spreadArray([], __read(this.suggestions), false);
|
|
14869
|
+
};
|
|
14870
|
+
AutoCompleter.prototype.getSearchPrefix = function () {
|
|
14871
|
+
return this.searchPrefix;
|
|
14872
|
+
};
|
|
14873
|
+
AutoCompleter.prototype.generateSuggestions = function (params) {
|
|
14874
|
+
var _this = this;
|
|
14875
|
+
var _a, _b, _c, _d;
|
|
14876
|
+
var suggestions = new Set();
|
|
14877
|
+
litsCommands.forEach(function (name) {
|
|
14878
|
+
if (name.toLowerCase().startsWith(_this.searchPrefix)) {
|
|
14879
|
+
suggestions.add(name);
|
|
14880
|
+
}
|
|
14881
|
+
});
|
|
14882
|
+
Object.keys((_a = params.globalContext) !== null && _a !== void 0 ? _a : {})
|
|
14883
|
+
.filter(function (name) { return name.toLowerCase().startsWith(_this.searchPrefix); })
|
|
14884
|
+
.forEach(function (name) { return suggestions.add(name); });
|
|
14885
|
+
(_b = params.contexts) === null || _b === void 0 ? void 0 : _b.forEach(function (context) {
|
|
14886
|
+
Object.keys(context)
|
|
14887
|
+
.filter(function (name) { return name.toLowerCase().startsWith(_this.searchPrefix); })
|
|
14888
|
+
.forEach(function (name) { return suggestions.add(name); });
|
|
14889
|
+
});
|
|
14890
|
+
Object.keys((_c = params.jsFunctions) !== null && _c !== void 0 ? _c : {})
|
|
14891
|
+
.filter(function (name) { return name.toLowerCase().startsWith(_this.searchPrefix); })
|
|
14892
|
+
.forEach(function (name) { return suggestions.add(name); });
|
|
14893
|
+
Object.keys((_d = params.values) !== null && _d !== void 0 ? _d : {})
|
|
14894
|
+
.filter(function (name) { return name.toLowerCase().startsWith(_this.searchPrefix); })
|
|
14895
|
+
.forEach(function (name) { return suggestions.add(name); });
|
|
14896
|
+
this.suggestions = __spreadArray([], __read(suggestions), false).sort(function (a, b) { return a.toLowerCase().localeCompare(b.toLowerCase()); });
|
|
14897
|
+
};
|
|
14898
|
+
return AutoCompleter;
|
|
14899
|
+
}());
|
|
14900
|
+
|
|
14805
14901
|
var Cache = /** @class */ (function () {
|
|
14806
14902
|
function Cache(maxSize) {
|
|
14807
14903
|
this.cache = {};
|
|
@@ -14977,6 +15073,16 @@ var Lits = /** @class */ (function () {
|
|
|
14977
15073
|
(_a = this.astCache) === null || _a === void 0 ? void 0 : _a.set(program, ast);
|
|
14978
15074
|
return ast;
|
|
14979
15075
|
};
|
|
15076
|
+
Lits.prototype.getAutoCompleter = function (partialProgram, params) {
|
|
15077
|
+
if (params === void 0) { params = {}; }
|
|
15078
|
+
try {
|
|
15079
|
+
var tokenStream = this.tokenize(partialProgram);
|
|
15080
|
+
return new AutoCompleter(tokenStream, params);
|
|
15081
|
+
}
|
|
15082
|
+
catch (_a) {
|
|
15083
|
+
return new AutoCompleter(null, params);
|
|
15084
|
+
}
|
|
15085
|
+
};
|
|
14980
15086
|
return Lits;
|
|
14981
15087
|
}());
|
|
14982
15088
|
|