Skip to content

Commit a77d731

Browse files
committed
Initial Private Beta
1 parent 19b9431 commit a77d731

12 files changed

+188
-187
lines changed

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<!-- Plugin description -->
2-
This plugin adds support for using Pest PHP inside PhpStorm.
2+
This plugin adds debugging tool window for Trap inside PhpStorm.
33
<!-- Plugin description end -->

Diff for: src/main/kotlin/com/intellij/plugins/phpstorm_dd/NotificationConstants.kt

-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package com.intellij.plugins.phpstorm_dd
22

3-
/**
4-
* Constants for notifications.
5-
*/
63
object NotificationConstants {
74
const val NOTIFICATION_GROUP_ID = "TrapPlugin"
85
const val NOTIFICATION_TITLE = "Trap plugin"

Diff for: src/main/kotlin/com/intellij/plugins/phpstorm_dd/Preferences.kt

-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package com.intellij.plugins.phpstorm_dd
22

3-
/**
4-
* Constants for preferences.
5-
*/
63
object Preferences {
74
const val HTTP_PORT_DEFAULT = 8888
85
const val HTTP_PORT_KEY = "com.intellij.plugins.phpstorm_dd.http_port"

Diff for: src/main/kotlin/com/intellij/plugins/phpstorm_dd/PreferencesDialog.kt

+2-5
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ import javax.swing.JLabel
1111
import javax.swing.JPanel
1212
import javax.swing.JTextField
1313

14-
/**
15-
* Preferences component.
16-
*/
1714
class PreferencesDialog(
1815
project: Project?
1916
) : DialogWrapper(project) {
@@ -22,7 +19,7 @@ class PreferencesDialog(
2219

2320
override fun createCenterPanel(): JComponent? {
2421
val panel = JPanel(FlowLayout())
25-
panel.add(JLabel("Http Port: "))
22+
panel.add(JLabel("Port: "))
2623
val propertiesComponent = PropertiesComponent.getInstance()
2724
val httpPort = propertiesComponent.getInt(Preferences.HTTP_PORT_KEY, Preferences.HTTP_PORT_DEFAULT)
2825
portTextField = JTextField(httpPort.toString(), 6)
@@ -49,6 +46,6 @@ class PreferencesDialog(
4946

5047
init {
5148
init()
52-
title = "Proxy Preferences"
49+
title = "Preferences"
5350
}
5451
}

Diff for: src/main/kotlin/com/intellij/plugins/phpstorm_dd/StartTrapServerAction.kt

+14-3
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@ import com.intellij.openapi.actionSystem.AnAction
66
import com.intellij.openapi.actionSystem.AnActionEvent
77
import com.intellij.openapi.actionSystem.CommonDataKeys
88
import com.jetbrains.php.config.interpreters.PhpInterpretersManagerImpl
9-
import kotlinx.coroutines.isActive
9+
import kotlinx.coroutines.CoroutineScope
10+
import kotlinx.coroutines.Dispatchers
11+
import kotlinx.coroutines.launch
1012

1113

1214
class StartTrapServerAction()
1315
: AnAction("Start Server", "", AllIcons.Actions.Execute) {
1416

1517
override fun actionPerformed(event: AnActionEvent) {
1618

19+
event.presentation.isEnabled = false
20+
1721
val project = event.dataContext.getData(CommonDataKeys.PROJECT)
1822

1923
val interpretersManager = PhpInterpretersManagerImpl.getInstance(project)
@@ -24,12 +28,19 @@ class StartTrapServerAction()
2428
}
2529

2630
val trapServerService = event.project!!.getService(TrapServerService::class.java)
27-
trapServerService.startTrapServer(interpretersManager.interpreters[1])
31+
CoroutineScope(Dispatchers.IO).launch {
32+
trapServerService.startTrapServer(interpretersManager.interpreters[1])
33+
}
2834
}
2935

3036
override fun update(event: AnActionEvent) {
3137
val trapServerService = event.project!!.getService(TrapServerService::class.java)
32-
event.presentation.isEnabled = trapServerService.trapDaemon?.isActive == null || trapServerService.trapDaemon?.isActive == false
38+
val oldValue = event.presentation.isEnabled
39+
event.presentation.isEnabled = trapServerService.trapDaemon == null || trapServerService.trapDaemon?.isAlive == false
40+
41+
if (oldValue != event.presentation.isEnabled) {
42+
trapServerService.statusChanged()
43+
}
3344
}
3445

3546
override fun getActionUpdateThread(): ActionUpdateThread {

Diff for: src/main/kotlin/com/intellij/plugins/phpstorm_dd/StopTrapServerAction.kt

+11-9
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,26 @@ import com.intellij.notification.Notifications
77
import com.intellij.openapi.actionSystem.ActionUpdateThread
88
import com.intellij.openapi.actionSystem.AnAction
99
import com.intellij.openapi.actionSystem.AnActionEvent
10-
import kotlinx.coroutines.GlobalScope
11-
import kotlinx.coroutines.launch
1210

1311

14-
class StopTrapServerAction : AnAction("Stop Server", "", AllIcons.Actions.Suspend) {
12+
class StopTrapServerAction()
13+
: AnAction("Stop Server", "", AllIcons.Actions.Suspend) {
1514

1615
override fun actionPerformed(event: AnActionEvent) {
17-
notifyProxyShutdown()
16+
event.presentation.isEnabled = false
17+
// notifyProxyShutdown()
1818
val trapServerService = event.project!!.getService(TrapServerService::class.java)
19-
GlobalScope.launch {
20-
trapServerService.stopTrapServer()
21-
}
22-
19+
trapServerService.stopTrapServer()
2320
}
2421

2522
override fun update(event: AnActionEvent) {
2623
val trapServerService = event.project!!.getService(TrapServerService::class.java)
27-
event.presentation.isEnabled = trapServerService.trapDaemon?.isActive !== null && trapServerService.trapDaemon?.isActive == true
24+
val oldValue = event.presentation.isEnabled
25+
event.presentation.isEnabled = trapServerService.trapDaemon !== null && trapServerService.trapDaemon?.isAlive == true
26+
27+
if (oldValue != event.presentation.isEnabled) {
28+
trapServerService.statusChanged()
29+
}
2830
}
2931

3032
private fun notifyProxyShutdown() {
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,89 @@
11
package com.intellij.plugins.phpstorm_dd
22

33
import com.intellij.openapi.Disposable
4-
import com.intellij.openapi.components.ServiceManager
5-
import com.intellij.openapi.externalSystem.service.ui.completion.collector.TextCompletionCollector.Companion.async
64
import com.intellij.openapi.project.Project
7-
import com.intellij.platform.ijent.IjentProcessWatcher.Companion.launch
5+
import com.intellij.ui.jcef.JBCefBrowser
86
import java.io.File
97
import com.jetbrains.php.config.interpreters.PhpInterpreter
10-
import com.jetbrains.rd.generator.nova.PredefinedType
118
import kotlinx.coroutines.*
9+
import kotlinx.coroutines.channels.Channel
1210
import java.io.InputStream
13-
import java.util.concurrent.TimeUnit
1411

1512
class TrapServerService(
1613
private var project: Project?
1714
) : Disposable {
1815

19-
var trapDaemon: Job? = null
16+
var webview: JBCefBrowser? = null
17+
var trapDaemon: Process? = null
2018

2119
override fun dispose() {
2220
if (trapDaemon != null) {
23-
trapDaemon!!.cancel()
21+
trapDaemon!!.destroy()
2422
trapDaemon = null
2523
}
2624
}
27-
28-
fun startTrapServer(interpreter: PhpInterpreter) {
25+
26+
// private var processChannel: Channel<Process?>? = null
27+
private var processChannel = Channel<Process?>()
28+
29+
suspend fun startTrapServer(interpreter: PhpInterpreter) {
2930

30-
if (trapDaemon?.isActive == true) {
31+
if (trapDaemon?.isAlive == true) {
3132
return
3233
}
3334

3435
val cmdString = "%s %s/vendor/bin/trap --ui".format(interpreter.pathToPhpExecutable, project?.basePath)
3536
val cmdMap = cmdString.split(" ")
3637
val workingDir = File(project?.basePath!!)
3738

38-
// trapDaemon = ProcessBuilder(cmdMap)
39-
// .directory(workingDir)
40-
// .redirectOutput(ProcessBuilder.Redirect.INHERIT)
41-
// .redirectError(ProcessBuilder.Redirect.INHERIT)
42-
// .start()
43-
44-
45-
trapDaemon = CoroutineScope(Dispatchers.IO).launch {
39+
CoroutineScope(Dispatchers.IO).launch {
4640
executeCommand(cmdMap, workingDir)
4741
}
42+
43+
trapDaemon = processChannel.receive()
4844

4945
println("here")
5046
}
5147

52-
suspend fun stopTrapServer() {
48+
fun stopTrapServer() {
5349

54-
if (trapDaemon == null || !trapDaemon!!.isActive) {
50+
if (trapDaemon == null || !trapDaemon!!.isAlive) {
5551
return
5652
}
57-
58-
trapDaemon!!.cancel()
59-
trapDaemon!!.join()
53+
54+
trapDaemon?.destroy()
55+
}
56+
57+
fun statusChanged() {
58+
if (trapDaemon == null || !trapDaemon!!.isAlive) {
59+
webview?.loadHTML("Not Running");
60+
} else {
61+
webview?.loadURL("http://127.0.0.1:8000")
62+
}
6063
}
6164

6265
private suspend fun executeCommand(commandArgs: List<String>, workingDir: File): CoroutineScope = withContext(
6366
Dispatchers.IO
6467
) {
68+
var process: Process? = null
6569
runCatching {
66-
val process = ProcessBuilder(commandArgs)
70+
process = ProcessBuilder(commandArgs)
6771
.directory(workingDir)
72+
.redirectOutput(ProcessBuilder.Redirect.INHERIT)
73+
.redirectError(ProcessBuilder.Redirect.INHERIT)
6874
.start()
75+
76+
processChannel.send(process)
77+
6978
val outputStream = async {
70-
println("Context for output stream -> $coroutineContext -> Thread -> ${Thread.currentThread()}")
71-
readStream(process.inputStream) }
79+
readStream(process!!.inputStream) }
7280
val errorStream = async {
73-
println("Context for error stream -> $coroutineContext -> Thread -> ${Thread.currentThread()}")
74-
readStream(process.errorStream)
81+
readStream(process!!.errorStream)
7582
}
76-
println("Context for exit code -> $coroutineContext -> Thread -> ${Thread.currentThread()}")
77-
val exitCode = process.waitFor()
83+
val exitCode = process?.waitFor()
84+
7885
ProcessResult(
79-
exitCode = exitCode,
86+
exitCode = exitCode!!,
8087
message = outputStream.await(),
8188
errorMessage = errorStream.await()
8289
)
@@ -92,14 +99,8 @@ class TrapServerService(
9299
return@withContext this
93100
}
94101

95-
private fun readStream(inputStream: InputStream) =
96-
inputStream.bufferedReader().use { reader -> reader.readText() }
97-
98102
data class ProcessResult(val exitCode: Int, val message: String, val errorMessage: String)
99103

100-
companion object {
101-
fun getInstance(project: Project): TrapServerService {
102-
return ServiceManager.getService(project, TrapServerService::class.java)
103-
}
104-
}
104+
private fun readStream(inputStream: InputStream) =
105+
inputStream.bufferedReader().use { reader -> reader.readText() }
105106
}

Diff for: src/main/kotlin/com/intellij/plugins/phpstorm_dd/TrapToolWindowFactory.kt

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ class TrapToolWindowFactory : ToolWindowFactory {
1212
vertical = false,
1313
borderless = true
1414
)
15+
val trapServerService = project.getService(TrapServerService::class.java)
16+
trapServerService.webview = trapToolWindowPanel.webview
1517
val contentFactory = ContentFactory.SERVICE.getInstance()
1618
val content = contentFactory.createContent(trapToolWindowPanel, "", false)
1719
toolWindow.contentManager.addContent(content)

0 commit comments

Comments
 (0)