Skip to content

Commit 46a4263

Browse files
committed
clean code
1 parent 9a80888 commit 46a4263

File tree

1 file changed

+3
-70
lines changed

1 file changed

+3
-70
lines changed

src/main/java/com/tang/intellij/lua/debugger/emmyLaunch/EmmyLaunchDebugProcess.kt

Lines changed: 3 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,7 @@ import com.intellij.xdebugger.XDebugSession
1010
import com.tang.intellij.lua.debugger.LogConsoleType
1111
import com.tang.intellij.lua.debugger.emmy.*
1212
import com.tang.intellij.lua.debugger.utils.FileUtils
13-
import java.io.BufferedReader
14-
import java.io.BufferedWriter
15-
import java.io.InputStreamReader
16-
import java.io.OutputStreamWriter
17-
import java.net.Socket
1813
import java.nio.charset.Charset
19-
import java.util.concurrent.ThreadLocalRandom
2014

2115

2216
class EmmyLaunchDebugProcess(
@@ -28,7 +22,7 @@ class EmmyLaunchDebugProcess(
2822
private var toolProcessHandler: ColoredProcessHandler? = null;
2923

3024
override fun setupTransporter() {
31-
LaunchDebug() { it ->
25+
launchDebug() { it ->
3226
attachTo(it)
3327
Thread.sleep(300)
3428
toolProcessHandler?.let { tool ->
@@ -65,68 +59,7 @@ class EmmyLaunchDebugProcess(
6559
return if (exitValue == 0) EmmyWinArch.X64 else EmmyWinArch.X86
6660
}
6761

68-
private fun LaunchWithWindows() {
69-
val port = getPort(ThreadLocalRandom.current().nextInt(10240) + 10240);
70-
val arch = detectArch()
71-
val path = FileUtils.getPluginVirtualFile("debugger/bin/win32-${arch}")
72-
val re = Regex("[^/\\\\]+\$")
73-
val mc = re.find(configuration.program)
74-
75-
val commandLine = GeneralCommandLine()
76-
commandLine.exePath = "wt"
77-
commandLine.setWorkDirectory(path)
78-
commandLine.addParameters(
79-
"--title",
80-
if (mc != null) mc.groups[0]?.value else configuration.program,
81-
"emmy_tool.exe",
82-
"run_and_attach",
83-
"-dll",
84-
"emmy_hook.dll",
85-
"-dir",
86-
"\"${path}\"",
87-
"-work",
88-
"\"${configuration.workingDirectory}\"",
89-
"-block-on-exit",
90-
"-exe",
91-
"\"${configuration.program}\"",
92-
"-debug-port",
93-
port.toString(),
94-
"-listen-mode",
95-
"-args",
96-
"\"${configuration.parameter}\""
97-
)
98-
99-
val handler = OSProcessHandler(commandLine)
100-
handler.addProcessListener(object : ProcessListener {
101-
override fun startNotified(processEvent: ProcessEvent) {
102-
}
103-
104-
override fun processTerminated(processEvent: ProcessEvent) {
105-
}
106-
107-
override fun processWillTerminate(processEvent: ProcessEvent, b: Boolean) {
108-
}
109-
110-
override fun onTextAvailable(processEvent: ProcessEvent, key: Key<*>) {
111-
when (key) {
112-
ProcessOutputTypes.STDERR -> print(
113-
processEvent.text,
114-
LogConsoleType.NORMAL,
115-
ConsoleViewContentType.ERROR_OUTPUT
116-
)
117-
118-
ProcessOutputTypes.STDOUT -> print(
119-
processEvent.text,
120-
LogConsoleType.NORMAL,
121-
ConsoleViewContentType.SYSTEM_OUTPUT
122-
)
123-
}
124-
}
125-
})
126-
handler.startNotify()
127-
}
128-
129-
private fun LaunchDebug(onConnected: (pid: Int) -> Unit) {
62+
private fun launchDebug(onConnected: (pid: Int) -> Unit) {
13063
val arch = detectArch()
13164
val path = FileUtils.getPluginVirtualFile("debugger/bin/win32-${arch}")
13265

@@ -147,7 +80,7 @@ class EmmyLaunchDebugProcess(
14780
"-exe",
14881
"\"${configuration.program}\"",
14982
"-args",
150-
"${configuration.parameter}"
83+
configuration.parameter
15184
)
15285

15386
charset = Charset.forName("utf8")

0 commit comments

Comments
 (0)