Search in sources :

Example 1 with DartRunConfigurationBase

use of com.jetbrains.lang.dart.ide.runner.base.DartRunConfigurationBase in project intellij-plugins by JetBrains.

the class DartRunner method doExecuteDartDebug.

private RunContentDescriptor doExecuteDartDebug(@NotNull final RunProfileState state, @NotNull final ExecutionEnvironment env, @Nullable final String dasExecutionContextId) throws RuntimeConfigurationError, ExecutionException {
    final DartSdk sdk = DartSdk.getDartSdk(env.getProject());
    // already checked
    assert (sdk != null);
    final RunProfile runConfiguration = env.getRunProfile();
    final VirtualFile contextFileOrDir;
    VirtualFile currentWorkingDirectory;
    final ExecutionResult executionResult;
    final String debuggingHost;
    final int observatoryPort;
    if (runConfiguration instanceof DartRunConfigurationBase) {
        contextFileOrDir = ((DartRunConfigurationBase) runConfiguration).getRunnerParameters().getDartFileOrDirectory();
        final String cwd = ((DartRunConfigurationBase) runConfiguration).getRunnerParameters().computeProcessWorkingDirectory(env.getProject());
        currentWorkingDirectory = LocalFileSystem.getInstance().findFileByPath((cwd));
        executionResult = state.execute(env.getExecutor(), this);
        if (executionResult == null) {
            return null;
        }
        debuggingHost = null;
        observatoryPort = ((DartCommandLineRunningState) state).getObservatoryPort();
    } else if (runConfiguration instanceof DartRemoteDebugConfiguration) {
        final String path = ((DartRemoteDebugConfiguration) runConfiguration).getParameters().getDartProjectPath();
        contextFileOrDir = LocalFileSystem.getInstance().findFileByPath(path);
        if (contextFileOrDir == null) {
            throw new RuntimeConfigurationError("Folder not found: " + FileUtil.toSystemDependentName(path));
        }
        currentWorkingDirectory = contextFileOrDir;
        executionResult = null;
        debuggingHost = ((DartRemoteDebugConfiguration) runConfiguration).getParameters().getHost();
        observatoryPort = ((DartRemoteDebugConfiguration) runConfiguration).getParameters().getPort();
    } else {
        LOG.error("Unexpected run configuration: " + runConfiguration.getClass().getName());
        return null;
    }
    FileDocumentManager.getInstance().saveAllDocuments();
    final XDebuggerManager debuggerManager = XDebuggerManager.getInstance(env.getProject());
    final XDebugSession debugSession = debuggerManager.startSession(env, new XDebugProcessStarter() {

        @Override
        @NotNull
        public XDebugProcess start(@NotNull final XDebugSession session) {
            final DartUrlResolver dartUrlResolver = getDartUrlResolver(env.getProject(), contextFileOrDir);
            return new DartVmServiceDebugProcess(session, StringUtil.notNullize(debuggingHost, "localhost"), observatoryPort, executionResult, dartUrlResolver, dasExecutionContextId, runConfiguration instanceof DartRemoteDebugConfiguration, getTimeout(), currentWorkingDirectory);
        }
    });
    return debugSession.getRunContentDescriptor();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XDebugSession(com.intellij.xdebugger.XDebugSession) XDebugProcess(com.intellij.xdebugger.XDebugProcess) DartRunConfigurationBase(com.jetbrains.lang.dart.ide.runner.base.DartRunConfigurationBase) XDebuggerManager(com.intellij.xdebugger.XDebuggerManager) ExecutionResult(com.intellij.execution.ExecutionResult) RunProfile(com.intellij.execution.configurations.RunProfile) NotNull(org.jetbrains.annotations.NotNull) DartVmServiceDebugProcess(com.jetbrains.lang.dart.ide.runner.server.vmService.DartVmServiceDebugProcess) DartSdk(com.jetbrains.lang.dart.sdk.DartSdk) DartRemoteDebugConfiguration(com.jetbrains.lang.dart.ide.runner.server.DartRemoteDebugConfiguration) XDebugProcessStarter(com.intellij.xdebugger.XDebugProcessStarter) DartUrlResolver(com.jetbrains.lang.dart.util.DartUrlResolver) RuntimeConfigurationError(com.intellij.execution.configurations.RuntimeConfigurationError)

Example 2 with DartRunConfigurationBase

use of com.jetbrains.lang.dart.ide.runner.base.DartRunConfigurationBase in project intellij-plugins by JetBrains.

the class DartRunner method doExecute.

@Override
protected RunContentDescriptor doExecute(@NotNull RunProfileState state, @NotNull ExecutionEnvironment env) throws ExecutionException {
    final String executorId = env.getExecutor().getId();
    if (!DefaultDebugExecutor.EXECUTOR_ID.equals(executorId)) {
        LOG.error("Unexpected executor id: " + executorId);
        return null;
    }
    try {
        final String dasExecutionContextId;
        final RunProfile runConfig = env.getRunProfile();
        if (runConfig instanceof DartRunConfigurationBase && DartAnalysisServerService.getInstance(env.getProject()).serverReadyForRequest(env.getProject())) {
            final String path = ((DartRunConfigurationBase) runConfig).getRunnerParameters().getFilePath();
            // already checked
            assert path != null;
            dasExecutionContextId = DartAnalysisServerService.getInstance(env.getProject()).execution_createContext(path);
        } else {
            // remote debug or can't start DAS
            dasExecutionContextId = null;
        }
        return doExecuteDartDebug(state, env, dasExecutionContextId);
    } catch (RuntimeConfigurationError e) {
        throw new ExecutionException(e);
    }
}
Also used : DartRunConfigurationBase(com.jetbrains.lang.dart.ide.runner.base.DartRunConfigurationBase) RunProfile(com.intellij.execution.configurations.RunProfile) ExecutionException(com.intellij.execution.ExecutionException) RuntimeConfigurationError(com.intellij.execution.configurations.RuntimeConfigurationError)

Aggregations

RunProfile (com.intellij.execution.configurations.RunProfile)2 RuntimeConfigurationError (com.intellij.execution.configurations.RuntimeConfigurationError)2 DartRunConfigurationBase (com.jetbrains.lang.dart.ide.runner.base.DartRunConfigurationBase)2 ExecutionException (com.intellij.execution.ExecutionException)1 ExecutionResult (com.intellij.execution.ExecutionResult)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 XDebugProcess (com.intellij.xdebugger.XDebugProcess)1 XDebugProcessStarter (com.intellij.xdebugger.XDebugProcessStarter)1 XDebugSession (com.intellij.xdebugger.XDebugSession)1 XDebuggerManager (com.intellij.xdebugger.XDebuggerManager)1 DartRemoteDebugConfiguration (com.jetbrains.lang.dart.ide.runner.server.DartRemoteDebugConfiguration)1 DartVmServiceDebugProcess (com.jetbrains.lang.dart.ide.runner.server.vmService.DartVmServiceDebugProcess)1 DartSdk (com.jetbrains.lang.dart.sdk.DartSdk)1 DartUrlResolver (com.jetbrains.lang.dart.util.DartUrlResolver)1 NotNull (org.jetbrains.annotations.NotNull)1