Skip to content

Commit

Permalink
Merge pull request #288 from JetBrains/revert-286
Browse files Browse the repository at this point in the history
Temporarily revert #286
  • Loading branch information
rafaelldi authored Nov 11, 2024
2 parents a1a051a + 5a4bc59 commit 39460b8
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 125 deletions.
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ pluginRepositoryUrl = https://github.com/JetBrains/aspire-plugin
pluginVersion = 1.6.2

# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
pluginSinceBuild = 251
pluginUntilBuild = 251.*
pluginSinceBuild = 243
pluginUntilBuild = 243.*

# IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#configuration-intellij-extension
# Examples:
# Release: 2020.2
# EAP: 2020.3-EAP2-SNAPSHOT
# Nightly: 2020.3-SNAPSHOT
platformVersion = 2025.1-SNAPSHOT
platformVersion = 2024.3-EAP4-SNAPSHOT

dotnetBuildConfiguration = Release

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import com.intellij.openapi.application.EDT
import com.intellij.openapi.project.Project
import com.intellij.openapi.rd.util.lifetime
import com.intellij.openapi.startup.ProjectActivity
import com.jetbrains.rd.util.threading.coroutines.launch
import com.intellij.util.application
import com.jetbrains.rd.util.reactive.adviseOnce
import com.jetbrains.rider.aspire.run.FunctionLaunchProfilesService
import com.jetbrains.rider.run.configurations.runnableProjectsModelIfAvailable
import kotlinx.coroutines.Dispatchers
Expand All @@ -13,11 +14,11 @@ import kotlinx.coroutines.withContext
class WarmupStartupActivity: ProjectActivity {
override suspend fun execute(project: Project) {
withContext(Dispatchers.EDT) {
project.runnableProjectsModelIfAvailable?.projects?.view(project.lifetime) { lt, projects ->
lt.launch(Dispatchers.Default) {
FunctionLaunchProfilesService.getInstance(project).initialize(projects)
project.runnableProjectsModelIfAvailable?.projects?.adviseOnce(project.lifetime) {
application.runReadAction {
FunctionLaunchProfilesService.getInstance(project).initialize(it)
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,29 +44,25 @@ class AspireHostConfigurationType : ConfigurationTypeBase(

val result = mutableListOf<Pair<RunnableProject, RunnerAndConfigurationSettings>>()

for (runnableProject in aspireHostProjects) {
val profiles = LaunchSettingsJsonService.getInstance(project).loadLaunchSettingsSuspend(
LaunchSettingsJsonService.getLaunchSettingsFileForProject(runnableProject) ?: continue
)?.profiles ?: continue
for (profile in profiles) {
aspireHostProjects.forEach { runnableProject ->
LaunchSettingsJsonService.loadLaunchSettings(runnableProject)?.profiles?.forEach { profile ->
if (!profile.value.commandName.equals("Project", true))
continue
return@forEach

if (hasRunConfigurationEverBeenGenerated(
autoGeneratedRunConfigurationManager,
runnableProject.projectFilePath,
profile.key
)
) continue
) return@forEach

val configurationName =
if (runnableProject.name == profile.key) profile.key
else "${runnableProject.name}: ${profile.key}"

if (runManager.hasConfigurationForNameAndTypeId(configurationName, ID) ||
runManager.hasConfigurationForNameAndTypeId(runnableProject.name, ID)
)
continue
runManager.hasConfigurationForNameAndTypeId(runnableProject.name, ID))
return@forEach

val configuration = generateConfigurationForProfile(
configurationName,
Expand Down Expand Up @@ -113,7 +109,7 @@ class AspireHostConfigurationType : ConfigurationTypeBase(
)
}

private suspend fun generateConfigurationForProfile(
private fun generateConfigurationForProfile(
name: String,
runnableProject: RunnableProject,
profile: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
package com.jetbrains.rider.aspire.run

import com.intellij.openapi.application.EDT
import com.intellij.openapi.application.ModalityState
import com.intellij.openapi.application.asContextElement
import com.intellij.openapi.project.Project
import com.jetbrains.rd.util.lifetime.Lifetime
import com.jetbrains.rd.util.lifetime.SequentialLifetimes
import com.jetbrains.rd.util.threading.coroutines.launch
import com.jetbrains.rd.util.threading.coroutines.nextNotNullValue
import com.jetbrains.rd.util.reactive.adviseOnce
import com.jetbrains.rider.model.ProjectOutput
import com.jetbrains.rider.model.RunnableProject
import com.jetbrains.rider.model.RunnableProjectsModel
Expand All @@ -17,13 +12,11 @@ import com.jetbrains.rider.run.configurations.controls.startBrowser.BrowserSetti
import com.jetbrains.rider.run.configurations.controls.startBrowser.BrowserSettingsEditor
import com.jetbrains.rider.run.configurations.launchSettings.LaunchSettingsJson
import com.jetbrains.rider.run.configurations.project.DotNetStartBrowserParameters
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import java.io.File

class AspireHostConfigurationViewModel(
private val project: Project,
lifetime: Lifetime,
private val lifetime: Lifetime,
private val runnableProjectsModel: RunnableProjectsModel?,
val projectSelector: ProjectSelector,
val tfmSelector: StringSelector,
Expand Down Expand Up @@ -82,12 +75,12 @@ class AspireHostConfigurationViewModel(
if (!isLoaded) return

reloadTfmSelector(runnableProject)
reloadLaunchProfileSelector(runnableProject) {
val projectOutput = getSelectedProjectOutput() ?: return@reloadLaunchProfileSelector
val launchProfile = launchProfileSelector.profile.valueOrNull ?: return@reloadLaunchProfileSelector
reloadLaunchProfileSelector(runnableProject)

recalculateFields(projectOutput, launchProfile)
}
val projectOutput = getSelectedProjectOutput() ?: return
val launchProfile = launchProfileSelector.profile.valueOrNull ?: return

recalculateFields(projectOutput, launchProfile)
}

private fun reloadTfmSelector(runnableProject: RunnableProject) {
Expand All @@ -101,21 +94,14 @@ class AspireHostConfigurationViewModel(
}
}

private fun reloadLaunchProfileSelector(runnableProject: RunnableProject, onLoadingComplete: (() -> Unit)? = null) {
launchProfileSelector.profile.set(LaunchProfile("", LaunchSettingsJson.Profile.UNKNOWN))

currentEditSessionLifetime.launch(Dispatchers.Default + ModalityState.current().asContextElement()) {
val launchProfiles = FunctionLaunchProfilesService.getInstance(project).getLaunchProfiles(runnableProject)
withContext(Dispatchers.EDT) {
launchProfileSelector.profileList.apply {
clear()
addAll(launchProfiles)
}
if (launchProfiles.any()) {
launchProfileSelector.profile.set(launchProfiles.first())
}
onLoadingComplete?.invoke()
}
private fun reloadLaunchProfileSelector(runnableProject: RunnableProject) {
val launchProfiles = FunctionLaunchProfilesService.getInstance(project).getLaunchProfiles(runnableProject)
launchProfileSelector.profileList.apply {
clear()
addAll(launchProfiles)
}
if (launchProfiles.any()) {
launchProfileSelector.profile.set(launchProfiles.first())
}
}

Expand Down Expand Up @@ -215,9 +201,6 @@ class AspireHostConfigurationViewModel(
trackUrl = urlEditor.text.value == applicationUrl
}

private val currentEditSessionLifetimeSource = SequentialLifetimes(lifetime)
private lateinit var currentEditSessionLifetime: Lifetime

fun reset(
projectFilePath: String,
projectTfm: String,
Expand All @@ -233,15 +216,13 @@ class AspireHostConfigurationViewModel(
dotNetStartBrowserParameters: DotNetStartBrowserParameters
) {
isLoaded = false
currentEditSessionLifetime = currentEditSessionLifetimeSource.next()

this.trackArguments = trackArguments
this.trackWorkingDirectory = trackWorkingDirectory
this.trackEnvs = trackEnvs
this.trackUrl = trackUrl

currentEditSessionLifetime.launch(Dispatchers.EDT + ModalityState.current().asContextElement()) {
val projectList = getProjectList() ?: return@launch
runnableProjectsModel?.projects?.adviseOnce(lifetime) { projectList ->
usePodmanRuntimeFlagEditor.isSelected.set(usePodmanRuntime)

dotNetBrowserSettingsEditor.settings.set(
Expand Down Expand Up @@ -281,9 +262,6 @@ class AspireHostConfigurationViewModel(
}
}

private suspend fun getProjectList(): List<RunnableProject>? = runnableProjectsModel?.projects?.nextNotNullValue()


private fun addFirstFunctionProject(projectList: List<RunnableProject>) {
val runnableProject = projectList.firstOrNull { it.kind == AspireRunnableProjectKinds.AspireHost }
?: return
Expand Down Expand Up @@ -331,54 +309,55 @@ class AspireHostConfigurationViewModel(

projectSelector.project.set(runnableProject)
reloadTfmSelector(runnableProject)
reloadLaunchProfileSelector(runnableProject) {
val selectedTfm =
if (tfm.isNotEmpty()) tfmSelector.stringList.firstOrNull { it == tfm }
else tfmSelector.stringList.firstOrNull()
if (selectedTfm != null) {
tfmSelector.string.set(selectedTfm)
} else {
tfmSelector.string.set("")
}
val selectedProfile =
if (launchProfile.isNotEmpty()) launchProfileSelector.profileList.firstOrNull { it.name == launchProfile }
else launchProfileSelector.profileList.firstOrNull()
if (selectedProfile != null) {
launchProfileSelector.profile.set(selectedProfile)
} else {
val fakeLaunchProfile = LaunchProfile(launchProfile, LaunchSettingsJson.Profile.UNKNOWN)
launchProfileSelector.profileList.add(fakeLaunchProfile)
launchProfileSelector.profile.set(fakeLaunchProfile)
}
if (selectedTfm != null && selectedProfile != null) {
val selectedOutput = getSelectedProjectOutput() ?: return@reloadLaunchProfileSelector

val effectiveArguments =
if (trackArguments) getArguments(selectedProfile.content, selectedOutput)
else arguments
programParametersEditor.defaultValue.set(effectiveArguments)
programParametersEditor.parametersString.set(effectiveArguments)

val effectiveWorkingDirectory =
if (trackWorkingDirectory) getWorkingDirectory(selectedProfile.content, selectedOutput)
else workingDirectory
workingDirectorySelector.defaultValue.set(effectiveWorkingDirectory)
workingDirectorySelector.path.set(effectiveWorkingDirectory)

val effectiveEnvs =
if (trackEnvs) getEnvironmentVariables(selectedProfile.name, selectedProfile.content)
else envs
environmentVariablesEditor.envs.set(effectiveEnvs)

val effectiveUrl =
if (trackUrl) getApplicationUrl(selectedProfile.content)
else dotNetStartBrowserParameters.url
urlEditor.defaultValue.value = effectiveUrl
urlEditor.text.value = effectiveUrl
}
reloadLaunchProfileSelector(runnableProject)

val selectedTfm =
if (tfm.isNotEmpty()) tfmSelector.stringList.firstOrNull { it == tfm }
else tfmSelector.stringList.firstOrNull()
if (selectedTfm != null) {
tfmSelector.string.set(selectedTfm)
} else {
tfmSelector.string.set("")
}

val selectedProfile =
if (launchProfile.isNotEmpty()) launchProfileSelector.profileList.firstOrNull { it.name == launchProfile }
else launchProfileSelector.profileList.firstOrNull()
if (selectedProfile != null) {
launchProfileSelector.profile.set(selectedProfile)
} else {
val fakeLaunchProfile = LaunchProfile(launchProfile, LaunchSettingsJson.Profile.UNKNOWN)
launchProfileSelector.profileList.add(fakeLaunchProfile)
launchProfileSelector.profile.set(fakeLaunchProfile)
}
}

if (selectedTfm != null && selectedProfile != null) {
val selectedOutput = getSelectedProjectOutput() ?: return

val effectiveArguments =
if (trackArguments) getArguments(selectedProfile.content, selectedOutput)
else arguments
programParametersEditor.defaultValue.set(effectiveArguments)
programParametersEditor.parametersString.set(effectiveArguments)

val effectiveWorkingDirectory =
if (trackWorkingDirectory) getWorkingDirectory(selectedProfile.content, selectedOutput)
else workingDirectory
workingDirectorySelector.defaultValue.set(effectiveWorkingDirectory)
workingDirectorySelector.path.set(effectiveWorkingDirectory)

val effectiveEnvs =
if (trackEnvs) getEnvironmentVariables(selectedProfile.name, selectedProfile.content)
else envs
environmentVariablesEditor.envs.set(effectiveEnvs)

val effectiveUrl =
if (trackUrl) getApplicationUrl(selectedProfile.content)
else dotNetStartBrowserParameters.url
urlEditor.defaultValue.value = effectiveUrl
urlEditor.text.value = effectiveUrl
}
}

private fun getSelectedProjectOutput(): ProjectOutput? {
val selectedProject = projectSelector.project.valueOrNull ?: return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class AspireHostExecutorFactory(
.getInstance(project)
.getLaunchProfileByName(runnableProject, parameters.profileName)
?: throw CantRunException("Profile ${parameters.profileName} not found")

val executable = getDotNetExecutable(runnableProject, projectOutput, profile)

return when (executorId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,29 @@ import com.intellij.openapi.project.Project
import com.jetbrains.rider.model.RunnableProject
import com.jetbrains.rider.run.configurations.controls.LaunchProfile
import com.jetbrains.rider.run.configurations.launchSettings.LaunchSettingsJsonService
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import java.io.File
import java.util.concurrent.ConcurrentHashMap

@Service(Service.Level.PROJECT)
class FunctionLaunchProfilesService(val project: Project) {
class FunctionLaunchProfilesService {
companion object {
fun getInstance(project: Project): FunctionLaunchProfilesService = project.service()
}

private val cache = ConcurrentHashMap<String, Pair<Long, List<LaunchProfile>>>()

suspend fun initialize(runnableProjects: List<RunnableProject>) {
for (it in runnableProjects) {
fun initialize(runnableProjects: List<RunnableProject>) {
runnableProjects.forEach {
val launchSettingsFile = LaunchSettingsJsonService.getLaunchSettingsFileForProject(it)
?: continue
?: return@forEach
val profiles = getLaunchProfiles(launchSettingsFile)
cache[launchSettingsFile.absolutePath] = Pair(launchSettingsFile.lastModified(), profiles)
}
}

suspend fun getLaunchProfiles(runnableProject: RunnableProject): List<LaunchProfile> {
val launchSettingsFile = withContext(Dispatchers.IO) {
LaunchSettingsJsonService.getLaunchSettingsFileForProject(runnableProject)
} ?: return emptyList()
fun getLaunchProfiles(runnableProject: RunnableProject): List<LaunchProfile> {
val launchSettingsFile = LaunchSettingsJsonService.getLaunchSettingsFileForProject(runnableProject)
?: return emptyList()

val launchSettingsFileStamp = launchSettingsFile.lastModified()
val existingLaunchProfile = cache[launchSettingsFile.absolutePath]
Expand All @@ -44,13 +41,12 @@ class FunctionLaunchProfilesService(val project: Project) {
return existingLaunchProfile.second
}

suspend fun getLaunchProfileByName(runnableProject: RunnableProject, launchProfileName: String?): LaunchProfile? =
fun getLaunchProfileByName(runnableProject: RunnableProject, launchProfileName: String?): LaunchProfile? =
getLaunchProfiles(runnableProject).find { it.name == launchProfileName }

private suspend fun getLaunchProfiles(launchSettingsFile: File): List<LaunchProfile> {
val launchSettings = withContext(Dispatchers.IO) {
LaunchSettingsJsonService.getInstance(project).loadLaunchSettings(launchSettingsFile)
} ?: return emptyList()
private fun getLaunchProfiles(launchSettingsFile: File): List<LaunchProfile> {
val launchSettings = LaunchSettingsJsonService.loadLaunchSettings(launchSettingsFile)
?: return emptyList()

return launchSettings
.profiles
Expand Down
Loading

0 comments on commit 39460b8

Please sign in to comment.