Skip to content

Commit 3b16ded

Browse files
committed
(#264, #265) Settings: store a setting with working directory
1 parent c9c1dc8 commit 3b16ded

File tree

4 files changed

+45
-17
lines changed

4 files changed

+45
-17
lines changed

src/rider/main/kotlin/me/fornever/avaloniarider/idea/settings/AvaloniaWorkspaceSettings.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@ import java.nio.file.Paths
1515
*/
1616
class AvaloniaWorkspaceState : BaseState() {
1717
var projectPerEditor by map<String, String>()
18+
19+
// TODO[#265]: Move to AvaloniaProjectSettingsState
20+
var workingDirectory by property<WorkingDirectorySpecification>(DefinedByMsBuild) { it == DefinedByMsBuild }
1821
}
1922

20-
@State(name = "AvaloniaProject", storages = [Storage("avalonia.xml")]) // TODO[#265]: move to a workspace-related file
23+
@State(name = "AvaloniaProject", storages = [Storage("avalonia.xml")]) // TODO[#265]: Move to a workspace-related file
2124
@Service(Service.Level.PROJECT)
2225
class AvaloniaWorkspaceSettings(private val project: Project) : SimplePersistentStateComponent<AvaloniaWorkspaceState>(
2326
AvaloniaWorkspaceState()
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package me.fornever.avaloniarider.idea.settings
2+
3+
import java.nio.file.Path
4+
5+
sealed interface WorkingDirectorySpecification {
6+
fun getPath(): Path
7+
}
8+
9+
object DefinedByMsBuild : WorkingDirectorySpecification {
10+
override fun getPath(): Path {
11+
TODO("Not yet implemented")
12+
}
13+
}
14+
15+
object SolutionDirectory : WorkingDirectorySpecification
16+
data class CustomPath(val path: String) : WorkingDirectorySpecification

src/rider/main/kotlin/me/fornever/avaloniarider/previewer/AvaloniaPreviewerProcess.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ data class AvaloniaPreviewerParameters(
3131
/**
3232
* Path to the assembly containing a XAML file in question.
3333
*/
34-
val xamlContainingAssemblyPath: Path
34+
val xamlContainingAssemblyPath: Path,
35+
val workingDirectory: Path
3536
)
3637

3738
class AvaloniaPreviewerProcess(
@@ -60,7 +61,7 @@ class AvaloniaPreviewerProcess(
6061
else -> GeneralCommandLine().withExePath(parameters.previewerBinary.toAbsolutePath().toString())
6162
.withParameters(previewerArguments)
6263
}
63-
return commandLine.withWorkDirectory(parameters.targetDir.toFile())
64+
return commandLine.withWorkDirectory(parameters.workingDirectory.toFile())
6465
}
6566

6667
private fun startProcess(

src/rider/main/kotlin/me/fornever/avaloniarider/previewer/MsBuildParameterCollector.kt

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,21 @@ import com.intellij.openapi.diagnostic.logger
55
import com.intellij.openapi.project.Project
66
import com.intellij.openapi.util.io.FileUtil
77
import com.intellij.workspaceModel.ide.toPath
8-
import com.jetbrains.rider.model.RdTargetFrameworkId
98
import com.jetbrains.rider.projectView.workspace.ProjectModelEntity
109
import com.jetbrains.rider.run.environment.MSBuildEvaluator
1110
import com.jetbrains.rider.runtime.DotNetRuntime
1211
import com.jetbrains.rider.runtime.RiderDotNetActiveRuntimeHost
1312
import com.jetbrains.rider.runtime.dotNetCore.DotNetCoreRuntime
1413
import me.fornever.avaloniarider.exceptions.AvaloniaPreviewerInitializationException
14+
import me.fornever.avaloniarider.idea.settings.AvaloniaWorkspaceSettings
1515
import me.fornever.avaloniarider.model.RdProjectOutput
1616
import me.fornever.avaloniarider.rider.AvaloniaRiderProjectModelHost
1717
import org.jetbrains.concurrency.await
1818
import java.nio.file.Path
1919
import java.nio.file.Paths
20-
import kotlin.io.path.ExperimentalPathApi
2120
import kotlin.io.path.nameWithoutExtension
2221

23-
@Service
22+
@Service(Service.Level.PROJECT)
2423
class MsBuildParameterCollector(private val project: Project) {
2524
companion object {
2625
fun getInstance(project: Project): MsBuildParameterCollector =
@@ -29,18 +28,22 @@ class MsBuildParameterCollector(private val project: Project) {
2928
private val logger = logger<MsBuildParameterCollector>()
3029
}
3130

31+
private val workspaceSettings
32+
get() = AvaloniaWorkspaceSettings.getInstance(project)
33+
3234
private fun getPathKey(runtime: DotNetRuntime): String = when (runtime) {
3335
is DotNetCoreRuntime -> "AvaloniaPreviewerNetCoreToolPath"
3436
else -> "AvaloniaPreviewerNetFullToolPath"
3537
}
3638

37-
@OptIn(ExperimentalPathApi::class)
3839
private fun createParameters(
3940
runtime: DotNetRuntime,
4041
runnableProjectFilePath: Path,
4142
avaloniaPreviewerPathKey: String,
4243
runnableProjectProperties: Map<String, String>,
43-
xamlContainingProjectProperties: Map<String, String>): AvaloniaPreviewerParameters {
44+
xamlContainingProjectProperties: Map<String, String>,
45+
runnableProjectWorkingDirectory: Path
46+
): AvaloniaPreviewerParameters {
4447
fun getProperty(properties: Map<String, String>, key: String, errorMessage: String? = null): String {
4548
val property = properties[key]
4649
if (property.isNullOrEmpty()) {
@@ -64,7 +67,15 @@ class MsBuildParameterCollector(private val project: Project) {
6467

6568
val xamlAssemblyPath = Paths.get(getProperty(xamlContainingProjectProperties, "TargetPath"))
6669

67-
return AvaloniaPreviewerParameters(runtime, previewerPath, targetDir, targetName, targetPath, xamlAssemblyPath)
70+
return AvaloniaPreviewerParameters(
71+
runtime,
72+
previewerPath,
73+
targetDir,
74+
targetName,
75+
targetPath,
76+
xamlAssemblyPath,
77+
workspaceSettings.state.workingDirectory.getPath()
78+
)
6879
}
6980

7081
@Suppress("UnstableApiUsage")
@@ -95,14 +106,9 @@ class MsBuildParameterCollector(private val project: Project) {
95106
val runtime = DotNetRuntime.detectRuntimeForProjectOrThrow(
96107
runnableProject.kind,
97108
runtimeHost,
98-
null,
109+
runtimeType = null,
99110
runnableProjectOutput.outputPath,
100-
RdTargetFrameworkId(
101-
tfm.shortName,
102-
tfm.presentableName,
103-
isNetCoreApp = tfm.isNetCoreApp,
104-
isNetFramework = tfm.isNetFramework
105-
)
111+
tfm
106112
)
107113
val avaloniaPreviewerPathKey = getPathKey(runtime)
108114

@@ -126,6 +132,8 @@ class MsBuildParameterCollector(private val project: Project) {
126132
runnableProjectFilePath,
127133
avaloniaPreviewerPathKey,
128134
runnableProjectProperties.await(),
129-
xamlProjectProperties.await())
135+
xamlProjectProperties.await(),
136+
TODO("Determine program working directory from the runnableProject")
137+
)
130138
}
131139
}

0 commit comments

Comments
 (0)