cspell-trie-lib 6.9.0 → 6.10.0

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.
@@ -9,6 +9,11 @@ export interface SuggestionResultBase {
9
9
  word: string;
10
10
  /** The edit cost 100 = 1 edit */
11
11
  cost: Cost;
12
+ /**
13
+ * This suggestion is the preferred suggestion.
14
+ * Setting this to `true` implies that an auto fix is possible.
15
+ */
16
+ isPreferred?: boolean | undefined;
12
17
  }
13
18
  export interface SuggestionResult extends SuggestionResultBase {
14
19
  /** The suggested word with compound marks, generally a `•` */
@@ -76,17 +76,18 @@ function suggestionCollector(wordToMatch, options) {
76
76
  const words = sug.word.split(regexSeparator);
77
77
  const extraCost = words.map((w) => wordLengthCost[w.length] || 0).reduce((a, b) => a + b, 0) +
78
78
  (words.length - 1) * EXTRA_WORD_COST;
79
- return { word: sug.word, cost: sug.cost + extraCost };
79
+ return { word: sug.word, cost: sug.cost + extraCost, isPreferred: sug.isPreferred };
80
80
  }
81
81
  function collectSuggestion(suggestion) {
82
- const { word, cost } = adjustCost(suggestion);
82
+ const { word, cost, isPreferred } = adjustCost(suggestion);
83
83
  if (cost <= maxCost && filter(suggestion.word, cost)) {
84
84
  const known = sugs.get(word);
85
85
  if (known) {
86
86
  known.cost = Math.min(known.cost, cost);
87
+ known.isPreferred = known.isPreferred || isPreferred;
87
88
  }
88
89
  else {
89
- sugs.set(word, { word, cost });
90
+ sugs.set(word, { word, cost, isPreferred });
90
91
  if (cost < maxCost && sugs.size > numSugToHold) {
91
92
  dropMax();
92
93
  }
@@ -131,6 +132,7 @@ function suggestionCollector(wordToMatch, options) {
131
132
  word: cWord,
132
133
  cost,
133
134
  compoundWord: word,
135
+ isPreferred: undefined,
134
136
  };
135
137
  }
136
138
  return { ...sr };
@@ -142,9 +144,10 @@ function suggestionCollector(wordToMatch, options) {
142
144
  const nWordToMatch = wordToMatch.normalize(NF);
143
145
  const rawValues = [...sugs.values()];
144
146
  const values = weightMap
145
- ? rawValues.map(({ word }) => ({
147
+ ? rawValues.map(({ word, isPreferred }) => ({
146
148
  word,
147
149
  cost: (0, __1.editDistanceWeighted)(nWordToMatch, word.normalize(NF), weightMap, 110),
150
+ isPreferred,
148
151
  }))
149
152
  : rawValues;
150
153
  const sorted = values.sort(compSuggestionResults).map(cleanCompoundResult);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cspell-trie-lib",
3
- "version": "6.9.0",
3
+ "version": "6.10.0",
4
4
  "description": "Trie Data Structure to support cspell.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -37,8 +37,8 @@
37
37
  },
38
38
  "homepage": "https://github.com/streetsidesoftware/cspell#readme",
39
39
  "dependencies": {
40
- "@cspell/cspell-pipe": "^6.9.0",
41
- "@cspell/cspell-types": "^6.9.0",
40
+ "@cspell/cspell-pipe": "^6.10.0",
41
+ "@cspell/cspell-types": "^6.10.0",
42
42
  "fs-extra": "^10.1.0",
43
43
  "gensequence": "^4.0.2"
44
44
  },
@@ -53,5 +53,5 @@
53
53
  "jest": "^29.0.3",
54
54
  "rimraf": "^3.0.2"
55
55
  },
56
- "gitHead": "d68b540deb382bafb2dce1be8f14935cc0d3cd5d"
56
+ "gitHead": "244f2ff310aa64bdb41cf93e85ba9e9f35c2b937"
57
57
  }