Search in sources :

Example 6 with LanguageClass

use of com.google.idea.blaze.base.model.primitives.LanguageClass in project intellij by bazelbuild.

the class AdditionalLanguagesHelper method enableLanguageSupport.

/**
 * Adds the specified languages to the project view's 'additional_languages' section, and
 * installs/enables any other required plugins.
 */
public static void enableLanguageSupport(Project project, List<LanguageClass> languages) {
    ProjectViewEdit edit = ProjectViewEdit.editLocalProjectView(project, builder -> {
        ListSection<LanguageClass> existingSection = builder.getLast(AdditionalLanguagesSection.KEY);
        builder.replace(existingSection, ListSection.update(AdditionalLanguagesSection.KEY, existingSection).addAll(languages));
        return true;
    });
    if (edit == null) {
        Messages.showErrorDialog("Could not modify project view. Check for errors in your project view and try again", "Error");
        return;
    }
    edit.apply();
    ImmutableSet<String> requiredPlugins = Arrays.stream(BlazeSyncPlugin.EP_NAME.getExtensions()).map(syncPlugin -> syncPlugin.getRequiredExternalPluginIds(languages)).flatMap(Collection::stream).collect(toImmutableSet());
    PluginUtils.installOrEnablePlugins(requiredPlugins);
    BlazeSyncManager.getInstance(project).requestProjectSync(new BlazeSyncParams.Builder("Sync", BlazeSyncParams.SyncMode.INCREMENTAL).addProjectViewTargets(true).addWorkingSet(BlazeUserSettings.getInstance().getExpandSyncToWorkingSet()).build());
}
Also used : ProjectViewEdit(com.google.idea.blaze.base.projectview.ProjectViewEdit) LanguageClass(com.google.idea.blaze.base.model.primitives.LanguageClass)

Example 7 with LanguageClass

use of com.google.idea.blaze.base.model.primitives.LanguageClass in project intellij by bazelbuild.

the class LanguageSupport method supportedLanguagesForWorkspaceType.

/**
 * @return The set of {@link LanguageClass}'s supported for this {@link WorkspaceType}s.
 */
public static Set<LanguageClass> supportedLanguagesForWorkspaceType(WorkspaceType type) {
    Set<LanguageClass> supportedLanguages = EnumSet.noneOf(LanguageClass.class);
    for (BlazeSyncPlugin syncPlugin : BlazeSyncPlugin.EP_NAME.getExtensions()) {
        supportedLanguages.addAll(syncPlugin.getSupportedLanguagesInWorkspace(type));
        supportedLanguages.addAll(syncPlugin.getAlwaysActiveLanguages());
    }
    supportedLanguages.add(LanguageClass.GENERIC);
    return supportedLanguages;
}
Also used : BlazeSyncPlugin(com.google.idea.blaze.base.sync.BlazeSyncPlugin) LanguageClass(com.google.idea.blaze.base.model.primitives.LanguageClass)

Example 8 with LanguageClass

use of com.google.idea.blaze.base.model.primitives.LanguageClass in project intellij by bazelbuild.

the class LanguageSupport method validateLanguageSettings.

public static boolean validateLanguageSettings(BlazeContext context, WorkspaceLanguageSettings languageSettings) {
    Set<WorkspaceType> supportedTypes = supportedWorkspaceTypes();
    WorkspaceType workspaceType = languageSettings.getWorkspaceType();
    if (!supportedTypes.contains(languageSettings.getWorkspaceType())) {
        IssueOutput.error(String.format("Workspace type '%s' is not supported by this plugin", languageSettings.getWorkspaceType().getName())).submit(context);
        return false;
    }
    Set<LanguageClass> supportedLanguages = supportedLanguagesForWorkspaceType(workspaceType);
    Set<LanguageClass> availableLanguages = EnumSet.noneOf(LanguageClass.class);
    for (WorkspaceType type : supportedTypes) {
        availableLanguages.addAll(supportedLanguagesForWorkspaceType(type));
    }
    for (LanguageClass languageClass : languageSettings.activeLanguages) {
        if (!availableLanguages.contains(languageClass)) {
            IssueOutput.error(String.format("Language '%s' is not supported by this plugin", languageClass.getName())).submit(context);
            return false;
        }
        if (!supportedLanguages.contains(languageClass)) {
            IssueOutput.error(String.format("Language '%s' is not supported for this plugin with workspace type: '%s'", languageClass.getName(), workspaceType.getName())).submit(context);
            return false;
        }
    }
    return true;
}
Also used : WorkspaceType(com.google.idea.blaze.base.model.primitives.WorkspaceType) LanguageClass(com.google.idea.blaze.base.model.primitives.LanguageClass)

Aggregations

LanguageClass (com.google.idea.blaze.base.model.primitives.LanguageClass)8 ImmutableSet (com.google.common.collect.ImmutableSet)3 WorkspaceLanguageSettings (com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings)3 Nullable (javax.annotation.Nullable)3 Joiner (com.google.common.base.Joiner)2 BiMap (com.google.common.collect.BiMap)2 HashBiMap (com.google.common.collect.HashBiMap)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 Lists (com.google.common.collect.Lists)2 Maps (com.google.common.collect.Maps)2 Ordering (com.google.common.collect.Ordering)2 Sets (com.google.common.collect.Sets)2 Futures (com.google.common.util.concurrent.Futures)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)2 IntellijIdeInfo (com.google.devtools.intellij.ideinfo.IntellijIdeInfo)2 FutureUtil (com.google.idea.blaze.base.async.FutureUtil)2 BlazeExecutor (com.google.idea.blaze.base.async.executor.BlazeExecutor)2 ExternalTask (com.google.idea.blaze.base.async.process.ExternalTask)2