Search in sources :

Example 1 with Loader

use of com.intellij.spellchecker.dictionary.Loader 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)

Example 2 with Loader

use of com.intellij.spellchecker.dictionary.Loader in project intellij-community by JetBrains.

the class SpellCheckerManager method fillEngineDictionary.

private void fillEngineDictionary() {
    spellChecker.reset();
    final List<Loader> loaders = new SmartList<>();
    // Load bundled dictionaries from corresponding jars
    for (BundledDictionaryProvider provider : Extensions.getExtensions(BundledDictionaryProvider.EP_NAME)) {
        for (String dictionary : provider.getBundledDictionaries()) {
            if (settings == null || !settings.getBundledDisabledDictionariesPaths().contains(dictionary)) {
                final Class<? extends BundledDictionaryProvider> loaderClass = provider.getClass();
                final InputStream stream = loaderClass.getResourceAsStream(dictionary);
                if (stream != null) {
                    loaders.add(new StreamLoader(stream, dictionary));
                } else {
                    LOG.warn("Couldn't load dictionary '" + dictionary + "' with loader '" + loaderClass + "'");
                }
            }
        }
    }
    if (settings != null && settings.getDictionaryFoldersPaths() != null) {
        final Set<String> disabledDictionaries = settings.getDisabledDictionariesPaths();
        for (String folder : settings.getDictionaryFoldersPaths()) {
            SPFileUtil.processFilesRecursively(folder, s -> {
                if (!disabledDictionaries.contains(s)) {
                    loaders.add(new FileLoader(s, s));
                }
            });
        }
    }
    for (Loader loader : loaders) {
        spellChecker.loadDictionary(loader);
    }
    userDictionary = ServiceManager.getService(project, AggregatedDictionaryState.class).getDictionary();
    spellChecker.addModifiableDictionary(userDictionary);
}
Also used : InputStream(java.io.InputStream) Loader(com.intellij.spellchecker.dictionary.Loader) SmartList(com.intellij.util.SmartList)

Aggregations

Loader (com.intellij.spellchecker.dictionary.Loader)2 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 Consumer (com.intellij.util.Consumer)1 SmartList (com.intellij.util.SmartList)1 InputStream (java.io.InputStream)1