clarity-pattern-parser 11.3.7 → 11.3.9
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/index.browser.js +51 -26
- package/dist/index.browser.js.map +1 -1
- package/dist/index.esm.js +51 -26
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +51 -26
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/intellisense/AutoComplete.test.ts +24 -0
- package/src/intellisense/AutoComplete.ts +1 -1
package/dist/index.browser.js
CHANGED
|
@@ -4062,7 +4062,7 @@
|
|
|
4062
4062
|
const furthestError = cursor.furthestError;
|
|
4063
4063
|
const furthestMatch = cursor.allMatchedNodes[cursor.allMatchedNodes.length - 1];
|
|
4064
4064
|
if (furthestError && furthestMatch) {
|
|
4065
|
-
if (
|
|
4065
|
+
if (furthestMatch.endIndex > furthestError.lastIndex) {
|
|
4066
4066
|
return furthestMatch.endIndex;
|
|
4067
4067
|
}
|
|
4068
4068
|
else {
|
|
@@ -4117,7 +4117,7 @@
|
|
|
4117
4117
|
}
|
|
4118
4118
|
_createSuggestionsFromRoot() {
|
|
4119
4119
|
const suggestions = [];
|
|
4120
|
-
const tokens = this._pattern.getTokens();
|
|
4120
|
+
const tokens = [...this._pattern.getTokens(), ...this._getTokensForPattern(this._pattern)];
|
|
4121
4121
|
for (const token of tokens) {
|
|
4122
4122
|
if (suggestions.findIndex(s => s.text === token) === -1) {
|
|
4123
4123
|
suggestions.push(this._createSuggestion("", token));
|
|
@@ -4129,15 +4129,29 @@
|
|
|
4129
4129
|
if (match.pattern == null) {
|
|
4130
4130
|
return this._createSuggestions(-1, this._getTokensForPattern(this._pattern));
|
|
4131
4131
|
}
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
|
|
4135
|
-
|
|
4136
|
-
|
|
4137
|
-
|
|
4132
|
+
if (match.node != null) {
|
|
4133
|
+
const textStartingMatch = this._text.slice(match.node.startIndex, match.node.endIndex);
|
|
4134
|
+
const currentPatternsTokens = this._getTokensForPattern(match.pattern);
|
|
4135
|
+
/**
|
|
4136
|
+
* Compares tokens to current text and extracts remainder tokens
|
|
4137
|
+
* - IE. **currentText:** *abc*, **baseToken:** *abcdef*, **trailingToken:** *def*
|
|
4138
|
+
*/
|
|
4139
|
+
const trailingTokens = currentPatternsTokens.reduce((acc, token) => {
|
|
4140
|
+
if (token.startsWith(textStartingMatch)) {
|
|
4141
|
+
const sliced = token.slice(textStartingMatch.length);
|
|
4142
|
+
if (sliced !== '') {
|
|
4143
|
+
acc.push(sliced);
|
|
4144
|
+
}
|
|
4145
|
+
}
|
|
4146
|
+
return acc;
|
|
4147
|
+
}, []);
|
|
4148
|
+
const leafPatterns = match.pattern.getNextPatterns();
|
|
4149
|
+
const leafTokens = leafPatterns.reduce((acc, leafPattern) => {
|
|
4150
|
+
acc.push(...this._getTokensForPattern(leafPattern));
|
|
4138
4151
|
return acc;
|
|
4139
4152
|
}, []);
|
|
4140
|
-
|
|
4153
|
+
const allTokens = [...trailingTokens, ...leafTokens];
|
|
4154
|
+
return this._createSuggestions(match.node.lastIndex, allTokens);
|
|
4141
4155
|
}
|
|
4142
4156
|
else {
|
|
4143
4157
|
return [];
|
|
@@ -4147,44 +4161,54 @@
|
|
|
4147
4161
|
const augmentedTokens = this._getAugmentedTokens(pattern);
|
|
4148
4162
|
if (this._options.greedyPatternNames != null && this._options.greedyPatternNames.includes(pattern.name)) {
|
|
4149
4163
|
const nextPatterns = pattern.getNextPatterns();
|
|
4150
|
-
const tokens = [];
|
|
4151
4164
|
const nextPatternTokens = nextPatterns.reduce((acc, pattern) => {
|
|
4152
4165
|
acc.push(...this._getTokensForPattern(pattern));
|
|
4153
4166
|
return acc;
|
|
4154
4167
|
}, []);
|
|
4155
|
-
|
|
4156
|
-
|
|
4157
|
-
|
|
4168
|
+
// using set to prevent duplicates
|
|
4169
|
+
const tokens = new Set();
|
|
4170
|
+
for (const token of augmentedTokens) {
|
|
4171
|
+
for (const nextPatternToken of nextPatternTokens) {
|
|
4172
|
+
tokens.add(token + nextPatternToken);
|
|
4158
4173
|
}
|
|
4159
4174
|
}
|
|
4160
|
-
return tokens;
|
|
4175
|
+
return [...tokens];
|
|
4161
4176
|
}
|
|
4162
4177
|
else {
|
|
4163
4178
|
return augmentedTokens;
|
|
4164
4179
|
}
|
|
4165
4180
|
}
|
|
4166
4181
|
_getAugmentedTokens(pattern) {
|
|
4182
|
+
var _a, _b;
|
|
4167
4183
|
const customTokensMap = this._options.customTokens || {};
|
|
4168
4184
|
const leafPatterns = pattern.getPatterns();
|
|
4169
|
-
|
|
4170
|
-
|
|
4171
|
-
|
|
4172
|
-
|
|
4173
|
-
|
|
4174
|
-
|
|
4185
|
+
/** Using Set to
|
|
4186
|
+
* - prevent duplicates
|
|
4187
|
+
* - prevent mutation of original customTokensMap
|
|
4188
|
+
*/
|
|
4189
|
+
const customTokensForPattern = new Set((_a = customTokensMap[pattern.name]) !== null && _a !== void 0 ? _a : []);
|
|
4190
|
+
for (const lp of leafPatterns) {
|
|
4191
|
+
const augmentedTokens = (_b = customTokensMap[lp.name]) !== null && _b !== void 0 ? _b : [];
|
|
4192
|
+
const lpsCombinedTokens = [...lp.getTokens(), ...augmentedTokens];
|
|
4193
|
+
for (const token of lpsCombinedTokens) {
|
|
4194
|
+
customTokensForPattern.add(token);
|
|
4195
|
+
}
|
|
4196
|
+
}
|
|
4197
|
+
return [...customTokensForPattern];
|
|
4175
4198
|
}
|
|
4176
4199
|
_createSuggestions(lastIndex, tokens) {
|
|
4177
|
-
let
|
|
4200
|
+
let textToIndex = lastIndex === -1 ? "" : this._cursor.getChars(0, lastIndex);
|
|
4178
4201
|
const suggestionStrings = [];
|
|
4179
4202
|
const options = [];
|
|
4180
4203
|
for (const token of tokens) {
|
|
4181
|
-
|
|
4182
|
-
const
|
|
4204
|
+
// concatenated for start index identification inside createSuggestion
|
|
4205
|
+
const suggestion = textToIndex + token;
|
|
4183
4206
|
const alreadyExist = suggestionStrings.includes(suggestion);
|
|
4184
4207
|
const isSameAsText = suggestion === this._text;
|
|
4185
|
-
if (
|
|
4208
|
+
if (!alreadyExist && !isSameAsText) {
|
|
4186
4209
|
suggestionStrings.push(suggestion);
|
|
4187
|
-
|
|
4210
|
+
const suggestionOption = this._createSuggestion(this._cursor.text, suggestion);
|
|
4211
|
+
options.push(suggestionOption);
|
|
4188
4212
|
}
|
|
4189
4213
|
}
|
|
4190
4214
|
const reducedOptions = getFurthestOptions(options);
|
|
@@ -4194,10 +4218,11 @@
|
|
|
4194
4218
|
_createSuggestion(fullText, suggestion) {
|
|
4195
4219
|
const furthestMatch = findMatchIndex(suggestion, fullText);
|
|
4196
4220
|
const text = suggestion.slice(furthestMatch);
|
|
4197
|
-
|
|
4221
|
+
const option = {
|
|
4198
4222
|
text: text,
|
|
4199
4223
|
startIndex: furthestMatch,
|
|
4200
4224
|
};
|
|
4225
|
+
return option;
|
|
4201
4226
|
}
|
|
4202
4227
|
static suggestFor(text, pattern, options) {
|
|
4203
4228
|
return new AutoComplete(pattern, options).suggestFor(text);
|