Search in sources :

Example 1 with SdkRunConfig

use of io.flutter.run.SdkRunConfig in project flutter-intellij by flutter.

the class AttachDebuggerAction method update.

@Override
public void update(AnActionEvent e) {
    final Project project = e.getProject();
    if (project == null || project.isDefault()) {
        super.update(e);
        return;
    }
    if (!FlutterSdkUtil.hasFlutterModules(project)) {
        // Hide this button in Android projects.
        e.getPresentation().setVisible(false);
        return;
    }
    RunConfiguration configuration = findRunConfig(project);
    boolean enabled;
    if (configuration == null) {
        final RunnerAndConfigurationSettings settings = RunManagerEx.getInstanceEx(project).getSelectedConfiguration();
        if (settings == null) {
            enabled = false;
        } else {
            configuration = settings.getConfiguration();
            enabled = configuration instanceof SdkRunConfig;
        }
    } else {
        enabled = true;
    }
    if (enabled && (project.getUserData(ATTACH_IS_ACTIVE) != null)) {
        enabled = false;
    }
    e.getPresentation().setVisible(true);
    e.getPresentation().setEnabled(enabled);
}
Also used : Project(com.intellij.openapi.project.Project) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) SdkRunConfig(io.flutter.run.SdkRunConfig)

Example 2 with SdkRunConfig

use of io.flutter.run.SdkRunConfig in project flutter-intellij by flutter.

the class AttachDebuggerAction method findRunConfig.

@Nullable
public static RunConfiguration findRunConfig(Project project) {
    // Look for a Flutter run config. If exactly one is found then return it otherwise return null.
    final RunManagerEx mgr = RunManagerEx.getInstanceEx(project);
    final List<RunConfiguration> configs = mgr.getAllConfigurationsList();
    int count = 0;
    RunConfiguration sdkConfig = null;
    for (RunConfiguration config : configs) {
        if (config instanceof SdkRunConfig) {
            count += 1;
            sdkConfig = config;
        }
    }
    return count == 1 ? sdkConfig : null;
}
Also used : RunConfiguration(com.intellij.execution.configurations.RunConfiguration) SdkRunConfig(io.flutter.run.SdkRunConfig) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with SdkRunConfig

use of io.flutter.run.SdkRunConfig in project flutter-intellij by flutter.

the class FlutterModuleUtils method autoCreateRunConfig.

/**
 * Creates a Flutter run configuration if none exists.
 */
public static void autoCreateRunConfig(@NotNull Project project, @NotNull PubRoot root) {
    assert ApplicationManager.getApplication().isReadAccessAllowed();
    if (project.isDisposed())
        return;
    VirtualFile main = root.getLibMain();
    if (main == null || !main.exists()) {
        // Check for example main.dart in plugins
        main = root.getExampleLibMain();
        if (main == null || !main.exists()) {
            return;
        }
    }
    final FlutterRunConfigurationType configType = FlutterRunConfigurationType.getInstance();
    final RunManager runManager = RunManager.getInstance(project);
    if (!runManager.getConfigurationsList(configType).isEmpty()) {
        // Don't create a run config if one already exists.
        return;
    }
    final RunnerAndConfigurationSettings settings = runManager.createConfiguration(project.getName(), configType.getFactory());
    final SdkRunConfig config = (SdkRunConfig) settings.getConfiguration();
    // Set config name.
    config.setName("main.dart");
    // Set fields.
    final SdkFields fields = new SdkFields();
    fields.setFilePath(main.getPath());
    config.setFields(fields);
    runManager.addConfiguration(settings);
    runManager.setSelectedConfiguration(settings);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SdkRunConfig(io.flutter.run.SdkRunConfig) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) SdkFields(io.flutter.run.SdkFields) RunManager(com.intellij.execution.RunManager) FlutterRunConfigurationType(io.flutter.run.FlutterRunConfigurationType)

Example 4 with SdkRunConfig

use of io.flutter.run.SdkRunConfig in project flutter-intellij by flutter.

the class AttachDebuggerAction method startCommand.

@Override
public void startCommand(@NotNull Project project, @NotNull FlutterSdk sdk, @Nullable PubRoot root, @NotNull DataContext context) {
    // NOTE: When making changes here, consider making similar changes to RunFlutterAction.
    FlutterInitializer.sendAnalyticsAction(this);
    RunConfiguration configuration = findRunConfig(project);
    if (configuration == null) {
        final RunnerAndConfigurationSettings settings = RunManagerEx.getInstanceEx(project).getSelectedConfiguration();
        if (settings == null) {
            showSelectConfigDialog();
            return;
        }
        configuration = settings.getConfiguration();
        if (!(configuration instanceof SdkRunConfig)) {
            if (project.isDefault() || !FlutterSdkUtil.hasFlutterModules(project)) {
                return;
            }
            showSelectConfigDialog();
            return;
        }
    }
    final SdkAttachConfig sdkRunConfig = new SdkAttachConfig((SdkRunConfig) configuration);
    final Executor executor = RunFlutterAction.getExecutor(ToolWindowId.DEBUG);
    if (executor == null) {
        return;
    }
    final ExecutionEnvironmentBuilder builder = ExecutionEnvironmentBuilder.create(executor, sdkRunConfig);
    final ExecutionEnvironment env = builder.activeTarget().dataContext(context).build();
    FlutterLaunchMode.addToEnvironment(env, FlutterLaunchMode.DEBUG);
    if (project.getUserData(ATTACH_IS_ACTIVE) == null) {
        project.putUserData(ATTACH_IS_ACTIVE, ThreeState.fromBoolean(false));
        onAttachTermination(project, (p) -> p.putUserData(ATTACH_IS_ACTIVE, null));
    }
    ProgramRunnerUtil.executeConfiguration(env, false, true);
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) SdkRunConfig(io.flutter.run.SdkRunConfig) ExecutionEnvironmentBuilder(com.intellij.execution.runners.ExecutionEnvironmentBuilder) SdkAttachConfig(io.flutter.run.SdkAttachConfig)

Example 5 with SdkRunConfig

use of io.flutter.run.SdkRunConfig in project flutter-intellij by flutter.

the class RunFlutterAction method shouldEnable.

private static boolean shouldEnable(@Nullable AnActionEvent e) {
    final RunnerAndConfigurationSettings settings = getRunConfigSettings(e);
    final RunConfiguration config = settings == null ? null : settings.getConfiguration();
    // TODO(pq): add support for Bazel.
    return config instanceof SdkRunConfig && LaunchState.getRunningAppProcess((SdkRunConfig) config) == null;
}
Also used : RunConfiguration(com.intellij.execution.configurations.RunConfiguration) SdkRunConfig(io.flutter.run.SdkRunConfig) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings)

Aggregations

SdkRunConfig (io.flutter.run.SdkRunConfig)6 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)5 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)3 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)2 ExecutionEnvironmentBuilder (com.intellij.execution.runners.ExecutionEnvironmentBuilder)2 SdkFields (io.flutter.run.SdkFields)2 Executor (com.intellij.execution.Executor)1 RunManager (com.intellij.execution.RunManager)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 FlutterRunConfigurationType (io.flutter.run.FlutterRunConfigurationType)1 SdkAttachConfig (io.flutter.run.SdkAttachConfig)1 ArrayList (java.util.ArrayList)1 Nullable (org.jetbrains.annotations.Nullable)1