Skip to content

Commit b2ee9ff

Browse files
committed
refactor(devins-kotlin): extract for UnstableApiUsage #100
This commit refactors the RunService to leverage the new ExecutionManager API, improving the execution flow and callback handling.
1 parent 8e47d2e commit b2ee9ff

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

src/main/kotlin/cc/unitmesh/devti/provider/RunService.kt

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -188,40 +188,40 @@ interface RunService {
188188
private fun RunnerAndConfigurationSettings.startRunConfigurationExecution(context: Context): Boolean {
189189
val runner = ProgramRunner.getRunner(DefaultRunExecutor.EXECUTOR_ID, configuration)
190190
val env =
191-
ExecutionEnvironmentBuilder.create(DefaultRunExecutor.getRunExecutorInstance(), this).activeTarget().build()
191+
ExecutionEnvironmentBuilder.create(DefaultRunExecutor.getRunExecutorInstance(), this)
192+
.activeTarget()
193+
.build(callback(context))
192194

193195
if (runner == null || env.state == null) {
194196
context.latch.countDown()
195197
return false
196198
}
197199

200+
context.environments.add(env)
201+
runner.execute(env)
202+
return true
203+
}
198204

199-
@Suppress("UnstableApiUsage")
200-
env.callback = ProgramRunner.Callback { descriptor ->
201-
// Descriptor can be null in some cases.
202-
// For example, IntelliJ Rust's test runner provides null here if compilation fails
203-
if (descriptor == null) {
204-
context.latch.countDown()
205-
return@Callback
206-
}
205+
fun callback(context: Context) = ProgramRunner.Callback { descriptor ->
206+
// Descriptor can be null in some cases.
207+
// For example, IntelliJ Rust's test runner provides null here if compilation fails
208+
if (descriptor == null) {
209+
context.latch.countDown()
210+
return@Callback
211+
}
207212

208-
Disposer.register(context, Disposable {
209-
ExecutionManagerImpl.stopProcess(descriptor)
213+
Disposer.register(context, Disposable {
214+
ExecutionManagerImpl.stopProcess(descriptor)
215+
})
216+
val processHandler = descriptor.processHandler
217+
if (processHandler != null) {
218+
processHandler.addProcessListener(object : ProcessAdapter() {
219+
override fun processTerminated(event: ProcessEvent) {
220+
context.latch.countDown()
221+
}
210222
})
211-
val processHandler = descriptor.processHandler
212-
if (processHandler != null) {
213-
processHandler.addProcessListener(object : ProcessAdapter() {
214-
override fun processTerminated(event: ProcessEvent) {
215-
context.latch.countDown()
216-
}
217-
})
218-
context.processListener?.let { processHandler.addProcessListener(it) }
219-
}
223+
context.processListener?.let { processHandler.addProcessListener(it) }
220224
}
221-
222-
context.environments.add(env)
223-
runner.execute(env)
224-
return true
225225
}
226226

227227

0 commit comments

Comments
 (0)