cspell-lib 6.24.0 → 6.26.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.
@@ -233,6 +233,7 @@ exports.languageExtensionDefinitions = [
233
233
  { id: 'jar', extensions: ['.jar'], format: 'Binary' },
234
234
  { id: 'spv', extensions: ['.spv'], format: 'Binary', description: 'SPSS Output Document' },
235
235
  { id: 'mdb', extensions: ['.mdb'], format: 'Binary', description: 'Microsoft Access DB' },
236
+ { id: 'webm', extensions: ['.webm'], format: 'Binary', description: 'WebM is an audiovisual media file format.' },
236
237
  ];
237
238
  const binaryFormatIds = exports.languageExtensionDefinitions.filter((d) => d.format === 'Binary').map((d) => d.id);
238
239
  exports.binaryLanguages = new Set(['binary', 'image', 'video', 'fonts'].concat(binaryFormatIds));
@@ -32,6 +32,7 @@ export interface DictionaryFileDefinitionInternalWithSource extends DictionaryFi
32
32
  export type DictionaryDefinitionInternalWithSource = DictionaryDefinitionInternal & {
33
33
  readonly __source: string;
34
34
  };
35
+ export declare function cleanCSpellSettingsInternal(parts?: OptionalOrUndefined<Partial<CSpellSettingsInternal>>): CSpellSettingsInternal;
35
36
  export declare function createCSpellSettingsInternal(parts?: OptionalOrUndefined<Partial<CSpellSettingsInternal>>): CSpellSettingsInternal;
36
37
  export declare function isCSpellSettingsInternal(cs: CSpellSettingsInternal | CSpellSettingsWithSourceTrace | OptionalOrUndefined<CSpellSettingsInternal | CSpellSettingsWithSourceTrace>): cs is CSpellSettingsInternal;
37
38
  export declare function isDictionaryDefinitionInlineInternal(def: DictionaryDefinitionInternal | DictionaryDefinitionInline | DictionaryDefinition): def is DictionaryDefinitionInlineInternal;
@@ -1,8 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isDictionaryDefinitionInlineInternal = exports.isCSpellSettingsInternal = exports.createCSpellSettingsInternal = exports.SymbolCSpellSettingsInternal = void 0;
3
+ exports.isDictionaryDefinitionInlineInternal = exports.isCSpellSettingsInternal = exports.createCSpellSettingsInternal = exports.cleanCSpellSettingsInternal = exports.SymbolCSpellSettingsInternal = void 0;
4
4
  const util_1 = require("../util/util");
5
5
  exports.SymbolCSpellSettingsInternal = Symbol('CSpellSettingsInternal');
6
+ function cleanCSpellSettingsInternal(parts = {}) {
7
+ const csi = (0, util_1.clean)(parts);
8
+ Object.assign(csi, { [exports.SymbolCSpellSettingsInternal]: true });
9
+ return csi;
10
+ }
11
+ exports.cleanCSpellSettingsInternal = cleanCSpellSettingsInternal;
6
12
  function createCSpellSettingsInternal(parts = {}) {
7
13
  return (0, util_1.clean)({
8
14
  ...parts,
@@ -18,7 +24,7 @@ function isDictionaryDefinitionInlineInternal(def) {
18
24
  if (def.path)
19
25
  return false;
20
26
  const defInline = def;
21
- return !!(defInline.words || defInline.flagWords || defInline.ignoreWords);
27
+ return !!(defInline.words || defInline.flagWords || defInline.ignoreWords || defInline.suggestWords);
22
28
  }
23
29
  exports.isDictionaryDefinitionInlineInternal = isDictionaryDefinitionInlineInternal;
24
30
  //# sourceMappingURL=CSpellSettingsInternalDef.js.map
@@ -63,6 +63,11 @@ function mergeList(left, right) {
63
63
  }
64
64
  const emptyWords = [];
65
65
  Object.freeze(emptyWords);
66
+ const cachedMerges = new WeakMap();
67
+ function _mergeWordsCached(left, right) {
68
+ const map = (0, AutoResolve_1.autoResolveWeak)(cachedMerges, left, () => new WeakMap());
69
+ return (0, AutoResolve_1.autoResolveWeak)(map, right, () => left.concat(right));
70
+ }
66
71
  function mergeWordsCached(left, right) {
67
72
  if (left === undefined)
68
73
  return !right || right.length ? right : emptyWords;
@@ -72,7 +77,7 @@ function mergeWordsCached(left, right) {
72
77
  return !right || right.length ? right : emptyWords;
73
78
  if (!right.length)
74
79
  return !left || left.length ? left : emptyWords;
75
- return left.concat(right);
80
+ return _mergeWordsCached(left, right);
76
81
  }
77
82
  function mergeObjects(left, right) {
78
83
  if (left === undefined)
@@ -115,22 +120,21 @@ function merge(left, right) {
115
120
  if (doesLeftHaveRightAncestor(_left, _right)) {
116
121
  return _left;
117
122
  }
118
- const leftId = _left.id || _left.languageId || '';
119
- const rightId = _right.id || _right.languageId || '';
120
123
  const includeRegExpList = takeRightOtherwiseLeft(_left.includeRegExpList, _right.includeRegExpList);
121
124
  const optionals = includeRegExpList?.length ? { includeRegExpList } : {};
122
125
  const version = max(_left.version, _right.version);
123
- const settings = (0, CSpellSettingsInternalDef_1.createCSpellSettingsInternal)({
126
+ const settings = (0, CSpellSettingsInternalDef_1.cleanCSpellSettingsInternal)({
124
127
  ..._left,
125
128
  ..._right,
126
129
  ...optionals,
127
130
  version,
128
- id: [leftId, rightId].join('|'),
129
- name: [_left.name || '', _right.name || ''].join('|'),
131
+ id: undefined,
132
+ name: undefined,
130
133
  words: mergeWordsCached(_left.words, _right.words),
131
134
  userWords: mergeWordsCached(_left.userWords, _right.userWords),
132
135
  flagWords: mergeWordsCached(_left.flagWords, _right.flagWords),
133
136
  ignoreWords: mergeWordsCached(_left.ignoreWords, _right.ignoreWords),
137
+ suggestWords: mergeWordsCached(_left.suggestWords, _right.suggestWords),
134
138
  enabledLanguageIds: replaceIfNotEmpty(_left.enabledLanguageIds, _right.enabledLanguageIds),
135
139
  enableFiletypes: mergeList(_left.enableFiletypes, _right.enableFiletypes),
136
140
  ignoreRegExpList: mergeListUnique(_left.ignoreRegExpList, _right.ignoreRegExpList),
@@ -240,7 +244,7 @@ function toInternalSettings(settings) {
240
244
  const { dictionaryDefinitions: defs, ...rest } = settings;
241
245
  const dictionaryDefinitions = (0, DictionarySettings_1.mapDictDefsToInternal)(defs, filenameToDirectory(settings.source?.filename) || resolveCwd());
242
246
  const setting = dictionaryDefinitions ? { ...rest, dictionaryDefinitions } : rest;
243
- return (0, CSpellSettingsInternalDef_1.createCSpellSettingsInternal)(setting);
247
+ return (0, CSpellSettingsInternalDef_1.cleanCSpellSettingsInternal)(setting);
244
248
  }
245
249
  exports.toInternalSettings = toInternalSettings;
246
250
  function filenameToDirectory(filename) {
@@ -259,10 +263,8 @@ function checkFilenameMatchesGlob(filename, globs) {
259
263
  }
260
264
  exports.checkFilenameMatchesGlob = checkFilenameMatchesGlob;
261
265
  function mergeSources(left, right) {
262
- const { source: a = { name: 'left' } } = left;
263
- const { source: b = { name: 'right' } } = right;
264
266
  return {
265
- name: [left.name || a.name, right.name || b.name].join('|'),
267
+ name: 'merged',
266
268
  sources: [left, right],
267
269
  };
268
270
  }
@@ -26,6 +26,7 @@ export declare function normalizeDictionaryDefs(settings: NormalizeDictionaryDef
26
26
  words?: string[];
27
27
  flagWords?: string[];
28
28
  ignoreWords?: string[];
29
+ suggestWords?: string[];
29
30
  parser?: string;
30
31
  }>[] | undefined;
31
32
  }>;
@@ -1,4 +1,4 @@
1
- import type { CSpellUserSettings } from '@cspell/cspell-types';
1
+ import type { CSpellUserSettings, DictionaryDefinitionInline } from '@cspell/cspell-types';
2
2
  import type { Sequence } from 'gensequence';
3
3
  import type { ExtendedSuggestion } from '../Models/Suggestion';
4
4
  export type CSpellUserSettingsKeys = keyof CSpellUserSettings;
@@ -26,6 +26,7 @@ declare function parseIgnoreWords(match: string): CSpellUserSettings;
26
26
  declare function parseIgnoreRegExp(match: string): CSpellUserSettings;
27
27
  declare function getPossibleInDocSettings(text: string): Sequence<RegExpExecArray>;
28
28
  declare function getWordsFromDocument(text: string): string[];
29
+ export declare function extractInDocDictionary(settings: CSpellUserSettings): DictionaryDefinitionInline | undefined;
29
30
  export declare function getIgnoreWordsFromDocument(text: string): string[];
30
31
  export declare function getIgnoreRegExpFromDocument(text: string): (string | RegExp)[];
31
32
  /**
@@ -38,6 +39,7 @@ export declare const internal: {
38
39
  parseCompoundWords: typeof parseCompoundWords;
39
40
  parseIgnoreRegExp: typeof parseIgnoreRegExp;
40
41
  parseIgnoreWords: typeof parseIgnoreWords;
42
+ staticInDocumentDictionaryName: string;
41
43
  };
42
44
  export {};
43
45
  //# sourceMappingURL=InDocSettings.d.ts.map
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.internal = exports.getIgnoreRegExpFromDocument = exports.getIgnoreWordsFromDocument = exports.regExSpellingGuardLine = exports.regExSpellingGuardNext = exports.regExSpellingGuardBlock = exports.validateInDocumentSettings = exports.getInDocumentSettings = void 0;
26
+ exports.internal = exports.getIgnoreRegExpFromDocument = exports.getIgnoreWordsFromDocument = exports.extractInDocDictionary = exports.regExSpellingGuardLine = exports.regExSpellingGuardNext = exports.regExSpellingGuardBlock = exports.validateInDocumentSettings = exports.getInDocumentSettings = void 0;
27
27
  const sync_1 = require("@cspell/cspell-pipe/sync");
28
28
  const gensequence_1 = require("gensequence");
29
29
  const SpellingDictionary_1 = require("../SpellingDictionary");
@@ -92,12 +92,35 @@ const dictInDocSettings = (0, SpellingDictionary_1.createSpellingDictionary)(all
92
92
  });
93
93
  const EmptyWords = [];
94
94
  Object.freeze(EmptyWords);
95
+ const staticInDocumentDictionaryName = `[in-document-dict]`;
95
96
  function getInDocumentSettings(text) {
96
- const settings = getPossibleInDocSettings(text)
97
+ const collectedSettings = getPossibleInDocSettings(text)
97
98
  .concatMap((a) => parseSettingMatch(a))
98
99
  .reduce((s, setting) => {
99
100
  return (0, CSpellSettingsServer_1.mergeInDocSettings)(s, setting);
100
101
  }, { id: 'in-doc-settings' });
102
+ const { words, flagWords, ignoreWords, suggestWords, dictionaries = [], dictionaryDefinitions = [], ...rest } = collectedSettings;
103
+ const dict = (words || flagWords || ignoreWords || suggestWords) &&
104
+ (0, util_1.clean)({
105
+ name: staticInDocumentDictionaryName,
106
+ words,
107
+ flagWords,
108
+ ignoreWords,
109
+ suggestWords,
110
+ });
111
+ const dictSettings = dict
112
+ ? {
113
+ dictionaries: dictionaries.concat(staticInDocumentDictionaryName),
114
+ dictionaryDefinitions: dictionaryDefinitions.concat(dict),
115
+ }
116
+ : (0, util_1.clean)({
117
+ dictionaries: dictionaries.length ? dictionaries : undefined,
118
+ dictionaryDefinitions: dictionaryDefinitions.length ? dictionaryDefinitions : undefined,
119
+ });
120
+ const settings = {
121
+ ...rest,
122
+ ...dictSettings,
123
+ };
101
124
  // console.log('InDocSettings: %o', settings);
102
125
  return settings;
103
126
  }
@@ -124,6 +147,7 @@ const settingParsers = [
124
147
  exports.regExSpellingGuardBlock = /(\bc?spell(?:-?checker)?::?)\s*disable(?!-line|-next)\b[\s\S]*?((?:\1\s*enable\b)|$)/gi;
125
148
  exports.regExSpellingGuardNext = /\bc?spell(?:-?checker)?::?\s*disable-next\b.*\s\s?.*/gi;
126
149
  exports.regExSpellingGuardLine = /^.*\bc?spell(?:-?checker)?::?\s*disable-line\b.*/gim;
150
+ const emptySettings = Object.freeze({});
127
151
  const issueMessages = {
128
152
  unknownDirective: 'Unknown CSpell directive',
129
153
  };
@@ -183,11 +207,11 @@ function parseSettingMatch(matchArray) {
183
207
  }
184
208
  function parseCompoundWords(match) {
185
209
  const allowCompoundWords = /enable/i.test(match);
186
- return { id: 'in-doc-allowCompoundWords', allowCompoundWords };
210
+ return { allowCompoundWords };
187
211
  }
188
212
  function parseCaseSensitive(match) {
189
213
  const caseSensitive = /enable/i.test(match);
190
- return { id: 'in-doc-caseSensitive', caseSensitive };
214
+ return { caseSensitive };
191
215
  }
192
216
  function parseWords(match) {
193
217
  const words = match
@@ -195,20 +219,22 @@ function parseWords(match) {
195
219
  .split(/[,\s;]+/g)
196
220
  .slice(1)
197
221
  .filter((a) => !!a);
198
- return { id: 'in-doc-words', words };
222
+ return { words };
199
223
  }
200
224
  function parseLocale(match) {
201
225
  const parts = match.trim().split(/[\s,]+/);
202
226
  const language = parts.slice(1).join(',');
203
- return language ? { id: 'in-doc-local', language } : {};
227
+ return language ? { language } : emptySettings;
204
228
  }
205
229
  function parseIgnoreWords(match) {
206
230
  const wordsSetting = parseWords(match);
207
- return (0, util_1.clean)({ id: 'in-doc-ignore', ignoreWords: wordsSetting.words });
231
+ const ignoreWords = wordsSetting.words;
232
+ return ignoreWords && ignoreWords.length ? { ignoreWords } : emptySettings;
208
233
  }
209
234
  function parseFlagWords(match) {
210
235
  const wordsSetting = parseWords(match);
211
- return (0, util_1.clean)({ id: 'in-doc-forbid', flagWords: wordsSetting.words });
236
+ const flagWords = wordsSetting.words;
237
+ return flagWords && flagWords.length ? { flagWords } : emptySettings;
212
238
  }
213
239
  function parseRegEx(match) {
214
240
  const patterns = [match.replace(/^[^\s]+\s+/, '')].map((a) => {
@@ -222,22 +248,22 @@ function parseRegEx(match) {
222
248
  }
223
249
  function parseIgnoreRegExp(match) {
224
250
  const ignoreRegExpList = parseRegEx(match);
225
- return { id: 'in-doc-ignoreRegExp', ignoreRegExpList };
251
+ return { ignoreRegExpList };
226
252
  }
227
253
  function parseIncludeRegExp(match) {
228
254
  const includeRegExpList = parseRegEx(match);
229
- return { id: 'in-doc-includeRegExp', includeRegExpList };
255
+ return { includeRegExpList };
230
256
  }
231
257
  function parseDictionaries(match) {
232
258
  const dictionaries = match.split(/[,\s]+/g).slice(1);
233
- return { id: 'in-doc-dictionaries', dictionaries };
259
+ return { dictionaries };
234
260
  }
235
261
  function getPossibleInDocSettings(text) {
236
262
  return (0, gensequence_1.genSequence)(regExInFileSettings).concatMap((regexp) => Text.match(regexp, text));
237
263
  }
238
264
  function getWordsFromDocument(text) {
239
- const { words = EmptyWords } = getInDocumentSettings(text);
240
- return words;
265
+ const dict = extractInDocDictionary(getInDocumentSettings(text));
266
+ return dict?.words || EmptyWords;
241
267
  }
242
268
  function parseEnable(_match) {
243
269
  // Do nothing. Enable / Disable is handled in a different way.
@@ -247,9 +273,15 @@ function parseDisable(_match) {
247
273
  // Do nothing. Enable / Disable is handled in a different way.
248
274
  return {};
249
275
  }
276
+ function extractInDocDictionary(settings) {
277
+ const inDocDicts = settings.dictionaryDefinitions?.filter((def) => def.name === staticInDocumentDictionaryName);
278
+ const dict = inDocDicts?.[0];
279
+ return dict;
280
+ }
281
+ exports.extractInDocDictionary = extractInDocDictionary;
250
282
  function getIgnoreWordsFromDocument(text) {
251
- const { ignoreWords = EmptyWords } = getInDocumentSettings(text);
252
- return ignoreWords;
283
+ const dict = extractInDocDictionary(getInDocumentSettings(text));
284
+ return dict?.ignoreWords || EmptyWords;
253
285
  }
254
286
  exports.getIgnoreWordsFromDocument = getIgnoreWordsFromDocument;
255
287
  function getIgnoreRegExpFromDocument(text) {
@@ -267,5 +299,6 @@ exports.internal = {
267
299
  parseCompoundWords,
268
300
  parseIgnoreRegExp,
269
301
  parseIgnoreWords,
302
+ staticInDocumentDictionaryName,
270
303
  };
271
304
  //# sourceMappingURL=InDocSettings.js.map
@@ -29,7 +29,7 @@ function getDictionaryInternalSync(settings) {
29
29
  }
30
30
  exports.getDictionaryInternalSync = getDictionaryInternalSync;
31
31
  function _getDictionaryInternal(settings, spellDictionaries) {
32
- const { words = emptyWords, userWords = emptyWords, flagWords = emptyWords, ignoreWords = emptyWords } = settings;
32
+ const { words = emptyWords, userWords = emptyWords, flagWords = emptyWords, ignoreWords = emptyWords, suggestWords = emptyWords, } = settings;
33
33
  const settingsWordsDictionary = (0, cspell_dictionary_1.createSpellingDictionary)(words, '[words]', 'From Settings `words`', {
34
34
  caseSensitive: true,
35
35
  weightMap: undefined,
@@ -42,12 +42,14 @@ function _getDictionaryInternal(settings, spellDictionaries) {
42
42
  : undefined;
43
43
  const ignoreWordsDictionary = (0, cspell_dictionary_1.createIgnoreWordsDictionary)(ignoreWords, '[ignoreWords]', 'From Settings `ignoreWords`');
44
44
  const flagWordsDictionary = (0, cspell_dictionary_1.createForbiddenWordsDictionary)(flagWords, '[flagWords]', 'From Settings `flagWords`');
45
+ const suggestWordsDictionary = (0, cspell_dictionary_1.createSuggestDictionary)(suggestWords, '[suggestWords]', 'From Settings `suggestWords`');
45
46
  const dictionaries = [
46
47
  ...spellDictionaries,
47
48
  settingsWordsDictionary,
48
49
  settingsUserWordsDictionary,
49
50
  ignoreWordsDictionary,
50
51
  flagWordsDictionary,
52
+ suggestWordsDictionary,
51
53
  ].filter(util_1.isDefined);
52
54
  return (0, cspell_dictionary_1.createCollection)(dictionaries, 'dictionary collection');
53
55
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cspell-lib",
3
- "version": "6.24.0",
3
+ "version": "6.26.0",
4
4
  "description": "A library of useful functions used across various cspell tools.",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -48,19 +48,19 @@
48
48
  },
49
49
  "homepage": "https://github.com/streetsidesoftware/cspell#readme",
50
50
  "dependencies": {
51
- "@cspell/cspell-bundled-dicts": "6.24.0",
52
- "@cspell/cspell-pipe": "6.24.0",
53
- "@cspell/cspell-types": "6.24.0",
54
- "@cspell/strong-weak-map": "6.24.0",
51
+ "@cspell/cspell-bundled-dicts": "6.26.0",
52
+ "@cspell/cspell-pipe": "6.26.0",
53
+ "@cspell/cspell-types": "6.26.0",
54
+ "@cspell/strong-weak-map": "6.26.0",
55
55
  "clear-module": "^4.1.2",
56
56
  "comment-json": "^4.2.3",
57
57
  "configstore": "^5.0.1",
58
58
  "cosmiconfig": "^8.0.0",
59
- "cspell-dictionary": "6.24.0",
60
- "cspell-glob": "6.24.0",
61
- "cspell-grammar": "6.24.0",
62
- "cspell-io": "6.24.0",
63
- "cspell-trie-lib": "6.24.0",
59
+ "cspell-dictionary": "6.26.0",
60
+ "cspell-glob": "6.26.0",
61
+ "cspell-grammar": "6.26.0",
62
+ "cspell-io": "6.26.0",
63
+ "cspell-trie-lib": "6.26.0",
64
64
  "fast-equals": "^4.0.3",
65
65
  "find-up": "^5.0.0",
66
66
  "gensequence": "^4.0.3",
@@ -89,8 +89,8 @@
89
89
  "jest": "^29.4.2",
90
90
  "lorem-ipsum": "^2.0.8",
91
91
  "rollup": "^3.15.0",
92
- "rollup-plugin-dts": "^5.1.1",
92
+ "rollup-plugin-dts": "^5.2.0",
93
93
  "ts-jest": "^29.0.5"
94
94
  },
95
- "gitHead": "0d1e8bf9426cd0bfb814df4f61da12d8aee57ddd"
95
+ "gitHead": "a72f603f4f1afbe237f938b1a23d7cbe2a07d86f"
96
96
  }