@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.
package/dist/lits.iife.js CHANGED
@@ -11631,9 +11631,8 @@ var Lits = (function (exports) {
11631
11631
  'NaN': Number.NaN,
11632
11632
  };
11633
11633
  var reservedSymbolRecord = __assign(__assign({}, nonNumberReservedSymbolRecord), numberReservedSymbolRecord);
11634
- var validReservedSymbolRecord = __assign(__assign({}, nonNumberReservedSymbolRecord), numberReservedSymbolRecord);
11635
11634
  function isReservedSymbol(symbol) {
11636
- return symbol in validReservedSymbolRecord;
11635
+ return symbol in reservedSymbolRecord;
11637
11636
  }
11638
11637
  function isNumberReservedSymbol(symbol) {
11639
11638
  return symbol in numberReservedSymbolRecord;
@@ -14862,18 +14861,25 @@ var Lits = (function (exports) {
14862
14861
  return Parser;
14863
14862
  }());
14864
14863
 
14865
- var autoCompleteTokenTypes = [
14866
- 'Operator',
14867
- 'ReservedSymbol',
14868
- 'Symbol',
14869
- ];
14870
- var litsCommands = new Set(__spreadArray(__spreadArray([], __read(normalExpressionKeys), false), __read(specialExpressionKeys), false));
14864
+ var litsCommands = new Set(__spreadArray(__spreadArray(__spreadArray([], __read(normalExpressionKeys), false), __read(specialExpressionKeys), false), __read(Object.keys(reservedSymbolRecord)), false));
14871
14865
  // TODO: replace with get suggestions function
14872
14866
  var AutoCompleter = /** @class */ (function () {
14873
- function AutoCompleter(tokenStream, params) {
14874
- this.searchPrefix = '';
14867
+ function AutoCompleter(originalProgram, originalPosition, lits, params) {
14868
+ this.originalProgram = originalProgram;
14869
+ this.originalPosition = originalPosition;
14870
+ this.prefixProgram = '';
14871
+ this.suffixProgram = '';
14872
+ this.searchString = '';
14875
14873
  this.suggestions = [];
14876
14874
  this.suggestionIndex = null;
14875
+ var partialProgram = this.originalProgram.slice(0, this.originalPosition);
14876
+ var tokenStream = null;
14877
+ try {
14878
+ tokenStream = lits.tokenize(partialProgram);
14879
+ }
14880
+ catch (_a) {
14881
+ // do nothing
14882
+ }
14877
14883
  if (!tokenStream) {
14878
14884
  return;
14879
14885
  }
@@ -14881,14 +14887,28 @@ var Lits = (function (exports) {
14881
14887
  if (!lastToken) {
14882
14888
  return;
14883
14889
  }
14884
- var _a = __read(lastToken, 2), tokenType = _a[0], tokenValue = _a[1];
14885
- if (!autoCompleteTokenTypes.includes(tokenType)) {
14886
- return;
14887
- }
14888
- this.searchPrefix = tokenValue;
14889
- this.generateSuggestions(params);
14890
+ this.searchString = lastToken[1];
14891
+ this.prefixProgram = this.originalProgram.slice(0, this.originalPosition - this.searchString.length);
14892
+ this.suffixProgram = this.originalProgram.slice(this.prefixProgram.length + this.searchString.length);
14893
+ this.originalProgram.slice(this.prefixProgram.length + this.searchString.length);
14894
+ this.suggestions = this.generateSuggestions(params);
14890
14895
  }
14891
14896
  AutoCompleter.prototype.getNextSuggestion = function () {
14897
+ return this.getAutoCompleteSuggestionResult(this.getNextSuggestionSymbol());
14898
+ };
14899
+ AutoCompleter.prototype.getPreviousSuggestion = function () {
14900
+ return this.getAutoCompleteSuggestionResult(this.getPreviousSuggestionSymbol());
14901
+ };
14902
+ AutoCompleter.prototype.getAutoCompleteSuggestionResult = function (suggestion) {
14903
+ if (suggestion === null) {
14904
+ return null;
14905
+ }
14906
+ return {
14907
+ program: this.prefixProgram + suggestion + this.suffixProgram,
14908
+ position: this.prefixProgram.length + suggestion.length,
14909
+ };
14910
+ };
14911
+ AutoCompleter.prototype.getNextSuggestionSymbol = function () {
14892
14912
  if (this.suggestions.length === 0) {
14893
14913
  return null;
14894
14914
  }
@@ -14901,12 +14921,9 @@ var Lits = (function (exports) {
14901
14921
  this.suggestionIndex = 0;
14902
14922
  }
14903
14923
  }
14904
- return {
14905
- suggestion: this.suggestions[this.suggestionIndex],
14906
- searchPattern: this.searchPrefix,
14907
- };
14924
+ return this.suggestions[this.suggestionIndex];
14908
14925
  };
14909
- AutoCompleter.prototype.getPreviousSuggestion = function () {
14926
+ AutoCompleter.prototype.getPreviousSuggestionSymbol = function () {
14910
14927
  if (this.suggestions.length === 0) {
14911
14928
  return null;
14912
14929
  }
@@ -14919,41 +14936,38 @@ var Lits = (function (exports) {
14919
14936
  this.suggestionIndex = this.suggestions.length - 1;
14920
14937
  }
14921
14938
  }
14922
- return {
14923
- suggestion: this.suggestions[this.suggestionIndex],
14924
- searchPattern: this.searchPrefix,
14925
- };
14939
+ return this.suggestions[this.suggestionIndex];
14926
14940
  };
14927
14941
  AutoCompleter.prototype.getSuggestions = function () {
14928
14942
  return __spreadArray([], __read(this.suggestions), false);
14929
14943
  };
14930
- AutoCompleter.prototype.getSearchPrefix = function () {
14931
- return this.searchPrefix;
14944
+ AutoCompleter.prototype.getSearchString = function () {
14945
+ return this.searchString;
14932
14946
  };
14933
14947
  AutoCompleter.prototype.generateSuggestions = function (params) {
14934
14948
  var _this = this;
14935
14949
  var _a, _b, _c, _d;
14936
14950
  var suggestions = new Set();
14937
14951
  litsCommands.forEach(function (name) {
14938
- if (name.startsWith(_this.searchPrefix)) {
14952
+ if (name.startsWith(_this.searchString)) {
14939
14953
  suggestions.add(name);
14940
14954
  }
14941
14955
  });
14942
14956
  Object.keys((_a = params.globalContext) !== null && _a !== void 0 ? _a : {})
14943
- .filter(function (name) { return name.startsWith(_this.searchPrefix); })
14957
+ .filter(function (name) { return name.startsWith(_this.searchString); })
14944
14958
  .forEach(function (name) { return suggestions.add(name); });
14945
14959
  (_b = params.contexts) === null || _b === void 0 ? void 0 : _b.forEach(function (context) {
14946
14960
  Object.keys(context)
14947
- .filter(function (name) { return name.startsWith(_this.searchPrefix); })
14961
+ .filter(function (name) { return name.startsWith(_this.searchString); })
14948
14962
  .forEach(function (name) { return suggestions.add(name); });
14949
14963
  });
14950
14964
  Object.keys((_c = params.jsFunctions) !== null && _c !== void 0 ? _c : {})
14951
- .filter(function (name) { return name.startsWith(_this.searchPrefix); })
14965
+ .filter(function (name) { return name.startsWith(_this.searchString); })
14952
14966
  .forEach(function (name) { return suggestions.add(name); });
14953
14967
  Object.keys((_d = params.values) !== null && _d !== void 0 ? _d : {})
14954
- .filter(function (name) { return name.startsWith(_this.searchPrefix); })
14968
+ .filter(function (name) { return name.startsWith(_this.searchString); })
14955
14969
  .forEach(function (name) { return suggestions.add(name); });
14956
- this.suggestions = __spreadArray([], __read(suggestions), false).sort(function (a, b) { return a.localeCompare(b); });
14970
+ return __spreadArray([], __read(suggestions), false).sort(function (a, b) { return a.localeCompare(b); });
14957
14971
  };
14958
14972
  return AutoCompleter;
14959
14973
  }());
@@ -15133,15 +15147,9 @@ var Lits = (function (exports) {
15133
15147
  (_a = this.astCache) === null || _a === void 0 ? void 0 : _a.set(program, ast);
15134
15148
  return ast;
15135
15149
  };
15136
- Lits.prototype.getAutoCompleter = function (partialProgram, params) {
15150
+ Lits.prototype.getAutoCompleter = function (program, position, params) {
15137
15151
  if (params === void 0) { params = {}; }
15138
- try {
15139
- var tokenStream = this.tokenize(partialProgram);
15140
- return new AutoCompleter(tokenStream, params);
15141
- }
15142
- catch (_a) {
15143
- return new AutoCompleter(null, params);
15144
- }
15152
+ return new AutoCompleter(program, position, this, params);
15145
15153
  };
15146
15154
  return Lits;
15147
15155
  }());