cspell-lib 6.25.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.
@@ -120,8 +120,6 @@ function merge(left, right) {
120
120
  if (doesLeftHaveRightAncestor(_left, _right)) {
121
121
  return _left;
122
122
  }
123
- const leftId = _left.id || _left.languageId || '';
124
- const rightId = _right.id || _right.languageId || '';
125
123
  const includeRegExpList = takeRightOtherwiseLeft(_left.includeRegExpList, _right.includeRegExpList);
126
124
  const optionals = includeRegExpList?.length ? { includeRegExpList } : {};
127
125
  const version = max(_left.version, _right.version);
@@ -130,8 +128,8 @@ function merge(left, right) {
130
128
  ..._right,
131
129
  ...optionals,
132
130
  version,
133
- id: [leftId, rightId].join('|'),
134
- name: [_left.name || '', _right.name || ''].join('|'),
131
+ id: undefined,
132
+ name: undefined,
135
133
  words: mergeWordsCached(_left.words, _right.words),
136
134
  userWords: mergeWordsCached(_left.userWords, _right.userWords),
137
135
  flagWords: mergeWordsCached(_left.flagWords, _right.flagWords),
@@ -265,10 +263,8 @@ function checkFilenameMatchesGlob(filename, globs) {
265
263
  }
266
264
  exports.checkFilenameMatchesGlob = checkFilenameMatchesGlob;
267
265
  function mergeSources(left, right) {
268
- const { source: a = { name: 'left' } } = left;
269
- const { source: b = { name: 'right' } } = right;
270
266
  return {
271
- name: [left.name || a.name, right.name || b.name].join('|'),
267
+ name: 'merged',
272
268
  sources: [left, right],
273
269
  };
274
270
  }
@@ -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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cspell-lib",
3
- "version": "6.25.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.25.0",
52
- "@cspell/cspell-pipe": "6.25.0",
53
- "@cspell/cspell-types": "6.25.0",
54
- "@cspell/strong-weak-map": "6.25.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.25.0",
60
- "cspell-glob": "6.25.0",
61
- "cspell-grammar": "6.25.0",
62
- "cspell-io": "6.25.0",
63
- "cspell-trie-lib": "6.25.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",
@@ -92,5 +92,5 @@
92
92
  "rollup-plugin-dts": "^5.2.0",
93
93
  "ts-jest": "^29.0.5"
94
94
  },
95
- "gitHead": "fd7541605e07c43887191097d58ab58d87fac8fd"
95
+ "gitHead": "a72f603f4f1afbe237f938b1a23d7cbe2a07d86f"
96
96
  }