Search in sources :

Example 1 with CompressedDictionary

use of com.intellij.spellchecker.compress.CompressedDictionary in project intellij-community by JetBrains.

the class BaseSpellChecker method doLoadDictionaryAsync.

private void doLoadDictionaryAsync(Loader loader, Consumer<Dictionary> consumer) {
    StartupManager.getInstance(myProject).runWhenProjectIsInitialized(() -> {
        LOG.debug("Loading " + loader.getName());
        Application app = ApplicationManager.getApplication();
        app.executeOnPooledThread(() -> {
            if (app.isDisposed())
                return;
            CompressedDictionary dictionary = CompressedDictionary.create(loader, transform);
            LOG.debug(loader.getName() + " loaded!");
            consumer.consume(dictionary);
            while (!myDictionariesToLoad.isEmpty()) {
                if (app.isDisposed())
                    return;
                Pair<Loader, Consumer<Dictionary>> nextDictionary = myDictionariesToLoad.remove(0);
                Loader nextDictionaryLoader = nextDictionary.getFirst();
                dictionary = CompressedDictionary.create(nextDictionaryLoader, transform);
                LOG.debug(nextDictionaryLoader.getName() + " loaded!");
                nextDictionary.getSecond().consume(dictionary);
            }
            LOG.debug("Loading finished, restarting daemon...");
            myLoadingDictionaries.set(false);
            UIUtil.invokeLaterIfNeeded(() -> {
                if (app.isDisposed())
                    return;
                for (final Project project : ProjectManager.getInstance().getOpenProjects()) {
                    if (project.isInitialized() && project.isOpen() && !project.isDefault()) {
                        DaemonCodeAnalyzer instance = DaemonCodeAnalyzer.getInstance(project);
                        if (instance != null)
                            instance.restart();
                    }
                }
            });
        });
    });
}
Also used : Project(com.intellij.openapi.project.Project) Consumer(com.intellij.util.Consumer) CompressedDictionary(com.intellij.spellchecker.compress.CompressedDictionary) DaemonCodeAnalyzer(com.intellij.codeInsight.daemon.DaemonCodeAnalyzer) Loader(com.intellij.spellchecker.dictionary.Loader) Application(com.intellij.openapi.application.Application)

Aggregations

DaemonCodeAnalyzer (com.intellij.codeInsight.daemon.DaemonCodeAnalyzer)1 Application (com.intellij.openapi.application.Application)1 Project (com.intellij.openapi.project.Project)1 CompressedDictionary (com.intellij.spellchecker.compress.CompressedDictionary)1 Loader (com.intellij.spellchecker.dictionary.Loader)1 Consumer (com.intellij.util.Consumer)1