Skip to content

Commit

Permalink
Debug projects via profile
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelldi committed Sep 26, 2024
1 parent 04acaf3 commit d1c8daa
Show file tree
Hide file tree
Showing 16 changed files with 454 additions and 522 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ import com.jetbrains.rider.runtime.dotNetCore.DotNetCoreRuntime
import kotlinx.coroutines.ExperimentalCoroutinesApi

class AspireHostDebugProfileState(
dotNetExecutable: DotNetExecutable,
dotNetRuntime: DotNetCoreRuntime,
dotnetExecutable: DotNetExecutable,
dotnetRuntime: DotNetCoreRuntime,
environment: ExecutionEnvironment
) : DotNetCoreDebugProfile(
dotNetRuntime,
dotNetExecutable,
dotnetRuntime,
dotnetExecutable,
environment,
dotNetRuntime.cliExePath
dotnetRuntime.cliExePath
), AspireHostProfileState {

override val environmentVariables: Map<String, String> = dotNetExecutable.environmentVariables
override val environmentVariables: Map<String, String> = dotnetExecutable.environmentVariables

override suspend fun createWorkerRunInfo(
lifetime: Lifetime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ import com.jetbrains.rider.runtime.dotNetCore.DotNetCoreRuntime
import kotlin.io.path.Path

class AspireHostRunProfileState(
private val dotNetExecutable: DotNetExecutable,
private val dotNetRuntime: DotNetCoreRuntime,
private val dotnetExecutable: DotNetExecutable,
private val dotnetRuntime: DotNetCoreRuntime,
private val environment: ExecutionEnvironment
) : RunProfileState, AspireHostProfileState {

override val environmentVariables: Map<String, String> = dotNetExecutable.environmentVariables
override val environmentVariables: Map<String, String> = dotnetExecutable.environmentVariables

override fun execute(
executor: Executor?,
runner: ProgramRunner<*>
): ExecutionResult {
dotNetExecutable.validate()
dotnetExecutable.validate()

val commandLine = dotNetExecutable.createRunCommandLine(dotNetRuntime)
val commandLine = dotnetExecutable.createRunCommandLine(dotnetRuntime)
val originalExecutable = Path(commandLine.exePath)
val processHandler = TerminalProcessHandler(
environment.project,
Expand All @@ -42,7 +42,7 @@ class AspireHostRunProfileState(
environment.project
)

dotNetExecutable.onBeforeProcessStarted(environment, environment.runProfile, processHandler)
dotnetExecutable.onBeforeProcessStarted(environment, environment.runProfile, processHandler)

return DefaultExecutionResult(console, processHandler)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class SessionProcessLauncher(private val project: Project) {
return
}

if (debuggingMode || sessionModel.debug) {
if (debuggingMode) {
launchDebugProcess(
sessionId,
sessionModel,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.jetbrains.rider.aspire.sessionHost.dotnetProject

import com.intellij.execution.Executor
import com.intellij.execution.configurations.RunProfile
import com.intellij.execution.process.ProcessListener
import com.intellij.execution.runners.ExecutionEnvironment
import com.jetbrains.rd.util.lifetime.Lifetime
import com.jetbrains.rider.aspire.sessionHost.projectLaunchers.ProjectSessionDebugProfileState
import com.jetbrains.rider.debugger.IRiderDebuggable
import com.jetbrains.rider.runtime.DotNetExecutable
import com.jetbrains.rider.runtime.dotNetCore.DotNetCoreRuntime
import icons.RiderIcons

class DotNetProjectSessionDebugProfile(
private val sessionId: String,
private val projectName: String,
private val dotnetExecutable: DotNetExecutable,
private val dotnetRuntime: DotNetCoreRuntime,
private val sessionProcessEventListener: ProcessListener,
private val sessionProcessTerminatedListener: ProcessListener,
private val sessionProcessLifetime: Lifetime
) : RunProfile, IRiderDebuggable {
override fun getName() = projectName

override fun getIcon() = RiderIcons.RunConfigurations.DotNetProject

override fun getState(
executor: Executor,
environment: ExecutionEnvironment
) = ProjectSessionDebugProfileState(
sessionId,
dotnetExecutable,
dotnetRuntime,
environment,
sessionProcessEventListener,
sessionProcessTerminatedListener,
sessionProcessLifetime
)
}
Original file line number Diff line number Diff line change
@@ -1,39 +1,15 @@
@file:Suppress("UnstableApiUsage")

package com.jetbrains.rider.aspire.sessionHost.dotnetProject

import com.intellij.execution.DefaultExecutionResult
import com.intellij.execution.ExecutionResult
import com.intellij.execution.process.ProcessListener
import com.intellij.execution.runners.ExecutionEnvironment
import com.intellij.ide.browsers.StartBrowserSettings
import com.intellij.openapi.application.EDT
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.diagnostic.trace
import com.intellij.openapi.project.Project
import com.jetbrains.rd.util.lifetime.Lifetime
import com.jetbrains.rider.aspire.generated.SessionModel
import com.jetbrains.rider.aspire.run.AspireHostConfiguration
import com.jetbrains.rider.aspire.sessionHost.projectLaunchers.BaseProjectSessionProcessLauncher
import com.jetbrains.rider.debugger.createAndStartSession
import com.jetbrains.rider.run.ConsoleKind
import com.jetbrains.rider.run.IDebuggerOutputListener
import com.jetbrains.rider.run.createConsole
import com.jetbrains.rider.runtime.DotNetExecutable
import com.jetbrains.rider.runtime.DotNetRuntime
import com.jetbrains.rider.runtime.dotNetCore.DotNetCoreRuntime
import icons.RiderIcons
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import java.nio.file.Path
import kotlin.io.path.Path
import kotlin.io.path.nameWithoutExtension

class DotNetProjectSessionProcessLauncher : BaseProjectSessionProcessLauncher() {
companion object {
private val LOG = logger<DotNetProjectSessionProcessLauncher>()
}

override val priority = 10

override val hotReloadExtension = DotNetProjectHotReloadConfigurationExtension()
Expand All @@ -44,7 +20,7 @@ class DotNetProjectSessionProcessLauncher : BaseProjectSessionProcessLauncher()
sessionId: String,
projectName: String,
dotnetExecutable: DotNetExecutable,
dotnetRuntime: DotNetRuntime,
dotnetRuntime: DotNetCoreRuntime,
sessionProcessEventListener: ProcessListener,
sessionProcessTerminatedListener: ProcessListener,
sessionProcessLifetime: Lifetime
Expand All @@ -58,100 +34,23 @@ class DotNetProjectSessionProcessLauncher : BaseProjectSessionProcessLauncher()
sessionProcessLifetime
)

override suspend fun launchDebugProcess(
override fun getDebugProfile(
sessionId: String,
sessionModel: SessionModel,
sessionProcessEventListener: ProcessListener,
sessionProcessTerminatedListener: ProcessListener,
sessionProcessLifetime: Lifetime,
hostRunConfiguration: AspireHostConfiguration?,
project: Project
) {
LOG.trace { "Starting debug session for project ${sessionModel.projectPath}" }

val (executable, browserSettings) = getDotNetExecutable(sessionModel, hostRunConfiguration, true, project) ?: return
val runtime = getDotNetRuntime(executable, project) ?: return

withContext(Dispatchers.EDT) {
createAndStartDebugSession(
sessionId,
Path(sessionModel.projectPath),
executable,
runtime,
browserSettings,
hostRunConfiguration,
sessionProcessEventListener,
sessionProcessTerminatedListener,
sessionProcessLifetime,
project
)
}
}

private suspend fun createAndStartDebugSession(
sessionId: String,
sessionProjectPath: Path,
projectName: String,
projectPath: Path,
dotnetExecutable: DotNetExecutable,
dotnetRuntime: DotNetCoreRuntime,
browserSettings: StartBrowserSettings?,
hostRunConfiguration: AspireHostConfiguration?,
sessionProcessEventListener: ProcessListener,
sessionProcessTerminatedListener: ProcessListener,
sessionProcessLifetime: Lifetime,
project: Project
) {
val debuggerSessionId = ExecutionEnvironment.getNextUnusedExecutionId()

val debuggerWorkerSession = initDebuggerSession(
sessionId,
debuggerSessionId,
dotnetExecutable,
dotnetRuntime,
sessionProcessEventListener,
sessionProcessTerminatedListener,
sessionProcessLifetime,
project,
{ }
)

val executionResult =
executeDebuggerSession(debuggerWorkerSession, browserSettings, hostRunConfiguration, project)

createAndStartSession(
executionResult.executionConsole,
null,
project,
sessionProcessLifetime,
executionResult.processHandler,
debuggerWorkerSession.protocol,
debuggerWorkerSession.debugSessionModel,
object : IDebuggerOutputListener {},
debuggerSessionId
) { xDebuggerManager, xDebugProcessStarter ->
xDebuggerManager.startSessionAndShowTab(
sessionProjectPath.nameWithoutExtension,
RiderIcons.RunConfigurations.DotNetProject,
null,
false,
xDebugProcessStarter
)
}
}

private fun executeDebuggerSession(
session: DebuggerWorkerSession,
browserSettings: StartBrowserSettings?,
hostRunConfiguration: AspireHostConfiguration?,
project: Project
): ExecutionResult {
val console = createConsole(
ConsoleKind.Normal,
session.debuggerWorkerProcessHandler.debuggerWorkerRealHandler,
project
)

startBrowser(hostRunConfiguration, browserSettings, session.debuggerWorkerProcessHandler)

return DefaultExecutionResult(console, session.debuggerWorkerProcessHandler)
}
sessionProcessLifetime: Lifetime
) = DotNetProjectSessionDebugProfile(
sessionId,
projectName,
dotnetExecutable,
dotnetRuntime,
sessionProcessEventListener,
sessionProcessTerminatedListener,
sessionProcessLifetime
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import com.jetbrains.rd.util.lifetime.Lifetime
import com.jetbrains.rider.aspire.sessionHost.projectLaunchers.ProjectSessionRunProfile
import com.jetbrains.rider.aspire.sessionHost.projectLaunchers.ProjectSessionRunProfileState
import com.jetbrains.rider.runtime.DotNetExecutable
import com.jetbrains.rider.runtime.DotNetRuntime
import com.jetbrains.rider.runtime.dotNetCore.DotNetCoreRuntime

class DotNetProjectSessionRunProfile(
private val sessionId: String,
projectName: String,
private val dotnetExecutable: DotNetExecutable,
private val dotnetRuntime: DotNetRuntime,
private val dotnetRuntime: DotNetCoreRuntime,
private val sessionProcessEventListener: ProcessListener,
private val sessionProcessTerminatedListener: ProcessListener,
private val sessionProcessLifetime: Lifetime
Expand Down
Loading

0 comments on commit d1c8daa

Please sign in to comment.