Skip to content

Commit fae22a5

Browse files
committed
feat(idea): use most recent jdk for project
1 parent df5d4cd commit fae22a5

File tree

2 files changed

+47
-16
lines changed

2 files changed

+47
-16
lines changed

packages/plugin-idea/src/main/kotlin/dev/elide/intellij/project/model/ElideJdkContributor.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ class ElideJdkContributor : ElideProjectModelContributor {
3333
projectPath: Path
3434
) {
3535
// configure the project's JDK
36-
// TODO(@darvld): use configured JDK instead of choosing a default
37-
val jdkName = ProjectJdkTable.getInstance().allJdks.first().name
36+
val jdkName = ProjectJdkTable.getInstance().allJdks.lastOrNull()?.name
3837
projectNode.createChild(ProjectSdkData.KEY, ProjectSdkData(jdkName))
3938
}
4039

@@ -45,8 +44,7 @@ class ElideJdkContributor : ElideProjectModelContributor {
4544
projectPath: Path
4645
) {
4746
// configure the module's JDK
48-
// TODO(@darvld): use configured JDK instead of choosing a default
49-
val jdkName = ProjectJdkTable.getInstance().allJdks.first().name
47+
val jdkName = ProjectJdkTable.getInstance().allJdks.lastOrNull()?.name
5048
moduleNode.createChild(ModuleSdkData.KEY, ModuleSdkData(jdkName))
5149
}
5250
}

packages/plugin-idea/src/main/kotlin/dev/elide/intellij/service/ElideCliService.kt

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class ElideCliService(private val project: Project, private val serviceScope: Co
7979
*/
8080
fun launch(
8181
elideBinary: Path,
82-
projectPath: String,
82+
workdir: String? = null,
8383
scope: CoroutineScope,
8484
buildCommand: MutableList<String>.() -> Unit
8585
): ElideProcess {
@@ -89,7 +89,7 @@ class ElideCliService(private val project: Project, private val serviceScope: Co
8989
}
9090

9191
val process = ProcessBuilder(command)
92-
.directory(File(projectPath))
92+
.also { if (workdir != null) it.directory(File(workdir)) }
9393
.start()
9494

9595
return ElideProcess(process, scope, scope.async { process.awaitExit() })
@@ -98,19 +98,52 @@ class ElideCliService(private val project: Project, private val serviceScope: Co
9898
}
9999

100100
/**
101-
* Launch the Elide CLI binary as a subprocess and wrap it in [ElideProcess] for easy handling. The settings of the
102-
* linked project at [projectPath] are used to select an Elide distribution to be invoked.
101+
* A bridge used to call an Elide Command Line distribution at a specific path. Use the command methods to interface
102+
* with the CLI without blocking.
103103
*/
104-
private fun launchElide(projectPath: String, buildCommand: MutableList<String>.() -> Unit): ElideProcess {
105-
val elideHome = ElideDistributionResolver.getElideHome(project, projectPath)
106-
val elideBin = elideHome.resolve(Constants.ELIDE_BINARY)
104+
class ElideCommandLine private constructor(
105+
private val elideHome: Path,
106+
private val scope: CoroutineScope,
107+
) {
108+
/** Invoke the Elide CLI with the `--version` option in a background context and return its output. */
109+
suspend fun version(workdir: String? = null): String = withContext(Dispatchers.IO) {
110+
val elide = launchElide(elideHome, workdir, buildCommand = { add("--version") })
111+
elide.readStdOut()
112+
}
107113

108-
return ElideProcess.launch(elideBin, projectPath, serviceScope, buildCommand)
114+
/**
115+
* Launch the Elide CLI binary as a subprocess and wrap it in [ElideProcess] for easy handling. The settings of the
116+
* linked project at [workdir] are used to select an Elide distribution to be invoked.
117+
*/
118+
private fun launchElide(
119+
elideHome: Path,
120+
workdir: String? = null,
121+
buildCommand: MutableList<String>.() -> Unit
122+
): ElideProcess {
123+
val elideBin = elideHome.resolve(Constants.ELIDE_BINARY)
124+
return ElideProcess.launch(elideBin, workdir, scope, buildCommand)
125+
}
126+
127+
companion object {
128+
fun at(elideHome: Path, scope: CoroutineScope): ElideCommandLine {
129+
return ElideCommandLine(elideHome, scope)
130+
}
131+
}
132+
}
133+
134+
/** Returns a configured [ElideCommandLine] at the given [elideHome]. */
135+
fun at(elideHome: Path): ElideCommandLine {
136+
return ElideCommandLine.at(elideHome, serviceScope)
109137
}
110138

111-
/** Invoke the Elide CLI with the `--version` option in a background context and return its output. */
112-
fun version(projectPath: String): Deferred<String> = serviceScope.async {
113-
val elide = launchElide(projectPath, buildCommand = { add("--version") })
114-
elide.readStdOut()
139+
/** Resolves an [ElideCommandLine] for the linked project at [externalProjectPath]. */
140+
fun resolve(externalProjectPath: String): ElideCommandLine {
141+
return ElideCommandLine.at(ElideDistributionResolver.getElideHome(project, externalProjectPath), serviceScope)
142+
}
143+
144+
companion object {
145+
fun getInstance(project: Project): ElideCliService {
146+
return project.getService(ElideCliService::class.java)
147+
}
115148
}
116149
}

0 commit comments

Comments
 (0)