cspell-lib 8.0.0 → 8.1.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.
Files changed (92) hide show
  1. package/dist/esm/Settings/CSpellSettingsServer.d.ts +3 -12
  2. package/dist/esm/Settings/CSpellSettingsServer.js +19 -55
  3. package/dist/esm/Settings/Controller/configLoader/configLoader.d.ts +55 -126
  4. package/dist/esm/Settings/Controller/configLoader/configLoader.js +241 -336
  5. package/dist/esm/Settings/Controller/configLoader/configLocations.d.ts +3 -0
  6. package/dist/esm/Settings/Controller/configLoader/configLocations.js +57 -0
  7. package/dist/esm/Settings/Controller/configLoader/configSearch.d.ts +12 -0
  8. package/dist/esm/Settings/Controller/configLoader/configSearch.js +116 -0
  9. package/dist/esm/Settings/Controller/configLoader/configToRawSettings.d.ts +5 -0
  10. package/dist/esm/Settings/Controller/configLoader/configToRawSettings.js +36 -0
  11. package/dist/esm/Settings/Controller/configLoader/defaultConfigLoader.d.ts +34 -0
  12. package/dist/esm/Settings/Controller/configLoader/defaultConfigLoader.js +67 -0
  13. package/dist/esm/Settings/Controller/configLoader/extractImportErrors.d.ts +1 -0
  14. package/dist/esm/Settings/Controller/configLoader/extractImportErrors.js +4 -0
  15. package/dist/esm/Settings/Controller/configLoader/index.d.ts +3 -1
  16. package/dist/esm/Settings/Controller/configLoader/index.js +3 -1
  17. package/dist/esm/Settings/Controller/configLoader/normalizeRawSettings.d.ts +8 -6
  18. package/dist/esm/Settings/Controller/configLoader/normalizeRawSettings.js +31 -14
  19. package/dist/esm/Settings/Controller/configLoader/readSettings.d.ts +6 -5
  20. package/dist/esm/Settings/Controller/configLoader/readSettings.js +10 -5
  21. package/dist/esm/Settings/Controller/configLoader/readSettingsFiles.d.ts +1 -1
  22. package/dist/esm/Settings/Controller/configLoader/readSettingsFiles.js +3 -2
  23. package/dist/esm/Settings/Controller/pnpLoader.d.ts +4 -12
  24. package/dist/esm/Settings/Controller/pnpLoader.js +22 -48
  25. package/dist/esm/Settings/DefaultSettings.d.ts +10 -2
  26. package/dist/esm/Settings/DefaultSettings.js +33 -22
  27. package/dist/esm/Settings/DictionarySettings.d.ts +4 -4
  28. package/dist/esm/Settings/DictionarySettings.js +8 -5
  29. package/dist/esm/Settings/GlobalSettings.d.ts +6 -3
  30. package/dist/esm/Settings/GlobalSettings.js +24 -19
  31. package/dist/esm/Settings/InDocSettings.js +2 -2
  32. package/dist/esm/Settings/LanguageSettings.js +10 -15
  33. package/dist/esm/Settings/TextDocumentSettings.js +4 -4
  34. package/dist/esm/Settings/calcOverrideSettings.d.ts +3 -0
  35. package/dist/esm/Settings/calcOverrideSettings.js +11 -0
  36. package/dist/esm/Settings/checkFilenameMatchesGlob.d.ts +10 -0
  37. package/dist/esm/Settings/checkFilenameMatchesGlob.js +10 -0
  38. package/dist/esm/Settings/index.d.ts +5 -3
  39. package/dist/esm/Settings/index.js +5 -3
  40. package/dist/esm/Settings/link.d.ts +3 -3
  41. package/dist/esm/Settings/link.js +20 -13
  42. package/dist/esm/Settings/mergeCache.d.ts +13 -0
  43. package/dist/esm/Settings/mergeCache.js +22 -0
  44. package/dist/esm/Settings/mergeList.d.ts +18 -0
  45. package/dist/esm/Settings/mergeList.js +34 -0
  46. package/dist/esm/Settings/patterns.js +13 -2
  47. package/dist/esm/SpellingDictionary/DictionaryController/DictionaryLoader.d.ts +1 -0
  48. package/dist/esm/SpellingDictionary/DictionaryController/DictionaryLoader.js +40 -38
  49. package/dist/esm/clearCachedFiles.d.ts +14 -0
  50. package/dist/esm/clearCachedFiles.js +29 -3
  51. package/dist/esm/events/events.d.ts +17 -0
  52. package/dist/esm/events/events.js +28 -0
  53. package/dist/esm/events/index.d.ts +3 -0
  54. package/dist/esm/events/index.js +2 -0
  55. package/dist/esm/getDictionary.js +1 -1
  56. package/dist/esm/globs/checkFilenameMatchesGlob.d.ts +8 -0
  57. package/dist/esm/globs/checkFilenameMatchesGlob.js +11 -0
  58. package/dist/esm/globs/getGlobMatcher.d.ts +4 -0
  59. package/dist/esm/globs/getGlobMatcher.js +31 -0
  60. package/dist/esm/index.d.ts +4 -2
  61. package/dist/esm/index.js +3 -2
  62. package/dist/esm/perf/index.d.ts +3 -0
  63. package/dist/esm/perf/index.js +2 -0
  64. package/dist/esm/perf/perf.d.ts +14 -0
  65. package/dist/esm/perf/perf.js +27 -0
  66. package/dist/esm/perf/timer.d.ts +11 -0
  67. package/dist/esm/perf/timer.js +37 -0
  68. package/dist/esm/spellCheckFile.d.ts +8 -1
  69. package/dist/esm/spellCheckFile.js +33 -4
  70. package/dist/esm/suggestions.js +5 -5
  71. package/dist/esm/textValidation/ValidateTextOptions.d.ts +5 -0
  72. package/dist/esm/textValidation/determineTextDocumentSettings.d.ts +1 -1
  73. package/dist/esm/textValidation/determineTextDocumentSettings.js +2 -2
  74. package/dist/esm/textValidation/docValidator.d.ts +4 -9
  75. package/dist/esm/textValidation/docValidator.js +53 -91
  76. package/dist/esm/trace.js +8 -1
  77. package/dist/esm/util/AutoResolve.d.ts +21 -4
  78. package/dist/esm/util/AutoResolve.js +25 -4
  79. package/dist/esm/util/errors.js +4 -4
  80. package/dist/esm/util/fileReader.d.ts +3 -3
  81. package/dist/esm/util/findUp.d.ts +9 -0
  82. package/dist/esm/util/findUp.js +43 -0
  83. package/dist/esm/util/resolveFile.d.ts +31 -1
  84. package/dist/esm/util/resolveFile.js +107 -27
  85. package/dist/esm/util/url.d.ts +29 -0
  86. package/dist/esm/util/url.js +91 -0
  87. package/dist/esm/util/wordSplitter.js +4 -4
  88. package/package.json +16 -17
  89. package/dist/esm/util/debugPerf.d.ts +0 -9
  90. package/dist/esm/util/debugPerf.js +0 -18
  91. package/dist/esm/util/timer.d.ts +0 -26
  92. package/dist/esm/util/timer.js +0 -51
@@ -0,0 +1,22 @@
1
+ import { onClearCache } from '../events/index.js';
2
+ import { AutoResolveWeakCache } from '../util/AutoResolve.js';
3
+ export class CalcLeftRightResultWeakCache {
4
+ map = new AutoResolveWeakCache();
5
+ _toDispose;
6
+ constructor() {
7
+ this._toDispose = onClearCache(() => {
8
+ this.clear();
9
+ });
10
+ }
11
+ get(left, right, calc) {
12
+ const m = this.map.get(left, () => new AutoResolveWeakCache());
13
+ return m.get(right, () => calc(left, right));
14
+ }
15
+ clear() {
16
+ this.map.clear();
17
+ }
18
+ dispose() {
19
+ this._toDispose.dispose();
20
+ }
21
+ }
22
+ //# sourceMappingURL=mergeCache.js.map
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Merges two lists and removes duplicates. Order is NOT preserved.
3
+ */
4
+ export declare function mergeListUnique(left: undefined, right: undefined): undefined;
5
+ export declare function mergeListUnique<T>(left: T[], right: T[]): T[];
6
+ export declare function mergeListUnique<T>(left: undefined, right: T[]): T[];
7
+ export declare function mergeListUnique<T>(left: T[], right: undefined): T[];
8
+ export declare function mergeListUnique<T>(left: T[] | undefined, right: T[] | undefined): T[] | undefined;
9
+ /**
10
+ * Merges two lists.
11
+ * Order is preserved.
12
+ */
13
+ export declare function mergeList(left: undefined, right: undefined): undefined;
14
+ export declare function mergeList<T>(left: T[], right: T[]): T[];
15
+ export declare function mergeList<T>(left: undefined, right: T[]): T[];
16
+ export declare function mergeList<T>(left: T[], right: undefined): T[];
17
+ export declare function mergeList<T>(left: T[] | undefined, right: T[] | undefined): T[] | undefined;
18
+ //# sourceMappingURL=mergeList.d.ts.map
@@ -0,0 +1,34 @@
1
+ import { CalcLeftRightResultWeakCache } from './mergeCache.js';
2
+ const cacheMergeListUnique = new CalcLeftRightResultWeakCache();
3
+ const cacheMergeLists = new CalcLeftRightResultWeakCache();
4
+ export function mergeListUnique(left, right) {
5
+ if (!Array.isArray(left))
6
+ return Array.isArray(right) ? right : undefined;
7
+ if (!Array.isArray(right))
8
+ return left;
9
+ if (!right.length)
10
+ return left;
11
+ if (!left.length)
12
+ return right;
13
+ const result = cacheMergeListUnique.get(left, right, (left, right) => [...new Set([...left, ...right])]);
14
+ Object.freeze(left);
15
+ Object.freeze(right);
16
+ Object.freeze(result);
17
+ return result;
18
+ }
19
+ export function mergeList(left, right) {
20
+ if (!Array.isArray(left))
21
+ return Array.isArray(right) ? right : undefined;
22
+ if (!Array.isArray(right))
23
+ return left;
24
+ if (!left.length)
25
+ return right;
26
+ if (!right.length)
27
+ return left;
28
+ const result = cacheMergeLists.get(left, right, (left, right) => left.concat(right));
29
+ Object.freeze(left);
30
+ Object.freeze(right);
31
+ Object.freeze(result);
32
+ return result;
33
+ }
34
+ //# sourceMappingURL=mergeList.js.map
@@ -1,6 +1,13 @@
1
1
  import { stringToRegExp } from '../util/textRegex.js';
2
2
  import { isDefined } from '../util/util.js';
3
- export function resolvePatterns(regExpList = [], patternDefinitions = []) {
3
+ import { CalcLeftRightResultWeakCache } from './mergeCache.js';
4
+ const emptyRegExpList = [];
5
+ const emptyPatternDefinitions = [];
6
+ const cache = new CalcLeftRightResultWeakCache();
7
+ export function resolvePatterns(regExpList = emptyRegExpList, patternDefinitions = emptyPatternDefinitions) {
8
+ return cache.get(regExpList, patternDefinitions, _resolvePatterns);
9
+ }
10
+ function _resolvePatterns(regExpList, patternDefinitions) {
4
11
  const patternMap = new Map(patternDefinitions.map((def) => [def.name.toLowerCase(), def.pattern]));
5
12
  const resolved = new Set();
6
13
  function resolvePattern(p) {
@@ -20,7 +27,11 @@ export function resolvePatterns(regExpList = [], patternDefinitions = []) {
20
27
  }
21
28
  }
22
29
  const patternList = regExpList.map(resolvePattern).filter(isDefined);
23
- return [...flatten(patternList)].map(toRegExp).filter(isDefined);
30
+ const result = [...flatten(patternList)].map(toRegExp).filter(isDefined);
31
+ Object.freeze(regExpList);
32
+ Object.freeze(patternDefinitions);
33
+ Object.freeze(result);
34
+ return result;
24
35
  }
25
36
  function toRegExp(pattern) {
26
37
  return pattern instanceof RegExp ? new RegExp(pattern) : stringToRegExp(pattern, 'gim', 'g');
@@ -27,5 +27,6 @@ export declare class DictionaryLoader {
27
27
  private isEqual;
28
28
  private normalizeOptions;
29
29
  private loadInlineDict;
30
+ private calcKey;
30
31
  }
31
32
  //# sourceMappingURL=DictionaryLoader.d.ts.map
@@ -55,7 +55,7 @@ export class DictionaryLoader {
55
55
  if (entry?.dictionary && entry.loadingState === LoadingState.Loaded) {
56
56
  return entry.dictionary;
57
57
  }
58
- const loadedEntry = this.loadEntrySync(def.path, def);
58
+ const loadedEntry = this.loadEntrySync(this.cspellIO.toFileURL(def.path), def);
59
59
  this.setCacheEntry(key, loadedEntry, def);
60
60
  return loadedEntry.dictionary;
61
61
  }
@@ -72,7 +72,7 @@ export class DictionaryLoader {
72
72
  if (defEntry) {
73
73
  return defEntry;
74
74
  }
75
- const key = calcKey(def);
75
+ const key = this.calcKey(def);
76
76
  const entry = this.dictionaryCache.get(key);
77
77
  if (entry) {
78
78
  // replace old entry so it can be released.
@@ -96,21 +96,22 @@ export class DictionaryLoader {
96
96
  const sigMatches = entry.sig === sig;
97
97
  if (sigMatches && hasChanged) {
98
98
  entry.loadingState = LoadingState.Loading;
99
- const key = calcKey(entry.options);
99
+ const key = this.calcKey(entry.options);
100
100
  const newEntry = this.loadEntry(entry.uri, entry.options);
101
101
  this.dictionaryCache.set(key, newEntry);
102
102
  this.dictionaryCacheByDef.set(entry.options, { key, entry: newEntry });
103
103
  }
104
104
  }
105
105
  }
106
- loadEntry(uri, options, now = Date.now()) {
107
- options = this.normalizeOptions(uri, options);
108
- const pDictionary = load(this.reader, uri, options).catch((e) => createFailedToLoadDictionary(options.name, uri, new SpellingDictionaryLoadError(uri, options, e, 'failed to load'), options));
109
- const pStat = this.getStat(uri);
106
+ loadEntry(fileOrUri, options, now = Date.now()) {
107
+ const url = this.cspellIO.toFileURL(fileOrUri);
108
+ options = this.normalizeOptions(url, options);
109
+ const pDictionary = load(this.reader, this.cspellIO.toFileURL(fileOrUri), options).catch((e) => createFailedToLoadDictionary(options.name, fileOrUri, new SpellingDictionaryLoadError(url.href, options, e, 'failed to load'), options));
110
+ const pStat = this.getStat(fileOrUri);
110
111
  const pending = Promise.all([pDictionary, pStat]);
111
112
  const sig = now + Math.random();
112
113
  const entry = {
113
- uri,
114
+ uri: url.href,
114
115
  options,
115
116
  ts: now,
116
117
  stat: undefined,
@@ -128,15 +129,16 @@ export class DictionaryLoader {
128
129
  });
129
130
  return entry;
130
131
  }
131
- loadEntrySync(uri, options, now = Date.now()) {
132
- options = this.normalizeOptions(uri, options);
133
- const stat = this.getStatSync(uri);
132
+ loadEntrySync(fileOrUri, options, now = Date.now()) {
133
+ const url = this.cspellIO.toFileURL(fileOrUri);
134
+ options = this.normalizeOptions(url, options);
135
+ const stat = this.getStatSync(url);
134
136
  const sig = now + Math.random();
135
137
  try {
136
- const dictionary = loadSync(this.reader, uri, options);
138
+ const dictionary = loadSync(this.reader, url, options);
137
139
  const pending = Promise.resolve([dictionary, stat]);
138
140
  return {
139
- uri,
141
+ uri: url.href,
140
142
  options,
141
143
  ts: now,
142
144
  stat,
@@ -148,10 +150,10 @@ export class DictionaryLoader {
148
150
  }
149
151
  catch (e) {
150
152
  const error = toError(e);
151
- const dictionary = createFailedToLoadDictionary(options.name, uri, new SpellingDictionaryLoadError(uri, options, error, 'failed to load'), options);
153
+ const dictionary = createFailedToLoadDictionary(options.name, fileOrUri, new SpellingDictionaryLoadError(url.href, options, error, 'failed to load'), options);
152
154
  const pending = Promise.resolve([dictionary, stat]);
153
155
  return {
154
- uri,
156
+ uri: url.href,
155
157
  options,
156
158
  ts: now,
157
159
  stat,
@@ -163,11 +165,11 @@ export class DictionaryLoader {
163
165
  }
164
166
  }
165
167
  getStat(uri) {
166
- return this.cspellIO.getStat(uri).catch(toError);
168
+ return this.cspellIO.getStat(this.cspellIO.toFileURL(uri)).catch(toError);
167
169
  }
168
170
  getStatSync(uri) {
169
171
  try {
170
- return this.cspellIO.getStatSync(uri);
172
+ return this.cspellIO.getStatSync(this.cspellIO.toFileURL(uri));
171
173
  }
172
174
  catch (e) {
173
175
  return toError(e);
@@ -184,28 +186,28 @@ export class DictionaryLoader {
184
186
  normalizeOptions(uri, options) {
185
187
  if (options.name)
186
188
  return options;
187
- return { ...options, name: this.cspellIO.uriBasename(uri) };
189
+ return { ...options, name: this.cspellIO.urlBasename(uri) };
188
190
  }
189
191
  loadInlineDict(def) {
190
192
  return this.inlineDictionaryCache.get(def, (def) => createInlineSpellingDictionary(def, def.__source || 'memory'));
191
193
  }
194
+ calcKey(def) {
195
+ const path = def.path;
196
+ const loaderType = determineType(this.cspellIO.toFileURL(path), def);
197
+ const optValues = importantOptionKeys.map((k) => def[k]?.toString() || '');
198
+ const parts = [path, loaderType].concat(optValues);
199
+ return parts.join('|');
200
+ }
192
201
  }
193
202
  function toReader(cspellIO) {
194
203
  return {
195
- read: async (filename) => (await cspellIO.readFile(filename)).content,
196
- readLines: async (filename) => toLines((await cspellIO.readFile(filename)).content),
197
- readSync: (filename) => cspellIO.readFileSync(filename).content,
198
- readLinesSync: (filename) => toLines(cspellIO.readFileSync(filename).content),
204
+ read: async (filename) => (await cspellIO.readFile(filename)).getText(),
205
+ readLines: async (filename) => toLines((await cspellIO.readFile(filename)).getText()),
206
+ readSync: (filename) => cspellIO.readFileSync(filename).getText(),
207
+ readLinesSync: (filename) => toLines(cspellIO.readFileSync(filename).getText()),
199
208
  };
200
209
  }
201
210
  const importantOptionKeys = ['name', 'noSuggest', 'useCompounds', 'type'];
202
- function calcKey(def) {
203
- const path = def.path;
204
- const loaderType = determineType(path, def);
205
- const optValues = importantOptionKeys.map((k) => def[k]?.toString() || '');
206
- const parts = [path, loaderType].concat(optValues);
207
- return parts.join('|');
208
- }
209
211
  function isError(e) {
210
212
  const err = e;
211
213
  return !!err.message;
@@ -213,9 +215,9 @@ function isError(e) {
213
215
  function determineType(uri, opts) {
214
216
  const t = (opts.type && opts.type in loaders && opts.type) || 'S';
215
217
  const defLoaderType = t;
216
- const defType = uri.endsWith('.trie.gz') ? 'T' : defLoaderType;
218
+ const defType = uri.pathname.endsWith('.trie.gz') ? 'T' : defLoaderType;
217
219
  const regTrieTest = /\.trie\b/i;
218
- return regTrieTest.test(uri) ? 'T' : defType;
220
+ return regTrieTest.test(uri.pathname) ? 'T' : defType;
219
221
  }
220
222
  function load(reader, uri, options) {
221
223
  const type = determineType(uri, options);
@@ -241,15 +243,15 @@ function _legacyWordListSync(lines, filename, options) {
241
243
  opMap((line) => line.replace(/#.*/g, '')),
242
244
  // Split on everything else
243
245
  opConcatMap((line) => line.split(/[^\w\p{L}\p{M}'’]+/gu)), opFilter((word) => !!word));
244
- return createSpellingDictionary(words, options.name, filename, options);
246
+ return createSpellingDictionary(words, options.name, filename.toString(), options);
245
247
  }
246
248
  async function wordsPerLineWordList(reader, filename, options) {
247
249
  const lines = await reader.readLines(filename);
248
- return _wordsPerLineWordList(lines, filename, options);
250
+ return _wordsPerLineWordList(lines, filename.toString(), options);
249
251
  }
250
252
  function wordsPerLineWordListSync(reader, filename, options) {
251
253
  const lines = reader.readLinesSync(filename);
252
- return _wordsPerLineWordList(lines, filename, options);
254
+ return _wordsPerLineWordList(lines, filename.toString(), options);
253
255
  }
254
256
  function _wordsPerLineWordList(lines, filename, options) {
255
257
  const words = pipe(lines,
@@ -261,19 +263,19 @@ function _wordsPerLineWordList(lines, filename, options) {
261
263
  }
262
264
  async function loadSimpleWordList(reader, filename, options) {
263
265
  const lines = await reader.readLines(filename);
264
- return createSpellingDictionary(lines, options.name, filename, options);
266
+ return createSpellingDictionary(lines, options.name, filename.href, options);
265
267
  }
266
268
  function loadSimpleWordListSync(reader, filename, options) {
267
269
  const lines = reader.readLinesSync(filename);
268
- return createSpellingDictionary(lines, options.name, filename, options);
270
+ return createSpellingDictionary(lines, options.name, filename.href, options);
269
271
  }
270
272
  async function loadTrie(reader, filename, options) {
271
273
  const content = await reader.read(filename);
272
- return createSpellingDictionaryFromTrieFile(content, options.name, filename, options);
274
+ return createSpellingDictionaryFromTrieFile(content, options.name, filename.href, options);
273
275
  }
274
276
  function loadTrieSync(reader, filename, options) {
275
277
  const content = reader.readSync(filename);
276
- return createSpellingDictionaryFromTrieFile(content, options.name, filename, options);
278
+ return createSpellingDictionaryFromTrieFile(content, options.name, filename.href, options);
277
279
  }
278
280
  function toLines(content) {
279
281
  return content.split(/\n|\r\n|\r/);
@@ -1,2 +1,16 @@
1
+ /**
2
+ * Clear the cached files and other cached data.
3
+ * Calling this function will cause the next spell check to take longer because it will need to reload configuration files and dictionaries.
4
+ * Call this function if configuration files have changed.
5
+ *
6
+ * It is safe to replace {@link clearCachedFiles} with {@link clearCaches}
7
+ */
1
8
  export declare function clearCachedFiles(): Promise<void>;
9
+ /**
10
+ * Sends and event to clear the caches.
11
+ * It resets the configuration files and dictionaries.
12
+ *
13
+ * It is safe to replace {@link clearCaches} with {@link clearCachedFiles}
14
+ */
15
+ export declare function clearCaches(): void;
2
16
  //# sourceMappingURL=clearCachedFiles.d.ts.map
@@ -1,6 +1,32 @@
1
- import { clearCachedSettingsFiles } from './Settings/index.js';
1
+ import { dispatchClearCache } from './events/index.js';
2
2
  import { refreshDictionaryCache } from './SpellingDictionary/index.js';
3
- export async function clearCachedFiles() {
4
- await Promise.all([clearCachedSettingsFiles(), refreshDictionaryCache(0)]);
3
+ /**
4
+ * Clear the cached files and other cached data.
5
+ * Calling this function will cause the next spell check to take longer because it will need to reload configuration files and dictionaries.
6
+ * Call this function if configuration files have changed.
7
+ *
8
+ * It is safe to replace {@link clearCachedFiles} with {@link clearCaches}
9
+ */
10
+ export function clearCachedFiles() {
11
+ return _clearCachedFiles();
12
+ }
13
+ /**
14
+ * Clear the cached files and other cached data.
15
+ * Calling this function will cause the next spell check to take longer because it will need to reload configuration files and dictionaries.
16
+ * Call this function if configuration files have changed.
17
+ */
18
+ function _clearCachedFiles() {
19
+ // We want to dispatch immediately.
20
+ dispatchClearCache();
21
+ return Promise.all([refreshDictionaryCache(0)]).then(() => undefined);
22
+ }
23
+ /**
24
+ * Sends and event to clear the caches.
25
+ * It resets the configuration files and dictionaries.
26
+ *
27
+ * It is safe to replace {@link clearCaches} with {@link clearCachedFiles}
28
+ */
29
+ export function clearCaches() {
30
+ clearCachedFiles().catch(() => { });
5
31
  }
6
32
  //# sourceMappingURL=clearCachedFiles.js.map
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Event indicating that the cache should be cleared.
3
+ */
4
+ export declare class ClearCacheEvent extends Event {
5
+ constructor();
6
+ static eventName: "clear-cache";
7
+ }
8
+ export type EventNames = typeof ClearCacheEvent.eventName;
9
+ export type EventTypes = ClearCacheEvent;
10
+ export interface DisposableListener {
11
+ dispose(): void;
12
+ }
13
+ export declare function addEventListener(event: EventNames, listener: (event: ClearCacheEvent) => void): DisposableListener;
14
+ export declare function dispatchEvent(event: EventTypes): void;
15
+ export declare function onClearCache(listener: () => void): DisposableListener;
16
+ export declare function dispatchClearCache(): void;
17
+ //# sourceMappingURL=events.d.ts.map
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Event indicating that the cache should be cleared.
3
+ */
4
+ export class ClearCacheEvent extends Event {
5
+ constructor() {
6
+ super(ClearCacheEvent.eventName);
7
+ }
8
+ static eventName = 'clear-cache';
9
+ }
10
+ const eventEmitter = new EventTarget();
11
+ export function addEventListener(event, listener) {
12
+ eventEmitter.addEventListener(event, listener);
13
+ return {
14
+ dispose() {
15
+ eventEmitter.removeEventListener(event, listener);
16
+ },
17
+ };
18
+ }
19
+ export function dispatchEvent(event) {
20
+ eventEmitter.dispatchEvent(event);
21
+ }
22
+ export function onClearCache(listener) {
23
+ return addEventListener(ClearCacheEvent.eventName, listener);
24
+ }
25
+ export function dispatchClearCache() {
26
+ dispatchEvent(new ClearCacheEvent());
27
+ }
28
+ //# sourceMappingURL=events.js.map
@@ -0,0 +1,3 @@
1
+ export type { DisposableListener, EventNames, EventTypes } from './events.js';
2
+ export { addEventListener, ClearCacheEvent, dispatchClearCache, dispatchEvent, onClearCache } from './events.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,2 @@
1
+ export { addEventListener, ClearCacheEvent, dispatchClearCache, dispatchEvent, onClearCache } from './events.js';
2
+ //# sourceMappingURL=index.js.map
@@ -5,7 +5,7 @@ import { getDictionaryInternal } from './SpellingDictionary/index.js';
5
5
  * @param settings - that defines the dictionaries and the ones to load.
6
6
  * @returns a dictionary collection that represents all the enabled dictionaries.
7
7
  */
8
- export function getDictionary(settings) {
8
+ export async function getDictionary(settings) {
9
9
  return getDictionaryInternal(toInternalSettings(settings));
10
10
  }
11
11
  //# sourceMappingURL=getDictionary.js.map
@@ -0,0 +1,8 @@
1
+ import type { Glob } from '@cspell/cspell-types';
2
+ /**
3
+ * @param filename - filename
4
+ * @param globs - globs
5
+ * @returns true if it matches
6
+ */
7
+ export declare function checkFilenameMatchesExcludeGlob(filename: string, globs: Glob | Glob[]): boolean;
8
+ //# sourceMappingURL=checkFilenameMatchesGlob.d.ts.map
@@ -0,0 +1,11 @@
1
+ import { getGlobMatcherForExcluding } from './getGlobMatcher.js';
2
+ /**
3
+ * @param filename - filename
4
+ * @param globs - globs
5
+ * @returns true if it matches
6
+ */
7
+ export function checkFilenameMatchesExcludeGlob(filename, globs) {
8
+ const m = getGlobMatcherForExcluding(globs);
9
+ return m.match(filename);
10
+ }
11
+ //# sourceMappingURL=checkFilenameMatchesGlob.js.map
@@ -0,0 +1,4 @@
1
+ import type { Glob } from '@cspell/cspell-types';
2
+ import { GlobMatcher } from 'cspell-glob';
3
+ export declare function getGlobMatcherForExcluding(glob: Glob | Glob[] | undefined): GlobMatcher;
4
+ //# sourceMappingURL=getGlobMatcher.d.ts.map
@@ -0,0 +1,31 @@
1
+ import { GlobMatcher } from 'cspell-glob';
2
+ import { onClearCache } from '../events/index.js';
3
+ const simpleGlobCache = new Map();
4
+ let globCache = new WeakMap();
5
+ onClearCache(() => {
6
+ globCache = new WeakMap();
7
+ simpleGlobCache.clear();
8
+ });
9
+ const emptyIgnorePaths = [];
10
+ export function getGlobMatcherForExcluding(glob) {
11
+ if (!glob || (Array.isArray(glob) && !glob.length))
12
+ return getGlobMatcherGlobGlob(emptyIgnorePaths);
13
+ return typeof glob === 'string' ? getGlobMatcherGlobString(glob) : getGlobMatcherGlobGlob(glob);
14
+ }
15
+ function getGlobMatcherGlobString(glob) {
16
+ const cached = simpleGlobCache.get(glob);
17
+ if (cached)
18
+ return cached;
19
+ const m = new GlobMatcher(glob);
20
+ simpleGlobCache.set(glob, m);
21
+ return m;
22
+ }
23
+ function getGlobMatcherGlobGlob(glob) {
24
+ const cached = globCache.get(glob);
25
+ if (cached)
26
+ return cached;
27
+ const m = new GlobMatcher(glob);
28
+ globCache.set(glob, m);
29
+ return m;
30
+ }
31
+ //# sourceMappingURL=getGlobMatcher.js.map
@@ -8,7 +8,7 @@ export { FeatureFlag, FeatureFlags, getSystemFeatureFlags, UnknownFeatureFlagErr
8
8
  export { getLanguagesForBasename as getLanguageIdsForBaseFilename, getLanguagesForExt } from './LanguageIds.js';
9
9
  export type { CreateTextDocumentParams, TextDocument, TextDocumentLine, TextDocumentRef, } from './Models/TextDocument.js';
10
10
  export { createTextDocument, updateTextDocument } from './Models/TextDocument.js';
11
- export { calcOverrideSettings, checkFilenameMatchesGlob, clearCachedSettingsFiles, type ConfigurationDependencies, currentSettingsFileVersion, defaultConfigFilenames, defaultFileName, ENV_CSPELL_GLOB_ROOT, extractDependencies, extractImportErrors, finalizeSettings, getCachedFileSize, getDefaultBundledSettings, getDefaultSettings, getGlobalSettings, getSources, ImportError, type ImportFileRefWithError, loadConfig, loadPnP, loadPnPSync, mergeInDocSettings, mergeSettings, readRawSettings, readSettings, readSettingsFiles, searchForConfig, sectionCSpell, } from './Settings/index.js';
11
+ export { calcOverrideSettings, checkFilenameMatchesGlob, type ConfigurationDependencies, currentSettingsFileVersion, defaultConfigFilenames, defaultFileName, ENV_CSPELL_GLOB_ROOT, extractDependencies, extractImportErrors, finalizeSettings, getCachedFileSize, getDefaultBundledSettingsAsync, getDefaultSettings, getGlobalSettings, getGlobalSettingsAsync, getSources, ImportError, type ImportFileRefWithError, loadConfig, loadPnP, mergeInDocSettings, mergeSettings, readRawSettings, readSettings, readSettingsFiles, searchForConfig, sectionCSpell, } from './Settings/index.js';
12
12
  export { defaultFileName as defaultSettingsFilename } from './Settings/index.js';
13
13
  export { combineTextAndLanguageSettings, combineTextAndLanguageSettings as constructSettingsForText, } from './Settings/TextDocumentSettings.js';
14
14
  export { determineFinalDocumentSettings, DetermineFinalDocumentSettingsResult, spellCheckDocument, spellCheckFile, SpellCheckFileOptions, SpellCheckFileResult, } from './spellCheckFile.js';
@@ -25,6 +25,8 @@ export * from '@cspell/cspell-types';
25
25
  export { asyncIterableToArray, readFileText as readFile, readFileTextSync as readFileSync, writeToFile, writeToFileIterable, writeToFileIterableP, } from 'cspell-io';
26
26
  export { Link, Text };
27
27
  export { ExclusionHelper };
28
- export { clearCachedFiles } from './clearCachedFiles.js';
28
+ export { clearCachedFiles, clearCaches } from './clearCachedFiles.js';
29
29
  export { getDictionary } from './getDictionary.js';
30
+ export type { PerfTimer } from './perf/index.js';
31
+ export { createPerfTimer } from './perf/index.js';
30
32
  //# sourceMappingURL=index.d.ts.map
package/dist/esm/index.js CHANGED
@@ -5,7 +5,7 @@ export { fileToDocument, fileToTextDocument, isBinaryFile } from './Document/ind
5
5
  export { FeatureFlags, getSystemFeatureFlags, UnknownFeatureFlagError } from './FeatureFlags/index.js';
6
6
  export { getLanguagesForBasename as getLanguageIdsForBaseFilename, getLanguagesForExt } from './LanguageIds.js';
7
7
  export { createTextDocument, updateTextDocument } from './Models/TextDocument.js';
8
- export { calcOverrideSettings, checkFilenameMatchesGlob, clearCachedSettingsFiles, currentSettingsFileVersion, defaultConfigFilenames, defaultFileName, ENV_CSPELL_GLOB_ROOT, extractDependencies, extractImportErrors, finalizeSettings, getCachedFileSize, getDefaultBundledSettings, getDefaultSettings, getGlobalSettings, getSources, ImportError, loadConfig, loadPnP, loadPnPSync, mergeInDocSettings, mergeSettings, readRawSettings, readSettings, readSettingsFiles, searchForConfig, sectionCSpell, } from './Settings/index.js';
8
+ export { calcOverrideSettings, checkFilenameMatchesGlob, currentSettingsFileVersion, defaultConfigFilenames, defaultFileName, ENV_CSPELL_GLOB_ROOT, extractDependencies, extractImportErrors, finalizeSettings, getCachedFileSize, getDefaultBundledSettingsAsync, getDefaultSettings, getGlobalSettings, getGlobalSettingsAsync, getSources, ImportError, loadConfig, loadPnP, mergeInDocSettings, mergeSettings, readRawSettings, readSettings, readSettingsFiles, searchForConfig, sectionCSpell, } from './Settings/index.js';
9
9
  export { defaultFileName as defaultSettingsFilename } from './Settings/index.js';
10
10
  export { combineTextAndLanguageSettings, combineTextAndLanguageSettings as constructSettingsForText, } from './Settings/TextDocumentSettings.js';
11
11
  export { determineFinalDocumentSettings, spellCheckDocument, spellCheckFile, } from './spellCheckFile.js';
@@ -20,6 +20,7 @@ export * from '@cspell/cspell-types';
20
20
  export { asyncIterableToArray, readFileText as readFile, readFileTextSync as readFileSync, writeToFile, writeToFileIterable, writeToFileIterableP, } from 'cspell-io';
21
21
  export { Link, Text };
22
22
  export { ExclusionHelper };
23
- export { clearCachedFiles } from './clearCachedFiles.js';
23
+ export { clearCachedFiles, clearCaches } from './clearCachedFiles.js';
24
24
  export { getDictionary } from './getDictionary.js';
25
+ export { createPerfTimer } from './perf/index.js';
25
26
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,3 @@
1
+ export type { PerfTimer } from './timer.js';
2
+ export { createPerfTimer } from './timer.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,2 @@
1
+ export { createPerfTimer } from './timer.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,14 @@
1
+ declare class PerfMonitor {
2
+ private _performance;
3
+ private _enabled;
4
+ constructor(_performance?: Performance);
5
+ mark(name: string): void;
6
+ measure(name: string, startMark: string, endMark: string): void;
7
+ clearMarks(name?: string): void;
8
+ clearMeasures(name?: string): void;
9
+ get enabled(): boolean;
10
+ set enabled(value: boolean);
11
+ }
12
+ export declare const perf: PerfMonitor;
13
+ export {};
14
+ //# sourceMappingURL=perf.d.ts.map
@@ -0,0 +1,27 @@
1
+ class PerfMonitor {
2
+ _performance;
3
+ _enabled = false;
4
+ constructor(_performance = performance) {
5
+ this._performance = _performance;
6
+ }
7
+ mark(name) {
8
+ this._enabled && this._performance.mark(name);
9
+ }
10
+ measure(name, startMark, endMark) {
11
+ this._enabled && this._performance.measure(name, startMark, endMark);
12
+ }
13
+ clearMarks(name) {
14
+ this._enabled && this._performance.clearMarks(name);
15
+ }
16
+ clearMeasures(name) {
17
+ this._enabled && this._performance.clearMeasures(name);
18
+ }
19
+ get enabled() {
20
+ return this._enabled;
21
+ }
22
+ set enabled(value) {
23
+ this._enabled = value;
24
+ }
25
+ }
26
+ export const perf = new PerfMonitor();
27
+ //# sourceMappingURL=perf.js.map
@@ -0,0 +1,11 @@
1
+ export interface PerfTimer {
2
+ readonly name: string;
3
+ readonly startTime: number;
4
+ readonly elapsed: number;
5
+ start(): void;
6
+ end(): void;
7
+ }
8
+ type TimeNowFn = () => number;
9
+ export declare function createPerfTimer(name: string, onEnd?: (elapsed: number, name: string) => void, timeNowFn?: TimeNowFn): PerfTimer;
10
+ export {};
11
+ //# sourceMappingURL=timer.d.ts.map
@@ -0,0 +1,37 @@
1
+ // Symbol.dispose ??= Symbol('Symbol.dispose');
2
+ // Symbol.asyncDispose ??= Symbol('Symbol.asyncDispose');
3
+ export function createPerfTimer(name, onEnd, timeNowFn) {
4
+ return new SimpleTimer(name, onEnd, timeNowFn);
5
+ }
6
+ class SimpleTimer {
7
+ name;
8
+ onEnd;
9
+ timeNowFn;
10
+ _start = performance.now();
11
+ _elapsed = undefined;
12
+ _running = true;
13
+ constructor(name, onEnd, timeNowFn = performance.now) {
14
+ this.name = name;
15
+ this.onEnd = onEnd;
16
+ this.timeNowFn = timeNowFn;
17
+ }
18
+ get startTime() {
19
+ return this._start;
20
+ }
21
+ get elapsed() {
22
+ return this._elapsed ?? performance.now() - this._start;
23
+ }
24
+ end() {
25
+ if (!this._running)
26
+ return;
27
+ this._running = false;
28
+ const end = performance.now();
29
+ this._elapsed = end - this._start;
30
+ this.onEnd?.(this._elapsed, this.name);
31
+ }
32
+ start() {
33
+ this._start = performance.now();
34
+ this._running = true;
35
+ }
36
+ }
37
+ //# sourceMappingURL=timer.js.map