-
-
Notifications
You must be signed in to change notification settings - Fork 84
/
DictionaryLoader.ts
30 lines (25 loc) · 1.28 KB
/
DictionaryLoader.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { CSpellIO } from 'cspell-io';
import { DictionaryDefinitionInternal } from '../Models/CSpellSettingsInternalDef';
import { getCSpellIO } from '../static';
import { DictionaryLoader } from './DictionaryController';
import { SpellingDictionary } from 'cspell-dictionary';
export type { LoadOptions } from './DictionaryController';
let loader: DictionaryLoader | undefined;
export function getDictionaryLoader(cspellIO?: CSpellIO): DictionaryLoader {
if (loader) return loader;
return (loader = new DictionaryLoader(cspellIO || getCSpellIO()));
}
export function loadDictionary(def: DictionaryDefinitionInternal): Promise<SpellingDictionary> {
return getDictionaryLoader().loadDictionary(def);
}
export function loadDictionarySync(def: DictionaryDefinitionInternal): SpellingDictionary {
return getDictionaryLoader().loadDictionarySync(def);
}
/**
* Check to see if any of the cached dictionaries have changed. If one has changed, reload it.
* @param maxAge - Only check the dictionary if it has been at least `maxAge` ms since the last check.
* @param now - optional timestamp representing now. (Mostly used in testing)
*/
export async function refreshCacheEntries(maxAge?: number, now?: number): Promise<void> {
return getDictionaryLoader().refreshCacheEntries(maxAge, now);
}