Skip to content

Commit

Permalink
fix(Spell check): Fix spell checker to initialize without loaded dict…
Browse files Browse the repository at this point in the history
…ionary
  • Loading branch information
adlk committed Oct 2, 2019
1 parent a31566d commit 734732f
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/webview/spellchecker.js
Expand Up @@ -18,8 +18,8 @@ const DEFAULT_LOCALE = 'en-us';
async function loadDictionary(locale) {
try {
const fileLocation = path.join(DICTIONARY_PATH, `hunspell-dict-${locale}/${locale}`);
await provider.loadDictionary(locale, readFileSync(`${fileLocation}.dic`), readFileSync(`${fileLocation}.aff`));
debug('Loaded dictionary', locale, 'from', fileLocation);
return provider.loadDictionary(locale, readFileSync(`${fileLocation}.dic`), readFileSync(`${fileLocation}.aff`));
} catch (err) {
console.error('Could not load dictionary', err);
}
Expand All @@ -44,8 +44,8 @@ export async function switchDict(locale = DEFAULT_LOCALE) {
if (currentDict) {
provider.unloadDictionary(locale);
}
loadDictionary(locale);
attached.switchLanguage(locale);
await loadDictionary(locale);
await attached.switchLanguage(locale);

debug('Switched dictionary to', locale);

Expand Down Expand Up @@ -77,9 +77,11 @@ export default async function initialize(languageCode = DEFAULT_LOCALE) {
debug('Attaching spellcheck provider');
attached = await attachSpellCheckProvider(provider);

debug('Available spellchecker dictionaries', provider.availableDictionaries);
const availableDictionaries = await provider.getAvailableDictionaries();

attached.switchLanguage(locale);
debug('Available spellchecker dictionaries', availableDictionaries);

await switchDict(locale);

return provider;
} catch (err) {
Expand Down

0 comments on commit 734732f

Please sign in to comment.