@mojir/lits 2.1.19 → 2.1.21

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.
@@ -11686,9 +11686,8 @@ var numberReservedSymbolRecord = {
11686
11686
  'NaN': Number.NaN,
11687
11687
  };
11688
11688
  var reservedSymbolRecord = __assign(__assign({}, nonNumberReservedSymbolRecord), numberReservedSymbolRecord);
11689
- var validReservedSymbolRecord = __assign(__assign({}, nonNumberReservedSymbolRecord), numberReservedSymbolRecord);
11690
11689
  function isReservedSymbol(symbol) {
11691
- return symbol in validReservedSymbolRecord;
11690
+ return symbol in reservedSymbolRecord;
11692
11691
  }
11693
11692
  function isNumberReservedSymbol(symbol) {
11694
11693
  return symbol in numberReservedSymbolRecord;
@@ -14802,18 +14801,25 @@ var Parser = /** @class */ (function () {
14802
14801
  return Parser;
14803
14802
  }());
14804
14803
 
14805
- var autoCompleteTokenTypes = [
14806
- 'Operator',
14807
- 'ReservedSymbol',
14808
- 'Symbol',
14809
- ];
14810
- var litsCommands = new Set(__spreadArray(__spreadArray([], __read(normalExpressionKeys), false), __read(specialExpressionKeys), false));
14804
+ var litsCommands = new Set(__spreadArray(__spreadArray(__spreadArray([], __read(normalExpressionKeys), false), __read(specialExpressionKeys), false), __read(Object.keys(reservedSymbolRecord)), false));
14811
14805
  // TODO: replace with get suggestions function
14812
14806
  var AutoCompleter = /** @class */ (function () {
14813
- function AutoCompleter(tokenStream, params) {
14814
- this.searchPrefix = '';
14807
+ function AutoCompleter(originalProgram, originalPosition, lits, params) {
14808
+ this.originalProgram = originalProgram;
14809
+ this.originalPosition = originalPosition;
14810
+ this.prefixProgram = '';
14811
+ this.suffixProgram = '';
14812
+ this.searchString = '';
14815
14813
  this.suggestions = [];
14816
14814
  this.suggestionIndex = null;
14815
+ var partialProgram = this.originalProgram.slice(0, this.originalPosition);
14816
+ var tokenStream = null;
14817
+ try {
14818
+ tokenStream = lits.tokenize(partialProgram);
14819
+ }
14820
+ catch (_a) {
14821
+ // do nothing
14822
+ }
14817
14823
  if (!tokenStream) {
14818
14824
  return;
14819
14825
  }
@@ -14821,14 +14827,28 @@ var AutoCompleter = /** @class */ (function () {
14821
14827
  if (!lastToken) {
14822
14828
  return;
14823
14829
  }
14824
- var _a = __read(lastToken, 2), tokenType = _a[0], tokenValue = _a[1];
14825
- if (!autoCompleteTokenTypes.includes(tokenType)) {
14826
- return;
14827
- }
14828
- this.searchPrefix = tokenValue;
14829
- this.generateSuggestions(params);
14830
+ this.searchString = lastToken[1];
14831
+ this.prefixProgram = this.originalProgram.slice(0, this.originalPosition - this.searchString.length);
14832
+ this.suffixProgram = this.originalProgram.slice(this.prefixProgram.length + this.searchString.length);
14833
+ this.originalProgram.slice(this.prefixProgram.length + this.searchString.length);
14834
+ this.suggestions = this.generateSuggestions(params);
14830
14835
  }
14831
14836
  AutoCompleter.prototype.getNextSuggestion = function () {
14837
+ return this.getAutoCompleteSuggestionResult(this.getNextSuggestionSymbol());
14838
+ };
14839
+ AutoCompleter.prototype.getPreviousSuggestion = function () {
14840
+ return this.getAutoCompleteSuggestionResult(this.getPreviousSuggestionSymbol());
14841
+ };
14842
+ AutoCompleter.prototype.getAutoCompleteSuggestionResult = function (suggestion) {
14843
+ if (suggestion === null) {
14844
+ return null;
14845
+ }
14846
+ return {
14847
+ program: this.prefixProgram + suggestion + this.suffixProgram,
14848
+ position: this.prefixProgram.length + suggestion.length,
14849
+ };
14850
+ };
14851
+ AutoCompleter.prototype.getNextSuggestionSymbol = function () {
14832
14852
  if (this.suggestions.length === 0) {
14833
14853
  return null;
14834
14854
  }
@@ -14841,12 +14861,9 @@ var AutoCompleter = /** @class */ (function () {
14841
14861
  this.suggestionIndex = 0;
14842
14862
  }
14843
14863
  }
14844
- return {
14845
- suggestion: this.suggestions[this.suggestionIndex],
14846
- searchPattern: this.searchPrefix,
14847
- };
14864
+ return this.suggestions[this.suggestionIndex];
14848
14865
  };
14849
- AutoCompleter.prototype.getPreviousSuggestion = function () {
14866
+ AutoCompleter.prototype.getPreviousSuggestionSymbol = function () {
14850
14867
  if (this.suggestions.length === 0) {
14851
14868
  return null;
14852
14869
  }
@@ -14859,41 +14876,38 @@ var AutoCompleter = /** @class */ (function () {
14859
14876
  this.suggestionIndex = this.suggestions.length - 1;
14860
14877
  }
14861
14878
  }
14862
- return {
14863
- suggestion: this.suggestions[this.suggestionIndex],
14864
- searchPattern: this.searchPrefix,
14865
- };
14879
+ return this.suggestions[this.suggestionIndex];
14866
14880
  };
14867
14881
  AutoCompleter.prototype.getSuggestions = function () {
14868
14882
  return __spreadArray([], __read(this.suggestions), false);
14869
14883
  };
14870
- AutoCompleter.prototype.getSearchPrefix = function () {
14871
- return this.searchPrefix;
14884
+ AutoCompleter.prototype.getSearchString = function () {
14885
+ return this.searchString;
14872
14886
  };
14873
14887
  AutoCompleter.prototype.generateSuggestions = function (params) {
14874
14888
  var _this = this;
14875
14889
  var _a, _b, _c, _d;
14876
14890
  var suggestions = new Set();
14877
14891
  litsCommands.forEach(function (name) {
14878
- if (name.startsWith(_this.searchPrefix)) {
14892
+ if (name.startsWith(_this.searchString)) {
14879
14893
  suggestions.add(name);
14880
14894
  }
14881
14895
  });
14882
14896
  Object.keys((_a = params.globalContext) !== null && _a !== void 0 ? _a : {})
14883
- .filter(function (name) { return name.startsWith(_this.searchPrefix); })
14897
+ .filter(function (name) { return name.startsWith(_this.searchString); })
14884
14898
  .forEach(function (name) { return suggestions.add(name); });
14885
14899
  (_b = params.contexts) === null || _b === void 0 ? void 0 : _b.forEach(function (context) {
14886
14900
  Object.keys(context)
14887
- .filter(function (name) { return name.startsWith(_this.searchPrefix); })
14901
+ .filter(function (name) { return name.startsWith(_this.searchString); })
14888
14902
  .forEach(function (name) { return suggestions.add(name); });
14889
14903
  });
14890
14904
  Object.keys((_c = params.jsFunctions) !== null && _c !== void 0 ? _c : {})
14891
- .filter(function (name) { return name.startsWith(_this.searchPrefix); })
14905
+ .filter(function (name) { return name.startsWith(_this.searchString); })
14892
14906
  .forEach(function (name) { return suggestions.add(name); });
14893
14907
  Object.keys((_d = params.values) !== null && _d !== void 0 ? _d : {})
14894
- .filter(function (name) { return name.startsWith(_this.searchPrefix); })
14908
+ .filter(function (name) { return name.startsWith(_this.searchString); })
14895
14909
  .forEach(function (name) { return suggestions.add(name); });
14896
- this.suggestions = __spreadArray([], __read(suggestions), false).sort(function (a, b) { return a.localeCompare(b); });
14910
+ return __spreadArray([], __read(suggestions), false).sort(function (a, b) { return a.localeCompare(b); });
14897
14911
  };
14898
14912
  return AutoCompleter;
14899
14913
  }());
@@ -15073,15 +15087,9 @@ var Lits = /** @class */ (function () {
15073
15087
  (_a = this.astCache) === null || _a === void 0 ? void 0 : _a.set(program, ast);
15074
15088
  return ast;
15075
15089
  };
15076
- Lits.prototype.getAutoCompleter = function (partialProgram, params) {
15090
+ Lits.prototype.getAutoCompleter = function (program, position, params) {
15077
15091
  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
- }
15092
+ return new AutoCompleter(program, position, this, params);
15085
15093
  };
15086
15094
  return Lits;
15087
15095
  }());