cspell-lib 9.6.0 → 9.6.2

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 (98) hide show
  1. package/dist/cspell-rpc/api.d.ts +28 -0
  2. package/dist/cspell-rpc/api.js +6 -0
  3. package/dist/cspell-rpc/client.d.ts +17 -0
  4. package/dist/cspell-rpc/client.js +20 -0
  5. package/dist/cspell-rpc/index.d.ts +7 -0
  6. package/dist/cspell-rpc/index.js +4 -0
  7. package/dist/cspell-rpc/server.d.ts +16 -0
  8. package/dist/cspell-rpc/server.js +37 -0
  9. package/dist/cspell-rpc/spellCheckFile.d.ts +2 -0
  10. package/dist/cspell-rpc/spellCheckFile.js +2 -0
  11. package/dist/index.d.ts +2 -0
  12. package/dist/index.js +2 -0
  13. package/dist/lib/Settings/CSpellSettingsServer.d.ts +4 -2
  14. package/dist/lib/Settings/CSpellSettingsServer.js +10 -2
  15. package/dist/lib/Settings/Controller/configLoader/configLoader.js +1 -1
  16. package/dist/lib/Settings/Controller/configLoader/defaultSettings.js +1 -1
  17. package/dist/lib/Settings/Controller/configLoader/normalizeRawSettings.js +1 -1
  18. package/dist/lib/Settings/Controller/configLoader/types.d.ts +1 -1
  19. package/dist/lib/Settings/DefaultSettings.d.ts +1 -1
  20. package/dist/lib/Settings/DefaultSettings.js +1 -1
  21. package/dist/lib/Settings/InDocSettings.d.ts +0 -3
  22. package/dist/lib/Settings/InDocSettings.js +2 -3
  23. package/dist/lib/Settings/LanguageSettings.js +3 -3
  24. package/dist/lib/Settings/TextDocumentSettings.d.ts +1 -1
  25. package/dist/lib/Settings/index.d.ts +3 -1
  26. package/dist/lib/Settings/index.js +2 -1
  27. package/dist/lib/Settings/internal/CSpellSettingsInternalDef.d.ts +18 -0
  28. package/dist/lib/{Models → Settings/internal}/CSpellSettingsInternalDef.js +1 -10
  29. package/dist/lib/Settings/{DictionarySettings.d.ts → internal/DictionarySettings.d.ts} +3 -2
  30. package/dist/lib/Settings/{DictionarySettings.js → internal/DictionarySettings.js} +14 -9
  31. package/dist/lib/{Models/CSpellSettingsInternalDef.d.ts → Settings/internal/InternalDictionaryDef.d.ts} +2 -17
  32. package/dist/lib/Settings/internal/InternalDictionaryDef.js +10 -0
  33. package/dist/lib/Settings/internal/index.d.ts +6 -0
  34. package/dist/lib/Settings/internal/index.js +4 -0
  35. package/dist/lib/Settings/sanitizeSettings.d.ts +11 -0
  36. package/dist/lib/Settings/sanitizeSettings.js +254 -0
  37. package/dist/lib/Settings/util/settingsToJson.d.ts +28 -0
  38. package/dist/lib/Settings/util/settingsToJson.js +125 -0
  39. package/dist/lib/SpellingDictionary/Dictionaries.d.ts +1 -1
  40. package/dist/lib/SpellingDictionary/Dictionaries.js +1 -1
  41. package/dist/lib/SpellingDictionary/DictionaryController/DictionaryLoader.d.ts +1 -1
  42. package/dist/lib/SpellingDictionary/DictionaryController/DictionaryLoader.js +99 -20
  43. package/dist/lib/SpellingDictionary/DictionaryLoader.d.ts +1 -1
  44. package/dist/lib/index.d.ts +2 -2
  45. package/dist/lib/index.js +2 -2
  46. package/dist/lib/perf/index.d.ts +1 -1
  47. package/dist/lib/perf/index.js +1 -1
  48. package/dist/lib/spellCheckFile.d.ts +10 -0
  49. package/dist/lib/spellCheckFile.js +24 -4
  50. package/dist/lib/suggestions.js +3 -3
  51. package/dist/lib/textValidation/cleanValidationIssue.d.ts +3 -0
  52. package/dist/lib/textValidation/cleanValidationIssue.js +21 -0
  53. package/dist/lib/textValidation/determineTextDocumentSettings.d.ts +1 -1
  54. package/dist/lib/textValidation/docValidator.d.ts +4 -1
  55. package/dist/lib/textValidation/docValidator.js +18 -1
  56. package/dist/lib/textValidation/settingsToValidateOptions.d.ts +1 -1
  57. package/dist/lib/util/clone.d.ts +35 -0
  58. package/dist/lib/util/clone.js +76 -0
  59. package/dist/lib/util/memoizeLastCall.d.ts +13 -0
  60. package/dist/lib/util/{memorizeLastCall.js → memoizeLastCall.js} +2 -2
  61. package/dist/lib/util/memoizeWeak.d.ts +6 -0
  62. package/dist/lib/util/{memorizerWeak.js → memoizeWeak.js} +2 -2
  63. package/dist/lib/util/text.js +6 -4
  64. package/dist/lib/util/textRegex.d.ts +2 -2
  65. package/dist/lib/util/textRegex.js +2 -2
  66. package/dist/rpc/Future.d.ts +18 -0
  67. package/dist/rpc/Future.js +49 -0
  68. package/dist/rpc/MessagePortEvents.d.ts +56 -0
  69. package/dist/rpc/MessagePortEvents.js +94 -0
  70. package/dist/rpc/assert.d.ts +14 -0
  71. package/dist/rpc/assert.js +21 -0
  72. package/dist/rpc/client.d.ts +186 -0
  73. package/dist/rpc/client.js +364 -0
  74. package/dist/rpc/errors.d.ts +24 -0
  75. package/dist/rpc/errors.js +47 -0
  76. package/dist/rpc/index.d.ts +11 -0
  77. package/dist/rpc/index.js +6 -0
  78. package/dist/rpc/messagePort.d.ts +34 -0
  79. package/dist/rpc/messagePort.js +2 -0
  80. package/dist/rpc/models.d.ts +134 -0
  81. package/dist/rpc/models.js +2 -0
  82. package/dist/rpc/modelsHelpers.d.ts +56 -0
  83. package/dist/rpc/modelsHelpers.js +117 -0
  84. package/dist/rpc/notify.d.ts +79 -0
  85. package/dist/rpc/notify.js +135 -0
  86. package/dist/rpc/protocol.d.ts +21 -0
  87. package/dist/rpc/protocol.js +17 -0
  88. package/dist/rpc/server.d.ts +39 -0
  89. package/dist/rpc/server.js +146 -0
  90. package/dist/rpc/types.d.ts +9 -0
  91. package/dist/rpc/types.js +2 -0
  92. package/dist/rpc.d.ts +2 -0
  93. package/dist/rpc.js +2 -0
  94. package/package.json +34 -21
  95. package/dist/lib/perf/performance.d.ts +0 -16
  96. package/dist/lib/perf/performance.js +0 -34
  97. package/dist/lib/util/memorizeLastCall.d.ts +0 -13
  98. package/dist/lib/util/memorizerWeak.d.ts +0 -6
@@ -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;
@@ -1,9 +1,61 @@
1
+ var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
2
+ if (value !== null && value !== void 0) {
3
+ if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
4
+ var dispose, inner;
5
+ if (async) {
6
+ if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
7
+ dispose = value[Symbol.asyncDispose];
8
+ }
9
+ if (dispose === void 0) {
10
+ if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
11
+ dispose = value[Symbol.dispose];
12
+ if (async) inner = dispose;
13
+ }
14
+ if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
15
+ if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
16
+ env.stack.push({ value: value, dispose: dispose, async: async });
17
+ }
18
+ else if (async) {
19
+ env.stack.push({ async: true });
20
+ }
21
+ return value;
22
+ };
23
+ var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
24
+ return function (env) {
25
+ function fail(e) {
26
+ env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
27
+ env.hasError = true;
28
+ }
29
+ var r, s = 0;
30
+ function next() {
31
+ while (r = env.stack.pop()) {
32
+ try {
33
+ if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
34
+ if (r.dispose) {
35
+ var result = r.dispose.call(r.value);
36
+ if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
37
+ }
38
+ else s |= 1;
39
+ }
40
+ catch (e) {
41
+ fail(e);
42
+ }
43
+ }
44
+ if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
45
+ if (env.hasError) throw env.error;
46
+ }
47
+ return next();
48
+ };
49
+ })(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
50
+ var e = new Error(message);
51
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
52
+ });
1
53
  import { opConcatMap, opFilter, opMap, pipe } from '@cspell/cspell-pipe/sync';
2
54
  import { StrongWeakMap } from '@cspell/strong-weak-map';
3
55
  import { createFailedToLoadDictionary, createInlineSpellingDictionary, createSpellingDictionary, createSpellingDictionaryFromTrieFile, } from 'cspell-dictionary';
4
56
  import { compareStats, toFileURL, urlBasename } from 'cspell-io';
5
- import { isDictionaryDefinitionInlineInternal, isDictionaryFileDefinitionInternal, } from '../../Models/CSpellSettingsInternalDef.js';
6
- import { measurePerfFn } from '../../perf/index.js';
57
+ import { measurePerf } from '../../perf/index.js';
58
+ import { isDictionaryDefinitionInlineInternal, isDictionaryFileDefinitionInternal } from '../../Settings/index.js';
7
59
  import { AutoResolveWeakCache, AutoResolveWeakWeakCache } from '../../util/AutoResolve.js';
8
60
  import { toError } from '../../util/errors.js';
9
61
  import { SimpleCache } from '../../util/simpleCache.js';
@@ -187,36 +239,63 @@ async function load(reader, uri, options) {
187
239
  return loader(reader, uri, options);
188
240
  }
189
241
  async function legacyWordList(reader, filename, options) {
190
- const lines = await reader.readLines(filename);
191
- return measurePerfFn('legacyWords', () => _legacyWordListSync(lines, filename, options));
192
- }
193
- function _legacyWordListSync(lines, filename, options) {
194
- const words = pipe(lines,
195
- // Remove comments
196
- opMap((line) => line.replaceAll(/#.*/g, '')),
197
- // Split on everything else
198
- opConcatMap((line) => line.split(/[^\w\p{L}\p{M}'’]+/gu)), opFilter((word) => !!word));
199
- return createSpellingDictionary(words, options.name, filename.toString(), options, true);
242
+ const env_1 = { stack: [], error: void 0, hasError: false };
243
+ try {
244
+ const lines = await reader.readLines(filename);
245
+ const _ = __addDisposableResource(env_1, measurePerf('legacyWords'), false);
246
+ const words = pipe(lines,
247
+ // Remove comments
248
+ opMap((line) => line.replaceAll(/#.*/g, '')),
249
+ // Split on everything else
250
+ opConcatMap((line) => line.split(/[^\w\p{L}\p{M}'’]+/gu)), opFilter((word) => !!word));
251
+ return createSpellingDictionary(words, options.name, filename.toString(), options, true);
252
+ }
253
+ catch (e_1) {
254
+ env_1.error = e_1;
255
+ env_1.hasError = true;
256
+ }
257
+ finally {
258
+ __disposeResources(env_1);
259
+ }
200
260
  }
201
261
  async function wordsPerLineWordList(reader, filename, options) {
202
262
  const lines = await reader.readLines(filename);
203
- return measurePerfFn('wordsPerLineWordList', () => _wordsPerLineWordList(lines, filename.toString(), options));
204
- }
205
- function _wordsPerLineWordList(lines, filename, options) {
206
263
  const words = pipe(lines,
207
264
  // Remove comments
208
265
  opMap((line) => line.replaceAll(/#.*/g, '')),
209
266
  // Split on everything else
210
267
  opConcatMap((line) => line.split(/\s+/gu)), opFilter((word) => !!word));
211
- return createSpellingDictionary(words, options.name, filename, options, true);
268
+ return createSpellingDictionary(words, options.name, filename.href, options, true);
212
269
  }
213
270
  async function loadSimpleWordList(reader, filename, options) {
214
- const lines = await reader.readLines(filename);
215
- return measurePerfFn('loadSimpleWordList', () => createSpellingDictionary(lines, options.name, filename.href, options));
271
+ const env_2 = { stack: [], error: void 0, hasError: false };
272
+ try {
273
+ const lines = await reader.readLines(filename);
274
+ const _ = __addDisposableResource(env_2, measurePerf('loadSimpleWordList'), false);
275
+ return createSpellingDictionary(lines, options.name, filename.href, options);
276
+ }
277
+ catch (e_2) {
278
+ env_2.error = e_2;
279
+ env_2.hasError = true;
280
+ }
281
+ finally {
282
+ __disposeResources(env_2);
283
+ }
216
284
  }
217
285
  async function loadTrie(reader, filename, options) {
218
- const content = await reader.read(filename);
219
- return measurePerfFn('loadTrie', () => createSpellingDictionaryFromTrieFile(content, options.name, filename.href, options));
286
+ const env_3 = { stack: [], error: void 0, hasError: false };
287
+ try {
288
+ const content = await reader.read(filename);
289
+ const _ = __addDisposableResource(env_3, measurePerf('loadTrie'), false);
290
+ return createSpellingDictionaryFromTrieFile(content, options.name, filename.href, options);
291
+ }
292
+ catch (e_3) {
293
+ env_3.error = e_3;
294
+ env_3.hasError = true;
295
+ }
296
+ finally {
297
+ __disposeResources(env_3);
298
+ }
220
299
  }
221
300
  function toLines(content) {
222
301
  return content.split(/\n|\r\n|\r/);
@@ -1,6 +1,6 @@
1
1
  import type { SpellingDictionary } from 'cspell-dictionary';
2
2
  import type { VFileSystem } from '../fileSystem.js';
3
- import type { DictionaryDefinitionInternal } from '../Models/CSpellSettingsInternalDef.js';
3
+ import type { DictionaryDefinitionInternal } from '../Settings/index.js';
4
4
  import { DictionaryLoader } from './DictionaryController/index.js';
5
5
  export type { LoadOptions } from './DictionaryController/index.js';
6
6
  export declare function getDictionaryLoader(vfs?: VFileSystem): DictionaryLoader;
@@ -13,11 +13,11 @@ export { createTextDocument, updateTextDocument } from './Models/TextDocument.js
13
13
  export type { PerfTimer } from './perf/index.js';
14
14
  export { createPerfTimer } from './perf/index.js';
15
15
  export type { ConfigurationDependencies, CSpellConfigFile, ICSpellConfigFile, ImportFileRefWithError, } from './Settings/index.js';
16
- export { calcOverrideSettings, checkFilenameMatchesGlob, createConfigLoader, currentSettingsFileVersion, defaultConfigFilenames, defaultFileName, ENV_CSPELL_GLOB_ROOT, extractDependencies, extractImportErrors, finalizeSettings, getCachedFileSize, getDefaultBundledSettingsAsync, getDefaultConfigLoader, getDefaultSettings, getGlobalSettings, getGlobalSettingsAsync, getSources, ImportError, loadConfig, loadPnP, mergeInDocSettings, mergeSettings, readConfigFile, readRawSettings, readSettings, readSettingsFiles, resolveConfigFileImports, searchForConfig, sectionCSpell, } from './Settings/index.js';
16
+ export { calcOverrideSettings, checkFilenameMatchesGlob, createConfigLoader, currentSettingsFileVersion, defaultConfigFilenames, defaultFileName, ENV_CSPELL_GLOB_ROOT, extractDependencies, extractImportErrors, finalizeSettings, getCachedFileSize, getDefaultBundledSettingsAsync, getDefaultConfigLoader, getDefaultSettings, getGlobalSettings, getGlobalSettingsAsync, getSources, ImportError, loadConfig, loadPnP, mergeInDocSettings, mergeSettings, readConfigFile, readRawSettings, readSettings, readSettingsFiles, resolveConfigFileImports, searchForConfig, sectionCSpell, toCSpellSettingsWithOutSourceTrace, } from './Settings/index.js';
17
17
  export { defaultFileName as defaultSettingsFilename } from './Settings/index.js';
18
18
  export * as Link from './Settings/index.link.js';
19
19
  export { combineTextAndLanguageSettings, combineTextAndLanguageSettings as constructSettingsForText, } from './Settings/TextDocumentSettings.js';
20
- export { determineFinalDocumentSettings, type DetermineFinalDocumentSettingsResult, spellCheckDocument, spellCheckFile, type SpellCheckFileOptions, type SpellCheckFilePerf, type SpellCheckFileResult, } from './spellCheckFile.js';
20
+ export { determineFinalDocumentSettings, type DetermineFinalDocumentSettingsResult, spellCheckDocument, spellCheckDocumentRPC, spellCheckFile, type SpellCheckFileOptions, type SpellCheckFilePerf, type SpellCheckFileResult, } from './spellCheckFile.js';
21
21
  export { CompoundWordsMethod, createSpellingDictionary, createCollection as createSpellingDictionaryCollection, isSpellingDictionaryLoadError, refreshDictionaryCache, type SpellingDictionary, type SpellingDictionaryCollection, SpellingDictionaryLoadError, type SuggestionCollector, type SuggestionResult, type SuggestOptions, } from './SpellingDictionary/index.js';
22
22
  export type { SuggestedWord, SuggestionOptions, SuggestionsForWordResult } from './suggestions.js';
23
23
  export { SuggestionError, suggestionsForWord, suggestionsForWords } from './suggestions.js';
package/dist/lib/index.js CHANGED
@@ -7,11 +7,11 @@ export { getLanguagesForBasename as getLanguageIdsForBaseFilename, getLanguagesF
7
7
  export { getDictionary } from './getDictionary.js';
8
8
  export { createTextDocument, updateTextDocument } from './Models/TextDocument.js';
9
9
  export { createPerfTimer } from './perf/index.js';
10
- export { calcOverrideSettings, checkFilenameMatchesGlob, createConfigLoader, currentSettingsFileVersion, defaultConfigFilenames, defaultFileName, ENV_CSPELL_GLOB_ROOT, extractDependencies, extractImportErrors, finalizeSettings, getCachedFileSize, getDefaultBundledSettingsAsync, getDefaultConfigLoader, getDefaultSettings, getGlobalSettings, getGlobalSettingsAsync, getSources, ImportError, loadConfig, loadPnP, mergeInDocSettings, mergeSettings, readConfigFile, readRawSettings, readSettings, readSettingsFiles, resolveConfigFileImports, searchForConfig, sectionCSpell, } from './Settings/index.js';
10
+ export { calcOverrideSettings, checkFilenameMatchesGlob, createConfigLoader, currentSettingsFileVersion, defaultConfigFilenames, defaultFileName, ENV_CSPELL_GLOB_ROOT, extractDependencies, extractImportErrors, finalizeSettings, getCachedFileSize, getDefaultBundledSettingsAsync, getDefaultConfigLoader, getDefaultSettings, getGlobalSettings, getGlobalSettingsAsync, getSources, ImportError, loadConfig, loadPnP, mergeInDocSettings, mergeSettings, readConfigFile, readRawSettings, readSettings, readSettingsFiles, resolveConfigFileImports, searchForConfig, sectionCSpell, toCSpellSettingsWithOutSourceTrace, } from './Settings/index.js';
11
11
  export { defaultFileName as defaultSettingsFilename } from './Settings/index.js';
12
12
  export * as Link from './Settings/index.link.js';
13
13
  export { combineTextAndLanguageSettings, combineTextAndLanguageSettings as constructSettingsForText, } from './Settings/TextDocumentSettings.js';
14
- export { determineFinalDocumentSettings, spellCheckDocument, spellCheckFile, } from './spellCheckFile.js';
14
+ export { determineFinalDocumentSettings, spellCheckDocument, spellCheckDocumentRPC, spellCheckFile, } from './spellCheckFile.js';
15
15
  export { CompoundWordsMethod, createSpellingDictionary, createCollection as createSpellingDictionaryCollection, isSpellingDictionaryLoadError, refreshDictionaryCache, SpellingDictionaryLoadError, } from './SpellingDictionary/index.js';
16
16
  export { SuggestionError, suggestionsForWord, suggestionsForWords } from './suggestions.js';
17
17
  export { DocumentValidator, shouldCheckDocument } from './textValidation/index.js';
@@ -1,4 +1,4 @@
1
- export { measurePerf, measurePerfEnd, measurePerfFn, measurePerfStart } from './performance.js';
2
1
  export type { PerfTimer } from './timer.js';
3
2
  export { createPerfTimer } from './timer.js';
3
+ export { measurePerf } from '@cspell/cspell-performance-monitor';
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1,3 +1,3 @@
1
- export { measurePerf, measurePerfEnd, measurePerfFn, measurePerfStart } from './performance.js';
2
1
  export { createPerfTimer } from './timer.js';
2
+ export { measurePerf } from '@cspell/cspell-performance-monitor';
3
3
  //# sourceMappingURL=index.js.map
@@ -1,6 +1,7 @@
1
1
  import type { CSpellSettingsWithSourceTrace, CSpellUserSettings } from '@cspell/cspell-types';
2
2
  import type { ICSpellConfigFile } from 'cspell-config-lib';
3
3
  import type { Document, DocumentWithText } from './Document/index.js';
4
+ import type { ImportFileRefWithError } from './Settings/index.js';
4
5
  import type { Uri } from './util/IUri.js';
5
6
  import type { ValidateTextOptions, ValidationIssue } from './validator.js';
6
7
  export interface SpellCheckFileOptions extends ValidateTextOptions, Pick<CSpellUserSettings, 'unknownWords'> {
@@ -38,6 +39,8 @@ export interface SpellCheckFileResult {
38
39
  issues: ValidationIssue[];
39
40
  checked: boolean;
40
41
  errors: Error[] | undefined;
42
+ configErrors?: ImportFileRefWithError[] | undefined;
43
+ dictionaryErrors?: Map<string, Error[]> | undefined;
41
44
  perf?: SpellCheckFilePerf;
42
45
  }
43
46
  /**
@@ -54,6 +57,13 @@ export declare function spellCheckFile(file: string | Uri | URL, options: SpellC
54
57
  * @param settings - default settings to use.
55
58
  */
56
59
  export declare function spellCheckDocument(document: Document | DocumentWithText, options: SpellCheckFileOptions, settingsOrConfigFile: CSpellUserSettings | ICSpellConfigFile): Promise<SpellCheckFileResult>;
60
+ /**
61
+ * Spell Check a Document.
62
+ * @param document - document to be checked. If `document.text` is `undefined` the file will be loaded
63
+ * @param options - options to control checking
64
+ * @param settings - default settings to use.
65
+ */
66
+ export declare function spellCheckDocumentRPC(document: Document | DocumentWithText, options: SpellCheckFileOptions, settingsOrConfigFile: CSpellUserSettings | ICSpellConfigFile): Promise<SpellCheckFileResult>;
57
67
  export interface DetermineFinalDocumentSettingsResult {
58
68
  document: DocumentWithText;
59
69
  settings: CSpellSettingsWithSourceTrace;