Skip to content

Commit

Permalink
Run Aspire from the configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelldi committed Nov 25, 2023
1 parent 685c813 commit dd13cc5
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 11 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
annotations = "24.0.1"

# plugins
kotlin = "1.9.20"
kotlin = "1.9.21"
changelog = "2.2.0"
gradleIntelliJPlugin = "1.16.0"
qodana = "0.1.13"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,41 @@
namespace AspirePlugin.RunnableProject;

[SolutionComponent]
public class AspireRunnableProjectProvider : IRunnableProjectProvider
public class AspireRunnableProjectProvider(
ProjectRunnableOutputDetector projectRunnableOutputDetector,
ILogger logger
) : IRunnableProjectProvider
{
public JetBrains.Rider.Model.RunnableProject? CreateRunnableProject(IProject project, string name, string fullName, IconModel? icon)
public JetBrains.Rider.Model.RunnableProject? CreateRunnableProject(
IProject project,
string name,
string fullName,
IconModel? icon)
{
if (!project.IsDotNetCoreProject()) return null;

var isAspireHost = project.GetUniqueRequestedProjectProperty(IsAspireHost);
if (isAspireHost.IsNullOrEmpty() || isAspireHost != "true") return null;

var projectOutputs = new List<ProjectOutput>();
foreach (var tfm in project.TargetFrameworkIds)
{
var projectOutput = projectRunnableOutputDetector.CalculateProjectOutput(project, tfm);
if (projectOutput == null)
{
logger.Trace("Unable to find output for project for {0}", tfm);
continue;
}

projectOutputs.Add(projectOutput);
}

return new JetBrains.Rider.Model.RunnableProject(
name,
fullName,
project.ProjectFileLocation.NormalizeSeparators(FileSystemPathEx.SeparatorStyle.Unix),
AspireRunnableProjectKinds.AspireHost,
[],
projectOutputs,
[],
null,
[]
Expand Down
5 changes: 2 additions & 3 deletions src/dotnet/aspire-plugin/ZoneMarker.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using JetBrains.Application.BuildScript.Application.Zones;
using JetBrains.ProjectModel;
using JetBrains.ReSharper.Psi.CSharp;
using JetBrains.ReSharper.Features.Running;

namespace AspirePlugin;

[ZoneMarker]
public class ZoneMarker : IRequire<ILanguageCSharpZone>, IRequire<IProjectModelZone>;
public class ZoneMarker : IRequire<RunnableProjectsZone>;
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import com.jetbrains.rider.run.configurations.project.DotNetStartBrowserParamete

class AspireHostConfigurationFactory(type: AspireHostConfigurationType) :
DotNetConfigurationFactoryBase<AspireHostConfiguration>(type) {
override fun getId() = "Aspire Host"

override fun createTemplateConfiguration(project: Project) = AspireHostConfiguration(
project,
this,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package com.github.rafaelldi.aspireplugin.run

import com.intellij.execution.configurations.RunConfiguration
import com.intellij.execution.configurations.RunProfile
import com.intellij.execution.configurations.RuntimeConfigurationError
import com.intellij.execution.process.ProcessHandler
import com.intellij.execution.runners.ExecutionEnvironment
import com.intellij.ide.browsers.BrowserStarter
import com.intellij.ide.browsers.StartBrowserSettings
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.JDOMExternalizerUtil
import com.jetbrains.rider.model.RunnableProject
Expand All @@ -22,6 +28,19 @@ class AspireHostConfigurationParameters(
private const val TRACK_URL = "TRACK_URL"
}

val startBrowserAction: (ExecutionEnvironment, RunProfile, ProcessHandler) -> Unit =
{ _, runProfile, processHandler ->
if (startBrowserParameters.startAfterLaunch && runProfile is RunConfiguration) {
val startBrowserSettings = StartBrowserSettings().apply {
isSelected = startBrowserParameters.startAfterLaunch
url = startBrowserParameters.url
browser = startBrowserParameters.browser
isStartJavaScriptDebugger = startBrowserParameters.withJavaScriptDebugger
}
BrowserStarter(runProfile, startBrowserSettings, processHandler).start()
}
}

fun validate() {
val runnableProjects = project.solution.runnableProjectsModel.projects.valueOrNull
if (project.solution.isLoaded.valueOrNull != true || runnableProjects == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@ import com.intellij.execution.executors.DefaultDebugExecutor
import com.intellij.execution.executors.DefaultRunExecutor
import com.intellij.execution.runners.ExecutionEnvironment
import com.intellij.openapi.project.Project
import com.intellij.util.execution.ParametersListUtil
import com.jetbrains.rd.util.lifetime.Lifetime
import com.jetbrains.rider.model.RunnableProject
import com.jetbrains.rider.model.runnableProjectsModel
import com.jetbrains.rider.projectView.solution
import com.jetbrains.rider.run.configurations.AsyncExecutorFactory
import com.jetbrains.rider.run.configurations.project.DotNetProjectConfigurationParameters
import com.jetbrains.rider.run.configurations.project.getRunOptions

Check warning on line 16 in src/main/kotlin/com/github/rafaelldi/aspireplugin/run/AspireHostExecutorFactory.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import directive

Unused import directive
import com.jetbrains.rider.runtime.DotNetExecutable
import com.jetbrains.rider.runtime.RiderDotNetActiveRuntimeHost

class AspireHostExecutorFactory(
private val project: Project,
Expand All @@ -17,9 +25,50 @@ class AspireHostExecutorFactory(
executorId: String,
environment: ExecutionEnvironment,
lifetime: Lifetime
): RunProfileState = when (executorId) {
DefaultDebugExecutor.EXECUTOR_ID -> throw CantRunException("")
DefaultRunExecutor.EXECUTOR_ID -> throw CantRunException("")
else -> throw CantRunException("")
): RunProfileState {
val activeRuntime = RiderDotNetActiveRuntimeHost.getInstance(project).dotNetCoreRuntime.value
?: throw CantRunException("Unable to find appropriate runtime")

val projects = project.solution.runnableProjectsModel.projects.valueOrNull
?: throw CantRunException(DotNetProjectConfigurationParameters.SOLUTION_IS_LOADING)

val runnableProject = projects.singleOrNull {
AspireHostConfigurationType.isTypeApplicable(it.kind) && it.projectFilePath == parameters.projectFilePath
} ?: throw CantRunException(DotNetProjectConfigurationParameters.PROJECT_NOT_SPECIFIED)

val executable = getDotNetExecutable(
runnableProject
)

return when (executorId) {
DefaultDebugExecutor.EXECUTOR_ID -> activeRuntime.createRunState(executable, environment)
DefaultRunExecutor.EXECUTOR_ID -> activeRuntime.createRunState(executable, environment)
else -> throw CantRunException("")
}
}

private fun getDotNetExecutable(
runnableProject: RunnableProject
): DotNetExecutable {
val projectOutput = runnableProject.projectOutputs.firstOrNull()
?: throw CantRunException("Unable to find project output")

return DotNetExecutable(
projectOutput.exePath,
projectOutput.tfm,
projectOutput.workingDirectory,
ParametersListUtil.join(projectOutput.defaultArguments),
false,

Check notice on line 61 in src/main/kotlin/com/github/rafaelldi/aspireplugin/run/AspireHostExecutorFactory.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Boolean literal argument without parameter name

Boolean literal argument without a parameter name
false,

Check notice on line 62 in src/main/kotlin/com/github/rafaelldi/aspireplugin/run/AspireHostExecutorFactory.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Boolean literal argument without parameter name

Boolean literal argument without a parameter name
mapOf(
"DEBUG_SESSION_PORT" to "localhost:5000",
"DEBUG_SESSION_TOKEN" to "123"
),
true,
parameters.startBrowserAction,
null,
"",
true
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.github.rafaelldi.aspireplugin.run

import com.intellij.execution.configurations.RunProfile
import com.jetbrains.rider.debugger.DotNetProgramRunner

class AspireHostProgramRunner : DotNetProgramRunner() {
override fun canRun(executorId: String, runConfiguration: RunProfile) = runConfiguration is AspireHostConfiguration
}
1 change: 1 addition & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<extensions defaultExtensionNs="com.intellij">
<configurationType implementation="com.github.rafaelldi.aspireplugin.run.AspireHostConfigurationType"/>
<programRunner implementation="com.github.rafaelldi.aspireplugin.run.AspireHostProgramRunner"/>
</extensions>

</idea-plugin>

0 comments on commit dd13cc5

Please sign in to comment.