in rider-fsharp/src/main/java/com/jetbrains/rider/plugins/fsharp/services/fsi/FsiHost.kt [50:121]
suspend fun getFsiRunOptions(
project: Project,
configuration: FSharpScriptConfiguration? = null,
debug: Boolean = false,
): Pair<DotNetExecutable, DotNetRuntime> {
val fsiHost = FsiHost.getInstance(project)
val sessionInfo = fsiHost.rdFsiHost.requestNewFsiSessionInfo.startSuspending(Unit)
val runtimeHost = RiderDotNetActiveRuntimeHost.getInstance(project)
val exePath = when (sessionInfo.runtime) {
RdFsiRuntime.Core -> runtimeHost.dotNetCoreRuntime.value?.cliExePath?.pathString
RdFsiRuntime.NetFramework -> sessionInfo.fsiPath
RdFsiRuntime.Mono -> {
val runtime = runtimeHost.getCurrentClassicNetRuntime(false).runtime as MonoRuntime
runtime.getMonoExe().pathString
}
}
val workingDirectory =
if (project.isDirectoryBased) {
val projectDir = project.guessProjectDir()
val workingDir =
if (projectDir != null && projectDir.exists()) projectDir
else VfsUtil.getUserHomeDir()
workingDir?.path ?: ""
} else ""
val runtimeType = when (sessionInfo.runtime) {
RdFsiRuntime.NetFramework -> MsNetRuntimeType
RdFsiRuntime.Mono -> MonoRuntimeType
RdFsiRuntime.Core -> DotNetCoreRuntimeType
}
val args = ArrayList<String>()
val sessionArgs = ArrayList(sessionInfo.args)
if (sessionInfo.runtime != RdFsiRuntime.NetFramework)
args.add(sessionInfo.fsiPath)
if (configuration != null)
args.add("--use:${configuration.scriptFile?.path}")
if (debug) {
args.addAll(listOf("--optimize-", "--debug+"))
sessionArgs.remove("--optimize+")
}
args.addAll(sessionArgs)
val parameters = DotNetExeConfigurationParameters(
project = project,
exePath = exePath ?: "",
programParameters = ParametersListUtil.join(args),
workingDirectory = workingDirectory,
envs = configuration?.envs ?: mapOf(),
isPassParentEnvs = true,
executeAsIs = false,
assemblyToDebug = null,
runtimeType = runtimeType,
runtimeArguments = ""
)
val dotNetExecutable = parameters.toDotNetExecutableSuspending(ProcessExecutionDetails.Default)
val dotNetRuntime = DotNetRuntime.detectRuntimeForExeOrThrow(
project,
runtimeHost,
dotNetExecutable.exePath,
dotNetExecutable.runtimeType,
dotNetExecutable.projectTfm
)
val patchedExecutable = dotNetExecutable.copy(usePty = false)
return Pair(patchedExecutable, dotNetRuntime)
}