Skip to content

Commit d555fa2

Browse files
committed
Merge branch 'refs/heads/listener'
2 parents 6a6871a + 1aa4acc commit d555fa2

File tree

11 files changed

+184
-78
lines changed

11 files changed

+184
-78
lines changed

README.md

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
# PHP Dump
22

3-
![Build](https://github.com/xepozz/php-dump-plugin/workflows/Build/badge.svg)
4-
[![Version](https://img.shields.io/jetbrains/plugin/v/MARKETPLACE_ID.svg)](https://plugins.jetbrains.com/plugin/MARKETPLACE_ID)
5-
[![Downloads](https://img.shields.io/jetbrains/plugin/d/MARKETPLACE_ID.svg)](https://plugins.jetbrains.com/plugin/MARKETPLACE_ID)
6-
7-
## Template ToDo list
8-
- [x] Create a new [IntelliJ Platform Plugin Template][template] project.
9-
- [ ] Set the `MARKETPLACE_ID` in the above README badges. You can obtain it once the plugin is published to JetBrains Marketplace.
3+
![Build](https://github.com/j-plugins/php-dump-plugin/workflows/Build/badge.svg)
4+
[![Version](https://img.shields.io/jetbrains/plugin/v/28100-php-dump.svg)](https://plugins.jetbrains.com/plugin/28100-php-dump)
5+
[![Downloads](https://img.shields.io/jetbrains/plugin/d/28100-php-dump.svg)](https://plugins.jetbrains.com/plugin/28100-php-dump)
106

117
<!-- Plugin description -->
128

13-
[Github](https://github.com/xepozz/php-dump-plugin) | [Telegram](https://t.me/jb_plugins/50) | [Donation](https://github.com/xepozz/xepozz?tab=readme-ov-file#become-a-sponsor)
9+
[Github](https://github.com/j-plugins/php-dump-plugin) | [Telegram](https://t.me/jb_plugins/50) | [Donation](https://github.com/xepozz/xepozz?tab=readme-ov-file#become-a-sponsor)
1410

1511
## PHP Dump
1612

@@ -53,14 +49,14 @@ Chose the best option for you to say thank you:
5349

5450
- Using JetBrains Marketplace:
5551

56-
Go to [JetBrains Marketplace](https://plugins.jetbrains.com/plugin/MARKETPLACE_ID) and install it by clicking the <kbd>Install to ...</kbd> button in case your IDE is running.
52+
Go to [JetBrains Marketplace](https://plugins.jetbrains.com/plugin/28100-php-dump) and install it by clicking the <kbd>Install to ...</kbd> button in case your IDE is running.
5753

58-
You can also download the [latest release](https://plugins.jetbrains.com/plugin/MARKETPLACE_ID/versions) from JetBrains Marketplace and install it manually using
54+
You can also download the [latest release](https://plugins.jetbrains.com/plugin/28100-php-dump/versions) from JetBrains Marketplace and install it manually using
5955
<kbd>Settings/Preferences</kbd> > <kbd>Plugins</kbd> > <kbd>⚙️</kbd> > <kbd>Install plugin from disk...</kbd>
6056

6157
- Manually:
6258

63-
Download the [latest release](https://github.com/xepozz/php-dump-plugin/releases/latest) and install it manually using
59+
Download the [latest release](https://github.com/j-plugins/php-dump-plugin/releases/latest) and install it manually using
6460
<kbd>Settings/Preferences</kbd> > <kbd>Plugins</kbd> > <kbd>⚙️</kbd> > <kbd>Install plugin from disk...</kbd>
6561

6662

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pluginGroup = com.github.xepozz.php_dump
44
pluginName = PHP Dump
55
pluginRepositoryUrl = https://github.com/xepozz/php-opcodes-plugin
66
# SemVer format -> https://semver.org
7-
pluginVersion = 2025.0.11
7+
pluginVersion = 2025.0.12
88

99
# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
1010
pluginSinceBuild = 231
@@ -16,7 +16,7 @@ platformVersion = 2025.1.1
1616

1717
# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
1818
# Example: platformPlugins = com.jetbrains.php:203.4449.22, org.intellij.scala:2023.3.27@EAP
19-
platformPlugins=com.jetbrains.php:251.23774.318,com.jetbrains.hackathon.indices.viewer:1.30,com.github.xepozz.php_opcodes_language:2025.0.7
19+
platformPlugins=com.jetbrains.php:251.23774.318,com.jetbrains.hackathon.indices.viewer:1.30,com.github.xepozz.php_opcodes_language:2025.0.12
2020
# Example: platformBundledPlugins = com.intellij.java
2121
platformBundledPlugins=
2222

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.github.xepozz.php_dump
2+
3+
import com.intellij.execution.process.ProcessAdapter
4+
import com.intellij.execution.process.ProcessEvent
5+
import com.intellij.execution.process.ProcessOutputTypes
6+
import com.intellij.openapi.util.Key
7+
8+
9+
class SeparateStringBufferProcessAdapter(val stderr: StringBuilder?, val stdout: StringBuilder?) : ProcessAdapter() {
10+
override fun onTextAvailable(event: ProcessEvent, outputType: Key<*>) {
11+
when (outputType) {
12+
ProcessOutputTypes.STDERR -> stderr?.append(event.text)
13+
ProcessOutputTypes.STDOUT -> stdout?.append(event.text)
14+
}
15+
}
16+
}

src/main/kotlin/com/github/xepozz/php_dump/command/PhpCommandExecutor.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import com.intellij.execution.process.KillableColoredProcessHandler
66
import com.intellij.execution.process.ProcessAdapter
77
import com.intellij.execution.process.ProcessEvent
88
import com.intellij.execution.process.ProcessHandler
9+
import com.intellij.openapi.diagnostic.thisLogger
910
import com.intellij.openapi.project.Project
1011
import com.intellij.openapi.util.text.StringUtil
1112
import com.jetbrains.php.config.PhpProjectConfigurationFacade
@@ -22,8 +23,6 @@ object PhpCommandExecutor {
2223
processListener: ProcessAdapter,
2324
processArguments: List<String> = emptyList()
2425
) {
25-
println("run php command $file, $phpSnippet")
26-
2726
val arguments = buildList {
2827
addAll(processArguments)
2928
add("-r")
@@ -66,7 +65,7 @@ object PhpCommandExecutor {
6665
.withRedirectErrorStream(false)
6766
.apply { addParameters(arguments) }
6867

69-
println("cmd: ${command.commandLineString}")
68+
thisLogger().info("cmd: ${command.commandLineString}")
7069
processHandler = manager.getRemoteProcessHandler(
7170
project,
7271
data,
@@ -75,7 +74,7 @@ object PhpCommandExecutor {
7574
*phpCommandSettings.additionalMappings
7675
)
7776
} else {
78-
println("cmd: ${command.commandLineString}")
77+
thisLogger().info("cmd: ${command.commandLineString}")
7978
processHandler = KillableColoredProcessHandler.Silent(command)
8079
processHandler.setShouldKillProcessSoftly(false)
8180
processHandler.setShouldDestroyProcessRecursively(true)

src/main/kotlin/com/github/xepozz/php_dump/panel/OpcodesTerminalPanel.kt

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import com.github.xepozz.php_dump.actions.OpenPhpSettingsAction
55
import com.github.xepozz.php_dump.actions.RefreshAction
66
import com.github.xepozz.php_dump.configuration.PhpDumpSettingsService
77
import com.github.xepozz.php_dump.configuration.PhpOpcacheDebugLevel
8+
import com.github.xepozz.php_dump.services.EditorProvider
89
import com.github.xepozz.php_dump.services.OpcodesDumperService
9-
import com.github.xepozz.php_opcodes_language.language.PHPOpFileType
1010
import com.intellij.icons.AllIcons
1111
import com.intellij.openapi.Disposable
1212
import com.intellij.openapi.actionSystem.ActionManager
@@ -17,15 +17,12 @@ import com.intellij.openapi.actionSystem.DefaultActionGroup
1717
import com.intellij.openapi.application.EDT
1818
import com.intellij.openapi.command.WriteCommandAction
1919
import com.intellij.openapi.editor.EditorFactory
20-
import com.intellij.openapi.editor.ex.EditorEx
2120
import com.intellij.openapi.fileChooser.FileChooser
2221
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory
2322
import com.intellij.openapi.fileEditor.FileEditorManager
2423
import com.intellij.openapi.project.Project
2524
import com.intellij.openapi.ui.SimpleToolWindowPanel
2625
import com.intellij.psi.PsiDocumentManager
27-
import com.intellij.psi.PsiManager
28-
import com.intellij.testFramework.LightVirtualFile
2926
import com.jetbrains.php.lang.PhpFileType
3027
import kotlinx.coroutines.CoroutineScope
3128
import kotlinx.coroutines.Dispatchers
@@ -40,48 +37,24 @@ import javax.swing.JPanel
4037
class OpcodesTerminalPanel(
4138
val project: Project,
4239
) : SimpleToolWindowPanel(false, false), RefreshablePanel, Disposable {
40+
4341
val fileEditorManager = FileEditorManager.getInstance(project)
4442
val documentManager = PsiDocumentManager.getInstance(project)
43+
val editorFactory = EditorFactory.getInstance()
4544

4645
private val service = project.getService(OpcodesDumperService::class.java)
46+
private val editorProvider = project.getService(EditorProvider::class.java)
4747
private val state = PhpDumpSettingsService.getInstance(project)
48-
private val editorFactory: EditorFactory = EditorFactory.getInstance()
49-
50-
private val virtualFile: LightVirtualFile = LightVirtualFile(
51-
"opcodes.phpop",
52-
PHPOpFileType.INSTANCE,
53-
""
54-
)
55-
val psiFile = PsiManager.getInstance(project).findFile(virtualFile)!!
56-
val document = documentManager.getDocument(psiFile)!!
57-
58-
private var editor = editorFactory.createEditor(
59-
document,
60-
project,
61-
virtualFile,
62-
false
63-
) as EditorEx
48+
49+
val editor = editorProvider.getOrCreateEditor()
6450
val viewComponent = editor.component
6551

6652
init {
67-
configureEditor()
53+
6854
createToolBar()
6955
createContent()
7056
}
7157

72-
private fun configureEditor() {
73-
editor.settings.apply {
74-
isBlinkCaret = true
75-
isCaretRowShown = true
76-
isBlockCursor = false
77-
isLineMarkerAreaShown = true
78-
isAutoCodeFoldingEnabled = true
79-
isSmartHome = true
80-
isShowIntentionBulb = true
81-
}
82-
83-
editor.setCaretEnabled(true)
84-
}
8558

8659
private fun createToolBar() {
8760
val actionGroup = DefaultActionGroup().apply {
@@ -207,8 +180,8 @@ class OpcodesTerminalPanel(
207180

208181
private fun setDocumentText(project: Project, content: String) {
209182
WriteCommandAction.runWriteCommandAction(project) {
210-
document.setText(content)
211-
documentManager.commitDocument(document)
183+
editor.document.setText(content)
184+
documentManager.commitDocument(editor.document)
212185
}
213186
}
214187

src/main/kotlin/com/github/xepozz/php_dump/panel/TokenTreePanel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class TokenTreePanel(private val project: Project) :
108108
}
109109
}
110110

111-
private fun navigation(closestPathForLocation: TreePath?) {
111+
private fun navigation(closestPathForLocation: TreePath) {
112112
val lastUserObject = TreeUtil.getLastUserObject(closestPathForLocation)
113113
if (lastUserObject is TokenNode) {
114114
val fileEditor = FileEditorManager.getInstance(project)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.github.xepozz.php_dump.services
2+
3+
import com.github.xepozz.php_opcodes_language.language.PHPOpFileType
4+
import com.intellij.openapi.components.Service
5+
import com.intellij.openapi.editor.EditorFactory
6+
import com.intellij.openapi.editor.ex.EditorEx
7+
import com.intellij.openapi.project.Project
8+
import com.intellij.openapi.util.Key
9+
import com.intellij.psi.PsiDocumentManager
10+
import com.intellij.psi.PsiManager
11+
import com.intellij.testFramework.LightVirtualFile
12+
13+
@Service(Service.Level.PROJECT)
14+
class EditorProvider(var project: Project) {
15+
companion object {
16+
val editorId = Key.create<Boolean>("opcodes.editor.id")
17+
}
18+
19+
val documentManager = PsiDocumentManager.getInstance(project)
20+
val editorFactory = EditorFactory.getInstance()
21+
22+
var editor: EditorEx? = null
23+
24+
fun getOrCreateEditor(): EditorEx = synchronized(this) {
25+
editor?.let { return it }
26+
27+
val virtualFile = LightVirtualFile(
28+
"opcodes.phpop",
29+
PHPOpFileType.INSTANCE,
30+
""
31+
)
32+
val psiFile = PsiManager.getInstance(project).findFile(virtualFile)!!
33+
val document = documentManager.getDocument(psiFile)!!
34+
35+
return@synchronized (editorFactory.createEditor(document, project, virtualFile, false) as EditorEx)
36+
.apply {
37+
settings.apply {
38+
isBlinkCaret = true
39+
isCaretRowShown = true
40+
isBlockCursor = false
41+
isLineMarkerAreaShown = true
42+
isAutoCodeFoldingEnabled = true
43+
isSmartHome = true
44+
isShowIntentionBulb = true
45+
}
46+
47+
setCaretEnabled(true)
48+
putUserData(editorId, true)
49+
50+
editor = this
51+
}
52+
}
53+
}

src/main/kotlin/com/github/xepozz/php_dump/services/OpcacheSettingsTreeDumperService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class OpcacheSettingsTreeDumperService(var project: Project) : DumperServiceInte
5151
phpSnippet,
5252
project,
5353
StringBufferProcessAdapter(output),
54-
listOf("-dopcache.enable_cli=1"),
54+
("-d opcache.enable_cli=1".split(" ")),
5555
)
5656

5757
val jsonString = output.toString()
Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,62 @@
11
package com.github.xepozz.php_dump.services
22

3-
import com.github.xepozz.php_dump.StringBufferProcessAdapter
3+
import com.github.xepozz.php_dump.SeparateStringBufferProcessAdapter
44
import com.github.xepozz.php_dump.command.PathMapper
55
import com.github.xepozz.php_dump.command.PhpCommandExecutor
66
import com.github.xepozz.php_dump.configuration.PhpDumpSettingsService
77
import com.intellij.execution.configurations.GeneralCommandLine
88
import com.intellij.openapi.components.Service
99
import com.intellij.openapi.project.Project
10-
import com.jetbrains.php.config.PhpProjectConfigurationFacade
11-
import com.jetbrains.php.config.interpreters.PhpInterpretersManagerImpl
1210
import kotlinx.coroutines.Dispatchers
1311
import kotlinx.coroutines.withContext
1412

1513
@Service(Service.Level.PROJECT)
1614
class OpcodesDumperService(var project: Project) : DumperServiceInterface {
1715
val state = PhpDumpSettingsService.getInstance(project)
18-
val interpreter = PhpProjectConfigurationFacade.getInstance(project).interpreter
19-
?: PhpInterpretersManagerImpl.getInstance(project).interpreters.firstOrNull()
2016

21-
override suspend fun dump(file: String): Any? {
22-
val interpreterPath = interpreter?.pathToPhpExecutable ?: return null
17+
override suspend fun dump(file: String): Any {
2318
val debugLevel = state.debugLevel.value
2419
val preloadFile = state.preloadFile
2520

2621
val localFile = PathMapper.map(project, file)
2722
val command = GeneralCommandLine(buildList {
28-
add(interpreterPath)
2923
add("-l")
30-
add("-ddisplay_errors=0")
31-
add("-derror_reporting=0")
24+
addAll("-d display_errors=0".split(" "))
25+
addAll("-d error_reporting=0".split(" "))
3226

33-
add("-dopcache.enable_cli=1")
34-
add("-dopcache.save_comments=1")
35-
add("-dopcache.opt_debug_level=${debugLevel}")
27+
addAll("-d opcache.enable_cli=1".split(" "))
28+
addAll("-d opcache.save_comments=1".split(" "))
29+
addAll("-d opcache.opt_debug_level=${debugLevel}".split(" "))
3630
if (preloadFile != null) {
37-
add("-dopcache.preload=${preloadFile}")
31+
addAll("-d opcache.preload=${preloadFile}".split(" "))
3832
}
39-
40-
add("1>/dev/null")
4133
add(localFile)
4234
}).commandLineString
4335

4436
// language=injectablephp
4537
val phpSnippet = $$"""
46-
opcache_compile_file($argv[1]);
47-
passthru('$$command');
38+
opcache_compile_file($argv[1]); passthru(PHP_BINARY . ' $$command');
4839
""".trimIndent()
4940

41+
// println("command: $command")
42+
// println("phpSnippet: $phpSnippet")
5043
return withContext(Dispatchers.IO) {
51-
val output = StringBuilder()
44+
val opcodes = StringBuilder()
45+
val errors = StringBuilder()
5246

5347
PhpCommandExecutor.execute(
5448
localFile,
5549
phpSnippet,
5650
project,
57-
StringBufferProcessAdapter(output),
58-
listOf("-dopcache.enable_cli=1"),
51+
SeparateStringBufferProcessAdapter(stderr = opcodes, stdout = errors),
52+
("-d opcache.enable_cli=1".split(" ")),
5953
)
6054

61-
62-
output.toString()
55+
if (opcodes.isEmpty()) {
56+
errors.toString()
57+
} else {
58+
opcodes.toString()
59+
}
6360
}
6461
}
6562
}

0 commit comments

Comments
 (0)