cspell-lib 9.4.0 → 9.6.1

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.
Files changed (115) hide show
  1. package/README.md +6 -6
  2. package/dist/cspell-rpc/api.d.ts +28 -0
  3. package/dist/cspell-rpc/api.js +6 -0
  4. package/dist/cspell-rpc/client.d.ts +17 -0
  5. package/dist/cspell-rpc/client.js +20 -0
  6. package/dist/cspell-rpc/index.d.ts +7 -0
  7. package/dist/cspell-rpc/index.js +4 -0
  8. package/dist/cspell-rpc/server.d.ts +16 -0
  9. package/dist/cspell-rpc/server.js +37 -0
  10. package/dist/cspell-rpc/spellCheckFile.d.ts +2 -0
  11. package/dist/cspell-rpc/spellCheckFile.js +2 -0
  12. package/dist/index.d.ts +2 -0
  13. package/dist/index.js +2 -0
  14. package/dist/lib/Settings/CSpellSettingsServer.d.ts +4 -2
  15. package/dist/lib/Settings/CSpellSettingsServer.js +10 -2
  16. package/dist/lib/Settings/Controller/ImportError.js +3 -0
  17. package/dist/lib/Settings/Controller/configLoader/configLoader.d.ts +6 -4
  18. package/dist/lib/Settings/Controller/configLoader/configLoader.js +12 -6
  19. package/dist/lib/Settings/Controller/configLoader/configLocations.js +1 -0
  20. package/dist/lib/Settings/Controller/configLoader/defaultSettings.js +1 -1
  21. package/dist/lib/Settings/Controller/configLoader/normalizeRawSettings.js +1 -1
  22. package/dist/lib/Settings/Controller/configLoader/types.d.ts +1 -1
  23. package/dist/lib/Settings/DefaultSettings.d.ts +1 -1
  24. package/dist/lib/Settings/DefaultSettings.js +1 -1
  25. package/dist/lib/Settings/InDocSettings.d.ts +0 -3
  26. package/dist/lib/Settings/InDocSettings.js +2 -3
  27. package/dist/lib/Settings/LanguageSettings.js +3 -3
  28. package/dist/lib/Settings/RegExpPatterns.js +2 -2
  29. package/dist/lib/Settings/TextDocumentSettings.d.ts +1 -1
  30. package/dist/lib/Settings/cfgStore.d.ts +1 -1
  31. package/dist/lib/Settings/index.d.ts +3 -1
  32. package/dist/lib/Settings/index.js +2 -1
  33. package/dist/lib/Settings/internal/CSpellSettingsInternalDef.d.ts +18 -0
  34. package/dist/lib/{Models → Settings/internal}/CSpellSettingsInternalDef.js +1 -10
  35. package/dist/lib/Settings/{DictionarySettings.d.ts → internal/DictionarySettings.d.ts} +3 -2
  36. package/dist/lib/Settings/{DictionarySettings.js → internal/DictionarySettings.js} +20 -10
  37. package/dist/lib/{Models/CSpellSettingsInternalDef.d.ts → Settings/internal/InternalDictionaryDef.d.ts} +2 -17
  38. package/dist/lib/Settings/internal/InternalDictionaryDef.js +10 -0
  39. package/dist/lib/Settings/internal/index.d.ts +6 -0
  40. package/dist/lib/Settings/internal/index.js +4 -0
  41. package/dist/lib/Settings/link.js +1 -1
  42. package/dist/lib/Settings/mergeCache.d.ts +1 -1
  43. package/dist/lib/Settings/mergeList.d.ts +1 -1
  44. package/dist/lib/Settings/sanitizeSettings.d.ts +11 -0
  45. package/dist/lib/Settings/sanitizeSettings.js +254 -0
  46. package/dist/lib/Settings/util/settingsToJson.d.ts +28 -0
  47. package/dist/lib/Settings/util/settingsToJson.js +125 -0
  48. package/dist/lib/SpellingDictionary/Dictionaries.d.ts +1 -1
  49. package/dist/lib/SpellingDictionary/Dictionaries.js +1 -1
  50. package/dist/lib/SpellingDictionary/DictionaryController/DictionaryLoader.d.ts +1 -1
  51. package/dist/lib/SpellingDictionary/DictionaryController/DictionaryLoader.js +115 -28
  52. package/dist/lib/SpellingDictionary/DictionaryLoader.d.ts +1 -1
  53. package/dist/lib/index.d.ts +2 -2
  54. package/dist/lib/index.js +2 -2
  55. package/dist/lib/perf/index.d.ts +1 -0
  56. package/dist/lib/perf/index.js +1 -0
  57. package/dist/lib/spellCheckFile.d.ts +11 -1
  58. package/dist/lib/spellCheckFile.js +24 -4
  59. package/dist/lib/suggestions.d.ts +1 -1
  60. package/dist/lib/suggestions.js +3 -3
  61. package/dist/lib/textValidation/cleanValidationIssue.d.ts +3 -0
  62. package/dist/lib/textValidation/cleanValidationIssue.js +21 -0
  63. package/dist/lib/textValidation/determineTextDocumentSettings.d.ts +1 -1
  64. package/dist/lib/textValidation/docValidator.d.ts +6 -3
  65. package/dist/lib/textValidation/docValidator.js +29 -6
  66. package/dist/lib/textValidation/isRandomString.d.ts +1 -1
  67. package/dist/lib/textValidation/lineValidatorFactory.js +13 -5
  68. package/dist/lib/textValidation/settingsToValidateOptions.d.ts +1 -1
  69. package/dist/lib/textValidation/traceWord.d.ts +1 -0
  70. package/dist/lib/textValidation/traceWord.js +1 -0
  71. package/dist/lib/trace.d.ts +2 -1
  72. package/dist/lib/trace.js +2 -2
  73. package/dist/lib/util/clone.d.ts +35 -0
  74. package/dist/lib/util/clone.js +76 -0
  75. package/dist/lib/util/errors.js +1 -1
  76. package/dist/lib/util/memoizeLastCall.d.ts +13 -0
  77. package/dist/lib/util/{memorizeLastCall.js → memoizeLastCall.js} +2 -2
  78. package/dist/lib/util/memoizeWeak.d.ts +6 -0
  79. package/dist/lib/util/{memorizerWeak.js → memoizeWeak.js} +2 -2
  80. package/dist/lib/util/text.js +6 -4
  81. package/dist/lib/util/textRegex.d.ts +2 -2
  82. package/dist/lib/util/textRegex.js +2 -2
  83. package/dist/rpc/Future.d.ts +18 -0
  84. package/dist/rpc/Future.js +49 -0
  85. package/dist/rpc/MessagePortEvents.d.ts +56 -0
  86. package/dist/rpc/MessagePortEvents.js +94 -0
  87. package/dist/rpc/assert.d.ts +14 -0
  88. package/dist/rpc/assert.js +21 -0
  89. package/dist/rpc/client.d.ts +186 -0
  90. package/dist/rpc/client.js +364 -0
  91. package/dist/rpc/errors.d.ts +24 -0
  92. package/dist/rpc/errors.js +47 -0
  93. package/dist/rpc/index.d.ts +11 -0
  94. package/dist/rpc/index.js +6 -0
  95. package/dist/rpc/messagePort.d.ts +34 -0
  96. package/dist/rpc/messagePort.js +2 -0
  97. package/dist/rpc/models.d.ts +134 -0
  98. package/dist/rpc/models.js +2 -0
  99. package/dist/rpc/modelsHelpers.d.ts +56 -0
  100. package/dist/rpc/modelsHelpers.js +117 -0
  101. package/dist/rpc/notify.d.ts +79 -0
  102. package/dist/rpc/notify.js +135 -0
  103. package/dist/rpc/protocol.d.ts +21 -0
  104. package/dist/rpc/protocol.js +17 -0
  105. package/dist/rpc/server.d.ts +39 -0
  106. package/dist/rpc/server.js +146 -0
  107. package/dist/rpc/types.d.ts +9 -0
  108. package/dist/rpc/types.js +2 -0
  109. package/dist/rpc.d.ts +2 -0
  110. package/dist/rpc.js +2 -0
  111. package/package.json +41 -26
  112. package/dist/lib/perf/perf.d.ts +0 -20
  113. package/dist/lib/perf/perf.js +0 -32
  114. package/dist/lib/util/memorizeLastCall.d.ts +0 -13
  115. package/dist/lib/util/memorizerWeak.d.ts +0 -6
@@ -1,11 +1,11 @@
1
1
  import * as path from 'node:path';
2
2
  import { mapDictionaryInformationToWeightMap } from 'cspell-trie-lib';
3
- import { isDictionaryDefinitionInlineInternal } from '../Models/CSpellSettingsInternalDef.js';
4
- import { createAutoResolveWeakWeakCache } from '../util/AutoResolve.js';
5
- import { resolveRelativeTo } from '../util/resolveFile.js';
6
- import { toFilePathOrHref } from '../util/url.js';
7
- import { clean } from '../util/util.js';
8
- import { createDictionaryReferenceCollection } from './DictionaryReferenceCollection.js';
3
+ import { createAutoResolveWeakWeakCache } from '../../util/AutoResolve.js';
4
+ import { resolveRelativeTo } from '../../util/resolveFile.js';
5
+ import { toFilePathOrHref } from '../../util/url.js';
6
+ import { clean } from '../../util/util.js';
7
+ import { createDictionaryReferenceCollection } from '../DictionaryReferenceCollection.js';
8
+ import { isDictionaryDefinitionInlineInternal } from './InternalDictionaryDef.js';
9
9
  /**
10
10
  * Combines the list of desired dictionaries with the list of dictionary
11
11
  * definitions. Order does not matter, but the number of leading `!` does.
@@ -27,10 +27,12 @@ function fixPath(def) {
27
27
  return def;
28
28
  }
29
29
  const newPath = fixDicPath(def.path, def.file);
30
+ const newBTriePath = def.btrie ? fixDicPath(def.btrie, def.file) : undefined;
30
31
  return {
31
32
  ...def,
32
33
  file: undefined,
33
34
  path: newPath,
35
+ btrie: newBTriePath,
34
36
  };
35
37
  }
36
38
  function fixDicPath(defPath, defFile) {
@@ -97,21 +99,26 @@ class _DictionaryDefinitionInternalWithSource {
97
99
  ignoreForbiddenWords;
98
100
  scope;
99
101
  __source;
100
- ddi;
102
+ #ddi;
103
+ #def;
101
104
  constructor(def, sourceURL) {
102
105
  this.sourceURL = sourceURL;
106
+ this.#def = def;
103
107
  this.__source = sourceURL.href;
104
108
  // this bit of assignment is to have the compiler help use if any new fields are added.
105
109
  const defAll = def;
106
- const { path: relPath = '', file = '', addWords, description, dictionaryInformation, type, repMap, noSuggest, ignoreForbiddenWords, scope, supportNonStrictSearches, useCompounds, } = defAll;
110
+ const { path: relPath = '', file = '', btrie, addWords, description, dictionaryInformation, type, repMap, noSuggest, ignoreForbiddenWords, scope, supportNonStrictSearches, useCompounds, } = defAll;
107
111
  const defaultPath = sourceURL;
108
112
  const filePath = fixDicPath(relPath, file);
109
113
  const name = determineName(filePath, def);
110
114
  const resolvedPath = toFilePathOrHref(resolveRelativeTo(filePath, defaultPath));
115
+ let bTriePath = btrie ? fixDicPath(btrie, file) : undefined;
116
+ bTriePath = bTriePath ? toFilePathOrHref(resolveRelativeTo(bTriePath, defaultPath)) : undefined;
111
117
  const ddi = {
112
118
  name,
113
119
  file: undefined,
114
120
  path: resolvedPath,
121
+ btrie: bTriePath,
115
122
  addWords,
116
123
  description,
117
124
  dictionaryInformation,
@@ -124,7 +131,7 @@ class _DictionaryDefinitionInternalWithSource {
124
131
  useCompounds,
125
132
  };
126
133
  Object.assign(this, clean(ddi));
127
- this.ddi = ddi;
134
+ this.#ddi = ddi;
128
135
  this.name = ddi.name;
129
136
  this.file = ddi.file;
130
137
  this.path = ddi.path;
@@ -136,7 +143,10 @@ class _DictionaryDefinitionInternalWithSource {
136
143
  return this._weightMap;
137
144
  }
138
145
  toJSON() {
139
- return this.ddi;
146
+ return this.#ddi;
147
+ }
148
+ __getOriginalDefinition() {
149
+ return this.#def;
140
150
  }
141
151
  }
142
152
  //# sourceMappingURL=DictionarySettings.js.map
@@ -1,17 +1,5 @@
1
- import type { AdvancedCSpellSettingsWithSourceTrace, CSpellSettingsWithSourceTrace, DictionaryDefinition, DictionaryDefinitionAugmented, DictionaryDefinitionCustom, DictionaryDefinitionInline, DictionaryDefinitionPreferred, DictionaryDefinitionSimple, Parser } from '@cspell/cspell-types';
1
+ import type { DictionaryDefinition, DictionaryDefinitionAugmented, DictionaryDefinitionCustom, DictionaryDefinitionInline, DictionaryDefinitionPreferred, DictionaryDefinitionSimple } from '@cspell/cspell-types';
2
2
  import type { WeightMap } from 'cspell-trie-lib';
3
- import type { OptionalOrUndefined } from '../util/types.js';
4
- export declare const SymbolCSpellSettingsInternal: unique symbol;
5
- export interface CSpellSettingsInternal extends Omit<AdvancedCSpellSettingsWithSourceTrace, 'dictionaryDefinitions'> {
6
- [SymbolCSpellSettingsInternal]: true;
7
- dictionaryDefinitions?: DictionaryDefinitionInternal[];
8
- }
9
- export interface CSpellSettingsInternalFinalized extends CSpellSettingsInternal {
10
- parserFn: Parser | undefined;
11
- finalized: true;
12
- ignoreRegExpList: RegExp[];
13
- includeRegExpList: RegExp[];
14
- }
15
3
  type DictionaryDefinitionCustomUniqueFields = Omit<DictionaryDefinitionCustom, keyof DictionaryDefinitionPreferred>;
16
4
  export type DictionaryDefinitionInternal = DictionaryFileDefinitionInternal | DictionaryDefinitionInlineInternal | DictionaryDefinitionSimpleInternal;
17
5
  export type DictionaryDefinitionInlineInternal = DictionaryDefinitionInline & {
@@ -36,10 +24,7 @@ export interface DictionaryFileDefinitionInternalWithSource extends DictionaryFi
36
24
  export type DictionaryDefinitionInternalWithSource = DictionaryDefinitionInternal & {
37
25
  readonly __source: string;
38
26
  };
39
- export declare function cleanCSpellSettingsInternal(parts?: OptionalOrUndefined<Partial<CSpellSettingsInternal>>): CSpellSettingsInternal;
40
- export declare function createCSpellSettingsInternal(parts?: OptionalOrUndefined<Partial<CSpellSettingsInternal>>): CSpellSettingsInternal;
41
- export declare function isCSpellSettingsInternal(cs: CSpellSettingsInternal | CSpellSettingsWithSourceTrace | OptionalOrUndefined<CSpellSettingsInternal | CSpellSettingsWithSourceTrace>): cs is CSpellSettingsInternal;
42
27
  export declare function isDictionaryDefinitionInlineInternal(def: DictionaryDefinitionInternal | DictionaryDefinitionInline | DictionaryDefinition): def is DictionaryDefinitionInlineInternal;
43
28
  export declare function isDictionaryFileDefinitionInternal(def: DictionaryDefinitionInternal | DictionaryDefinitionInline | DictionaryDefinition): def is DictionaryFileDefinitionInternal;
44
29
  export {};
45
- //# sourceMappingURL=CSpellSettingsInternalDef.d.ts.map
30
+ //# sourceMappingURL=InternalDictionaryDef.d.ts.map
@@ -0,0 +1,10 @@
1
+ export function isDictionaryDefinitionInlineInternal(def) {
2
+ if (def.path)
3
+ return false;
4
+ const defInline = def;
5
+ return !!(defInline.words || defInline.flagWords || defInline.ignoreWords || defInline.suggestWords);
6
+ }
7
+ export function isDictionaryFileDefinitionInternal(def) {
8
+ return !!(def.path || def.file);
9
+ }
10
+ //# sourceMappingURL=InternalDictionaryDef.js.map
@@ -0,0 +1,6 @@
1
+ export type { CSpellSettingsInternal, CSpellSettingsInternalFinalized } from './CSpellSettingsInternalDef.js';
2
+ export { cleanCSpellSettingsInternal, createCSpellSettingsInternal, isCSpellSettingsInternal, } from './CSpellSettingsInternalDef.js';
3
+ export { calcDictionaryDefsToLoad, filterDictDefsToLoad, mapDictDefsToInternal, mapDictDefToInternal, } from './DictionarySettings.js';
4
+ export type { DictionaryDefinitionInlineInternal, DictionaryDefinitionInternal, DictionaryDefinitionSimpleInternal, DictionaryFileDefinitionInternal, } from './InternalDictionaryDef.js';
5
+ export { isDictionaryDefinitionInlineInternal, isDictionaryFileDefinitionInternal } from './InternalDictionaryDef.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,4 @@
1
+ export { cleanCSpellSettingsInternal, createCSpellSettingsInternal, isCSpellSettingsInternal, } from './CSpellSettingsInternalDef.js';
2
+ export { calcDictionaryDefsToLoad, filterDictDefsToLoad, mapDictDefsToInternal, mapDictDefToInternal, } from './DictionarySettings.js';
3
+ export { isDictionaryDefinitionInlineInternal, isDictionaryFileDefinitionInternal } from './InternalDictionaryDef.js';
4
+ //# sourceMappingURL=index.js.map
@@ -78,7 +78,7 @@ export async function removePathsFromGlobalImports(paths) {
78
78
  return c === Path.sep || c === Path.posix.sep;
79
79
  }
80
80
  function matchFilename(pathToRemove) {
81
- return Path.dirname(pathToRemove) != '.'
81
+ return Path.dirname(pathToRemove) !== '.'
82
82
  ? ({ filename }) => compareFilenames(filename, pathToRemove)
83
83
  : () => false;
84
84
  }
@@ -1,4 +1,4 @@
1
- import { CacheStats } from '../util/AutoResolve.js';
1
+ import type { CacheStats } from '../util/AutoResolve.js';
2
2
  interface IDisposable {
3
3
  dispose(): void;
4
4
  }
@@ -1,4 +1,4 @@
1
- import { CacheStats } from '../util/AutoResolve.js';
1
+ import type { CacheStats } from '../util/AutoResolve.js';
2
2
  /**
3
3
  * Merges two lists and removes duplicates. Order is NOT preserved.
4
4
  */
@@ -0,0 +1,11 @@
1
+ import type { CSpellSettingsWithSourceTrace } from '@cspell/cspell-types';
2
+ import type { CSpellSettingsInternal, CSpellSettingsInternalFinalized } from './internal/index.js';
3
+ type CloneableSettings = CSpellSettingsWithSourceTrace | CSpellSettingsInternal | CSpellSettingsInternalFinalized;
4
+ /**
5
+ * Sanitize settings for export by removing any internal only properties.
6
+ *
7
+ * @param settings - the input settings
8
+ */
9
+ export declare function cloneSettingsForExport(settings: Readonly<CloneableSettings>): CSpellSettingsWithSourceTrace;
10
+ export {};
11
+ //# sourceMappingURL=sanitizeSettings.d.ts.map
@@ -0,0 +1,254 @@
1
+ import { cloneInto, copy0, copy1, skip } from '../util/clone.js';
2
+ /**
3
+ * Sanitize settings for export by removing any internal only properties.
4
+ *
5
+ * @param settings - the input settings
6
+ */
7
+ export function cloneSettingsForExport(settings) {
8
+ const result = {};
9
+ const handlers = getHandlers();
10
+ cloneInto(settings, result, handlers);
11
+ return result;
12
+ }
13
+ const handlers = {
14
+ $schema: skip,
15
+ __importRef: copyImportRefField,
16
+ __imports: copyImportsField,
17
+ source: copySourceField,
18
+ id: skip,
19
+ version: skip,
20
+ allowCompoundWords: copy1,
21
+ cache: skip,
22
+ caseSensitive: copy1,
23
+ description: skip,
24
+ dictionaries: copy1,
25
+ dictionaryDefinitions: copyDictionaryDefinitions,
26
+ enabled: copy1,
27
+ enabledLanguageIds: copy1,
28
+ enableFiletypes: copy1,
29
+ enabledFileTypes: copy1,
30
+ enableGlobDot: copy1,
31
+ failFast: copy1,
32
+ features: skip,
33
+ files: copyGlobsSettingsFields,
34
+ flagWords: copy1,
35
+ gitignoreRoot: copy1,
36
+ globRoot: copy1,
37
+ ignorePaths: copyGlobsSettingsFields,
38
+ ignoreRegExpList: copy1,
39
+ ignoreWords: copy1,
40
+ ignoreRandomStrings: copy1,
41
+ import: skip,
42
+ includeRegExpList: copy1,
43
+ language: copy1,
44
+ languageId: copy1,
45
+ languageSettings: copyLanguageSettings,
46
+ loadDefaultConfiguration: copy1,
47
+ maxDuplicateProblems: copy1,
48
+ maxFileSize: copy1,
49
+ maxNumberOfProblems: copy1,
50
+ minWordLength: copy1,
51
+ minRandomLength: copy1,
52
+ name: skip,
53
+ noConfigSearch: copy1,
54
+ noSuggestDictionaries: copy1,
55
+ numSuggestions: copy1,
56
+ overrides: copyOverrides,
57
+ patterns: copyPatternsField,
58
+ pnpFiles: skip,
59
+ readonly: skip,
60
+ reporters: skip,
61
+ showStatus: copy1,
62
+ spellCheckDelayMs: copy1,
63
+ suggestionNumChanges: copy1,
64
+ suggestionsTimeout: copy1,
65
+ suggestWords: copy1,
66
+ unknownWords: copy1,
67
+ useGitignore: copy1,
68
+ usePnP: skip,
69
+ userWords: copy1,
70
+ validateDirectives: copy1,
71
+ words: copy1,
72
+ // Experimental
73
+ parser: skip,
74
+ };
75
+ function getHandlers() {
76
+ return handlers;
77
+ }
78
+ function copyImportRefField(src, dst, key) {
79
+ const ref = src[key];
80
+ if (!ref)
81
+ return;
82
+ dst[key] = copyImportFileRef(ref);
83
+ }
84
+ function copyImportsField(src, dst, key) {
85
+ const imports = src[key];
86
+ if (!imports)
87
+ return;
88
+ dst[key] = new Map([...imports.entries()].map(([k, v]) => [k, copyImportFileRef(v)]));
89
+ }
90
+ function copyImportFileRef(src) {
91
+ const ref = { filename: src.filename };
92
+ copy0(src, ref, 'error');
93
+ return ref;
94
+ }
95
+ function copySourceField(src, dst, key) {
96
+ if (!src[key])
97
+ return;
98
+ dst[key] = copySource(src[key]);
99
+ }
100
+ function copySource(src) {
101
+ const source = { name: src.name };
102
+ cpy(src, source, 'filename');
103
+ return source;
104
+ }
105
+ function copyGlobsSettingsFields(src, dst, key) {
106
+ const globs = src[key];
107
+ if (!globs)
108
+ return;
109
+ dst[key] = copyGlobOrGlobs(globs);
110
+ }
111
+ function copyGlobsOverrideFields(src, dst, key) {
112
+ const globs = src[key];
113
+ if (!globs)
114
+ return;
115
+ dst[key] = copyGlobOrGlobs(globs);
116
+ }
117
+ function copyGlobOrGlobs(globOrGlobs) {
118
+ if (Array.isArray(globOrGlobs)) {
119
+ return globOrGlobs.map(copyGlob);
120
+ }
121
+ return copyGlob(globOrGlobs);
122
+ }
123
+ function copyGlob(glob) {
124
+ if (typeof glob === 'string') {
125
+ return glob;
126
+ }
127
+ const g = { glob: glob.glob };
128
+ cpy(glob, g, 'root');
129
+ return g;
130
+ }
131
+ function copyDictionaryDefinitions(src, dst, key) {
132
+ const defs = src[key];
133
+ if (!defs)
134
+ return;
135
+ dst[key] = defs.map(copyDictionaryDefinition);
136
+ }
137
+ function copyDictionaryDefinition(src) {
138
+ const def = { name: src.name };
139
+ cpy(src, def, 'path');
140
+ cpy(src, def, 'type');
141
+ cpy(src, def, 'description');
142
+ return def;
143
+ }
144
+ function copyLanguageSettings(src, dst, key) {
145
+ const langSettings = src[key];
146
+ if (!langSettings)
147
+ return;
148
+ dst[key] = langSettings.map((src) => {
149
+ const dst = { languageId: src.languageId };
150
+ copyLanguageSetting(src, dst);
151
+ return dst;
152
+ });
153
+ }
154
+ function cpy(src, dst, key) {
155
+ const value = src[key];
156
+ if (value === undefined)
157
+ return;
158
+ dst[key] = value;
159
+ }
160
+ const LanguageSettingsHandlers = {
161
+ id: cpy,
162
+ locale: cpy,
163
+ local: cpy,
164
+ allowCompoundWords: copy1,
165
+ caseSensitive: copy1,
166
+ description: skip,
167
+ dictionaries: copy1,
168
+ dictionaryDefinitions: copyDictionaryDefinitions,
169
+ enabled: copy1,
170
+ flagWords: copy1,
171
+ ignoreRegExpList: copy1,
172
+ ignoreWords: copy1,
173
+ includeRegExpList: copy1,
174
+ languageId: copy1,
175
+ name: skip,
176
+ noSuggestDictionaries: copy1,
177
+ patterns: copyPatternsField,
178
+ suggestWords: copy1,
179
+ unknownWords: copy1,
180
+ words: copy1,
181
+ // Experimental
182
+ parser: skip,
183
+ };
184
+ function copyLanguageSetting(src, dst) {
185
+ cloneInto(src, dst, LanguageSettingsHandlers);
186
+ }
187
+ const RegExpPatternDefinitionHandlers = {
188
+ name: cpy,
189
+ pattern: copy1,
190
+ description: cpy,
191
+ };
192
+ function copyPatternsField(src, dst, key) {
193
+ const patterns = src[key];
194
+ if (!patterns)
195
+ return;
196
+ dst[key] = patterns.map((p) => {
197
+ const dst = { pattern: p.pattern, name: p.name };
198
+ copyRegExpPatternDefinition(p, dst);
199
+ return dst;
200
+ });
201
+ }
202
+ function copyRegExpPatternDefinition(src, dst) {
203
+ cloneInto(src, dst, RegExpPatternDefinitionHandlers);
204
+ }
205
+ const OverridesHandlers = {
206
+ id: copy1,
207
+ allowCompoundWords: copy1,
208
+ caseSensitive: copy1,
209
+ description: copy1,
210
+ dictionaries: copy1,
211
+ dictionaryDefinitions: copyDictionaryDefinitions,
212
+ enabled: copy1,
213
+ enabledFileTypes: copy1,
214
+ enabledLanguageIds: copy1,
215
+ enableFiletypes: copy1,
216
+ filename: copyGlobsOverrideFields,
217
+ flagWords: copy1,
218
+ ignoreRandomStrings: copy1,
219
+ ignoreRegExpList: copy1,
220
+ ignoreWords: copy1,
221
+ includeRegExpList: copy1,
222
+ language: copy1,
223
+ languageId: copy1,
224
+ languageSettings: copyLanguageSettings,
225
+ loadDefaultConfiguration: copy1,
226
+ maxDuplicateProblems: copy1,
227
+ maxFileSize: copy1,
228
+ maxNumberOfProblems: copy1,
229
+ minRandomLength: copy1,
230
+ minWordLength: copy1,
231
+ name: skip,
232
+ noSuggestDictionaries: copy1,
233
+ numSuggestions: copy1,
234
+ patterns: copyPatternsField,
235
+ pnpFiles: skip,
236
+ suggestionNumChanges: copy1,
237
+ suggestionsTimeout: copy1,
238
+ suggestWords: copy1,
239
+ unknownWords: copy1,
240
+ usePnP: skip,
241
+ words: copy1,
242
+ parser: skip,
243
+ };
244
+ function copyOverrides(src, dst, key) {
245
+ const overrides = src[key];
246
+ if (!overrides)
247
+ return;
248
+ dst[key] = overrides.map((src) => {
249
+ const dst = {};
250
+ cloneInto(src, dst, OverridesHandlers);
251
+ return dst;
252
+ });
253
+ }
254
+ //# sourceMappingURL=sanitizeSettings.js.map
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Walks a value and converts it into a JSON-serializable representation.
3
+ *
4
+ * This function recursively traverses complex structures and normalizes them
5
+ * so they can be safely passed to {@link JSON.stringify}. The following
6
+ * conversions are applied:
7
+ *
8
+ * - Primitive types (`string`, `number`, `boolean`, `undefined`) are returned as-is.
9
+ * - `null` is returned as `null`.
10
+ * - Objects implementing `toJSON()` are serialized using that method.
11
+ * - `RegExp` instances are converted to their string form (e.g. `/pattern/gi`).
12
+ * - `Map` instances become arrays of `[key, value]` entry pairs, with both keys
13
+ * and values processed through `walkToJSONObj`.
14
+ * - `Set` instances become arrays of their values, each processed through
15
+ * `walkToJSONObj`.
16
+ * - Boxed `String` objects are converted to primitive strings.
17
+ * - Arrays are mapped element-wise via `walkToJSONObj`.
18
+ * - Plain objects are converted to new objects whose property values are
19
+ * processed via `walkToJSONObj`.
20
+ * - `bigint` values are currently returned as-is (note: not natively supported
21
+ * by `JSON.stringify`).
22
+ * - Functions are converted to `undefined`.
23
+ *
24
+ * @param value - The value to transform into a JSON-serializable structure.
25
+ * @returns A JSON-serializable representation of the input value.
26
+ */
27
+ export declare function walkToJSONObj(value: unknown): unknown;
28
+ //# sourceMappingURL=settingsToJson.d.ts.map
@@ -0,0 +1,125 @@
1
+ /* eslint-disable unicorn/no-null */
2
+ /**
3
+ * Walks a value and converts it into a JSON-serializable representation.
4
+ *
5
+ * This function recursively traverses complex structures and normalizes them
6
+ * so they can be safely passed to {@link JSON.stringify}. The following
7
+ * conversions are applied:
8
+ *
9
+ * - Primitive types (`string`, `number`, `boolean`, `undefined`) are returned as-is.
10
+ * - `null` is returned as `null`.
11
+ * - Objects implementing `toJSON()` are serialized using that method.
12
+ * - `RegExp` instances are converted to their string form (e.g. `/pattern/gi`).
13
+ * - `Map` instances become arrays of `[key, value]` entry pairs, with both keys
14
+ * and values processed through `walkToJSONObj`.
15
+ * - `Set` instances become arrays of their values, each processed through
16
+ * `walkToJSONObj`.
17
+ * - Boxed `String` objects are converted to primitive strings.
18
+ * - Arrays are mapped element-wise via `walkToJSONObj`.
19
+ * - Plain objects are converted to new objects whose property values are
20
+ * processed via `walkToJSONObj`.
21
+ * - `bigint` values are currently returned as-is (note: not natively supported
22
+ * by `JSON.stringify`).
23
+ * - Functions are converted to `undefined`.
24
+ *
25
+ * @param value - The value to transform into a JSON-serializable structure.
26
+ * @returns A JSON-serializable representation of the input value.
27
+ */
28
+ export function walkToJSONObj(value) {
29
+ const mapVisited = new WeakMap();
30
+ function walk(value) {
31
+ switch (typeof value) {
32
+ case 'string':
33
+ case 'number':
34
+ case 'boolean':
35
+ case 'undefined': {
36
+ return value;
37
+ }
38
+ case 'object': {
39
+ return walkObj(value);
40
+ }
41
+ case 'bigint': {
42
+ return value; // return as is for now
43
+ }
44
+ case 'function': {
45
+ return undefined; // `[function ${value.name || 'anonymous'}]`;
46
+ }
47
+ default: {
48
+ return undefined;
49
+ }
50
+ }
51
+ }
52
+ /**
53
+ * Adds the value/result pair to the visited map.
54
+ * @param value - the original object
55
+ * @param result - the processed or to be processed result
56
+ * @returns result
57
+ */
58
+ function rememberObj(value, result) {
59
+ mapVisited.set(value, result);
60
+ return result;
61
+ }
62
+ /**
63
+ * Adds an array to the visited map and processes its entries in place.
64
+ * @param value - the original object
65
+ * @param entries - the array entries, it will be modified in place.
66
+ * @param map - an optional mapping function to apply to each entry.
67
+ * @returns the processed array.
68
+ */
69
+ function rememberArrayAndMapValuesInPlace(value, entries, map = (entry) => walk(entry)) {
70
+ const result = rememberObj(value, entries);
71
+ for (let i = 0; i < entries.length; i++) {
72
+ entries[i] = map(entries[i], i);
73
+ }
74
+ return result;
75
+ }
76
+ /**
77
+ * Walk an object.
78
+ * This function handles circular references.
79
+ *
80
+ * It does this by adding a placeholder to the visited map before processing the object.
81
+ * The placeholder is updated in place with the final result after processing.
82
+ *
83
+ * @param value - the object to walk
84
+ * @returns the walked object
85
+ */
86
+ function walkObj(value) {
87
+ const visited = mapVisited.get(value);
88
+ // Note: it is possible that the value is in mapVisited but maps to undefined.
89
+ // It is not worth the cost of checking for that case since the result will be the same.
90
+ if (visited !== undefined) {
91
+ return visited;
92
+ }
93
+ if (value === null) {
94
+ return null;
95
+ }
96
+ if ('toJSON' in value && typeof value.toJSON === 'function') {
97
+ // We trust the toJSON implementation to handle circular references itself.
98
+ return rememberObj(value, value.toJSON());
99
+ }
100
+ if (value instanceof RegExp) {
101
+ return rememberObj(value, value.toString());
102
+ }
103
+ if (value instanceof Map) {
104
+ return rememberArrayAndMapValuesInPlace(value, [...value.entries()], (entry) => {
105
+ entry[0] = walk(entry[0]);
106
+ entry[1] = walk(entry[1]);
107
+ return entry;
108
+ });
109
+ }
110
+ if (value instanceof Set) {
111
+ return rememberArrayAndMapValuesInPlace(value, [...value.values()]);
112
+ }
113
+ if (value instanceof String) {
114
+ return rememberObj(value, value.toString());
115
+ }
116
+ if (Array.isArray(value)) {
117
+ return rememberArrayAndMapValuesInPlace(value, [...value]);
118
+ }
119
+ // Plain object - process its properties
120
+ const obj = rememberObj(value, {});
121
+ return Object.assign(obj, Object.fromEntries(Object.entries(value).map(([key, val]) => [key, walk(val)])));
122
+ }
123
+ return walk(value);
124
+ }
125
+ //# sourceMappingURL=settingsToJson.js.map
@@ -1,6 +1,6 @@
1
1
  import type { CSpellSettings } from '@cspell/cspell-types';
2
2
  import type { SpellingDictionary, SpellingDictionaryCollection } from 'cspell-dictionary';
3
- import type { CSpellSettingsInternal, DictionaryDefinitionInternal } from '../Models/CSpellSettingsInternalDef.js';
3
+ import type { CSpellSettingsInternal, DictionaryDefinitionInternal } from '../Settings/index.js';
4
4
  export declare function loadDictionaryDefs(defsToLoad: DictionaryDefinitionInternal[]): Promise<SpellingDictionary>[];
5
5
  export declare function refreshDictionaryCache(maxAge?: number): Promise<void>;
6
6
  export declare function getDictionaryInternal(settings: CSpellSettingsInternal): Promise<SpellingDictionaryCollection>;
@@ -1,5 +1,5 @@
1
1
  import { createCollection, createForbiddenWordsDictionary, createIgnoreWordsDictionary, createSpellingDictionary, createSuggestDictionary, } from 'cspell-dictionary';
2
- import { calcDictionaryDefsToLoad } from '../Settings/DictionarySettings.js';
2
+ import { calcDictionaryDefsToLoad } from '../Settings/index.js';
3
3
  import { isDefined } from '../util/util.js';
4
4
  import { loadDictionary, refreshCacheEntries } from './DictionaryLoader.js';
5
5
  export function loadDictionaryDefs(defsToLoad) {
@@ -1,6 +1,6 @@
1
1
  import type { SpellingDictionary } from 'cspell-dictionary';
2
2
  import type { VFileSystem } from 'cspell-io';
3
- import type { DictionaryDefinitionInternal } from '../../Models/CSpellSettingsInternalDef.js';
3
+ import type { DictionaryDefinitionInternal } from '../../Settings/index.js';
4
4
  export type LoadOptions = DictionaryDefinitionInternal;
5
5
  export declare class DictionaryLoader {
6
6
  private fs;