Skip to content

Commit a905e63

Browse files
committed
refactor(exec): move process commands to process package
Relocated process-related InsCommand implementations to
1 parent e672328 commit a905e63

6 files changed

Lines changed: 31 additions & 24 deletions

File tree

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/exec/KillProcessInsCommand.kt renamed to exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/exec/process/KillProcessInsCommand.kt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package cc.unitmesh.devti.language.compiler.exec
1+
package cc.unitmesh.devti.language.compiler.exec.process
22

33
import cc.unitmesh.devti.command.InsCommand
44
import cc.unitmesh.devti.command.dataprovider.BuiltinCommand
@@ -14,47 +14,47 @@ class KillProcessInsCommand(
1414
private val project: Project,
1515
private val prop: String
1616
) : InsCommand {
17-
17+
1818
override val commandName: BuiltinCommand = BuiltinCommand.KILL_PROCESS
1919
private val logger = logger<KillProcessInsCommand>()
20-
20+
2121
override suspend fun execute(): String? {
22-
val processStateManager = ProcessStateManager.getInstance(project)
23-
22+
val processStateManager = ProcessStateManager.Companion.getInstance(project)
23+
2424
// Parse parameters
2525
val (processId, force) = parseParameters(prop)
26-
26+
2727
if (processId.isEmpty()) {
2828
return "Error: Process ID is required. Usage: /kill-process:process_id [--force]"
2929
}
30-
30+
3131
// Check if process exists
3232
val processInfo = processStateManager.getProcess(processId)
3333
if (processInfo == null) {
3434
return "Error: Process '$processId' not found."
3535
}
36-
36+
3737
// Check if process is already terminated
3838
if (processInfo.status != ProcessStatus.RUNNING) {
3939
return "Process '$processId' is already terminated (status: ${processInfo.status})."
4040
}
41-
41+
4242
// Kill the process
4343
val result = processStateManager.killProcess(processId, force)
44-
44+
4545
return if (result.success) {
4646
val killMethod = if (force) "forcefully killed" else "gracefully terminated"
4747
"Process '$processId' has been $killMethod successfully."
4848
} else {
4949
"Failed to kill process '$processId': ${result.errorMessage}"
5050
}
5151
}
52-
52+
5353
private fun parseParameters(prop: String): Pair<String, Boolean> {
5454
val parts = prop.trim().split(" ")
5555
val processId = parts.firstOrNull()?.trim() ?: ""
5656
val force = parts.any { it.trim() == "--force" }
57-
57+
5858
return Pair(processId, force)
5959
}
60-
}
60+
}

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/exec/LaunchProcessInsCommand.kt renamed to exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/exec/process/LaunchProcessInsCommand.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package cc.unitmesh.devti.language.compiler.exec
1+
package cc.unitmesh.devti.language.compiler.exec.process
22

33
import cc.unitmesh.devti.AutoDevNotifications
44
import cc.unitmesh.devti.command.InsCommand
@@ -13,11 +13,10 @@ import com.intellij.execution.process.ProcessOutputTypes
1313
import com.intellij.openapi.application.ApplicationManager
1414
import com.intellij.openapi.diagnostic.logger
1515
import com.intellij.openapi.project.Project
16-
import com.intellij.util.concurrency.AppExecutorUtil
16+
import com.intellij.openapi.util.Key
1717
import kotlinx.coroutines.*
1818
import java.io.File
1919
import java.nio.charset.StandardCharsets
20-
import java.util.concurrent.TimeUnit
2120

2221
/**
2322
* InsCommand implementation for launching processes
@@ -163,7 +162,7 @@ class LaunchProcessInsCommand(
163162
val errorCapture = StringBuilder()
164163

165164
processHandler.addProcessListener(object : ProcessAdapter() {
166-
override fun onTextAvailable(event: ProcessEvent, outputType: com.intellij.openapi.util.Key<*>) {
165+
override fun onTextAvailable(event: ProcessEvent, outputType: Key<*>) {
167166
when (outputType) {
168167
ProcessOutputTypes.STDOUT -> {
169168
outputCapture.append(event.text)
@@ -221,7 +220,7 @@ class LaunchProcessInsCommand(
221220

222221
// Add process listener
223222
processHandler.addProcessListener(object : ProcessAdapter() {
224-
override fun onTextAvailable(event: ProcessEvent, outputType: com.intellij.openapi.util.Key<*>) {
223+
override fun onTextAvailable(event: ProcessEvent, outputType: Key<*>) {
225224
when (outputType) {
226225
ProcessOutputTypes.STDOUT -> {
227226
processStateManager.appendStdout(processInfo.processId, event.text)

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/exec/ListProcessesInsCommand.kt renamed to exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/exec/process/ListProcessesInsCommand.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
package cc.unitmesh.devti.language.compiler.exec
1+
package cc.unitmesh.devti.language.compiler.exec.process
22

33
import cc.unitmesh.devti.command.InsCommand
44
import cc.unitmesh.devti.command.dataprovider.BuiltinCommand
5+
import cc.unitmesh.devti.process.ProcessInfo
56
import cc.unitmesh.devti.process.ProcessStateManager
67
import cc.unitmesh.devti.process.ProcessStatus
78
import com.intellij.openapi.project.Project
@@ -42,7 +43,7 @@ class ListProcessesInsCommand(
4243
return match?.groupValues?.get(1)?.toIntOrNull() ?: 50
4344
}
4445

45-
private fun formatProcessList(processes: List<cc.unitmesh.devti.process.ProcessInfo>): String {
46+
private fun formatProcessList(processes: List<ProcessInfo>): String {
4647
val dateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault())
4748

4849
return buildString {

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/exec/ReadProcessOutputInsCommand.kt renamed to exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/exec/process/ReadProcessOutputInsCommand.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
package cc.unitmesh.devti.language.compiler.exec
1+
package cc.unitmesh.devti.language.compiler.exec.process
22

33
import cc.unitmesh.devti.command.InsCommand
44
import cc.unitmesh.devti.command.dataprovider.BuiltinCommand
5+
import cc.unitmesh.devti.process.ProcessInfo
56
import cc.unitmesh.devti.process.ProcessStateManager
7+
import cc.unitmesh.devti.process.ReadProcessOutputResponse
68
import com.intellij.openapi.project.Project
79

810
/**
@@ -78,8 +80,8 @@ class ReadProcessOutputInsCommand(
7880

7981
private fun formatOutput(
8082
processId: String,
81-
processInfo: cc.unitmesh.devti.process.ProcessInfo,
82-
outputResponse: cc.unitmesh.devti.process.ReadProcessOutputResponse,
83+
processInfo: ProcessInfo,
84+
outputResponse: ReadProcessOutputResponse,
8385
includeStdout: Boolean,
8486
includeStderr: Boolean,
8587
maxBytes: Int

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/exec/WriteProcessInputInsCommand.kt renamed to exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/exec/process/WriteProcessInputInsCommand.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package cc.unitmesh.devti.language.compiler.exec
1+
package cc.unitmesh.devti.language.compiler.exec.process
22

33
import cc.unitmesh.devti.command.InsCommand
44
import cc.unitmesh.devti.command.dataprovider.BuiltinCommand

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/processor/InsCommandFactory.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ import cc.unitmesh.devti.command.InsCommand
55
import cc.unitmesh.devti.command.dataprovider.BuiltinCommand
66
import cc.unitmesh.devti.command.dataprovider.BuiltinCommand.Companion.toolchainProviderName
77
import cc.unitmesh.devti.language.compiler.exec.*
8+
import cc.unitmesh.devti.language.compiler.exec.process.KillProcessInsCommand
9+
import cc.unitmesh.devti.language.compiler.exec.process.LaunchProcessInsCommand
10+
import cc.unitmesh.devti.language.compiler.exec.process.ListProcessesInsCommand
11+
import cc.unitmesh.devti.language.compiler.exec.process.ReadProcessOutputInsCommand
12+
import cc.unitmesh.devti.language.compiler.exec.process.WriteProcessInputInsCommand
813
import cc.unitmesh.devti.language.parser.CodeBlockElement
914
import cc.unitmesh.devti.language.psi.DevInTypes
1015
import cc.unitmesh.devti.language.psi.DevInUsed

0 commit comments

Comments
 (0)