Skip to content

Commit bf69150

Browse files
committed
feat: add preload.php chooser
1 parent 86895e0 commit bf69150

File tree

4 files changed

+66
-36
lines changed

4 files changed

+66
-36
lines changed

playground/preload.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
$directory = new RecursiveDirectoryIterator(__DIR__ . '/');
4+
$fullTree = new RecursiveIteratorIterator($directory);
5+
$phpFiles = new RegexIterator($fullTree, '/.+((?<!Test)+\.php$)/i', RecursiveRegexIterator::GET_MATCH);
6+
7+
foreach ($phpFiles as $key => $file) {
8+
opcache_compile_file($file[0]);
9+
}

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

Lines changed: 47 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ import com.intellij.openapi.actionSystem.ActionManager
99
import com.intellij.openapi.actionSystem.AnAction
1010
import com.intellij.openapi.actionSystem.AnActionEvent
1111
import com.intellij.openapi.actionSystem.DefaultActionGroup
12+
import com.intellij.openapi.fileChooser.FileChooser
13+
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory
1214
import com.intellij.openapi.fileEditor.FileEditorManager
1315
import com.intellij.openapi.project.Project
1416
import com.intellij.openapi.ui.SimpleToolWindowPanel
15-
import com.intellij.ui.JBColor
16-
import com.intellij.util.IconUtil
17+
import com.jetbrains.php.lang.PhpFileType
1718
import kotlinx.coroutines.runBlocking
1819
import java.awt.BorderLayout
1920
import java.awt.GridLayout
@@ -41,37 +42,56 @@ class OpcodesTerminalPanel(
4142
}
4243

4344
private fun createToolBar() {
44-
val actionGroup = DefaultActionGroup()
45-
actionGroup.add(RunDumpTokensCommandAction(service))
46-
actionGroup.addSeparator()
47-
actionGroup.add(DefaultActionGroup("Debug Level", true).apply {
48-
add(object : AnAction("Before Optimization") {
49-
override fun actionPerformed(e: AnActionEvent) {
50-
state.setDebugLevel(1)
51-
refresh(project)
52-
}
53-
override fun update(e: AnActionEvent) {
54-
e.presentation.icon = when (state.getDebugLevel()) {
55-
1 -> IconUtil.colorize(AllIcons.General.GreenCheckmark, JBColor.GRAY)
56-
else -> null
45+
val actionGroup = DefaultActionGroup().apply {
46+
add(RunDumpTokensCommandAction(service))
47+
addSeparator()
48+
add(DefaultActionGroup("Debug Level", true).apply {
49+
add(object : AnAction("Before Optimization") {
50+
override fun actionPerformed(e: AnActionEvent) {
51+
state.debugLevel = 1
52+
refresh(project)
5753
}
58-
}
54+
55+
override fun update(e: AnActionEvent) {
56+
e.presentation.icon = when (state.debugLevel) {
57+
1 -> AllIcons.Actions.Checked
58+
else -> null
59+
}
60+
}
61+
})
62+
add(object : AnAction("After Optimization") {
63+
override fun actionPerformed(e: AnActionEvent) {
64+
state.debugLevel = 2
65+
refresh(project)
66+
}
67+
68+
override fun update(e: AnActionEvent) {
69+
e.presentation.icon = when (state.debugLevel) {
70+
2 -> AllIcons.Actions.Checked
71+
else -> null
72+
}
73+
}
74+
})
75+
templatePresentation.icon = AllIcons.Actions.ToggleVisibility
5976
})
60-
add(object : AnAction("After Optimization") {
77+
78+
add(object : AnAction("Select Preload File", "Choose a file", AllIcons.Actions.MenuOpen) {
6179
override fun actionPerformed(e: AnActionEvent) {
62-
state.setDebugLevel(2)
63-
refresh(project)
64-
}
6580

66-
override fun update(e: AnActionEvent) {
67-
e.presentation.icon = when (state.getDebugLevel()) {
68-
2 -> IconUtil.colorize(AllIcons.General.GreenCheckmark, JBColor.GRAY)
69-
else -> null
70-
}
81+
val fileChooserDescriptor =
82+
FileChooserDescriptorFactory.createSingleFileDescriptor(PhpFileType.INSTANCE)
83+
.withTitle("Select Preload File")
84+
.withDescription("Choose a preload.php file")
85+
86+
FileChooser
87+
.chooseFile(fileChooserDescriptor, project, null)
88+
.let { file ->
89+
state.preloadFile = file?.path
90+
}
91+
refresh(project)
7192
}
7293
})
73-
templatePresentation.icon = AllIcons.Actions.ToggleVisibility
74-
})
94+
}
7595

7696
val actionToolbar = ActionManager.getInstance().createActionToolbar("Opcodes Toolbar", actionGroup, false)
7797
actionToolbar.targetComponent = this

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import com.intellij.openapi.project.Project
1313
)
1414
class DebugLevelState : PersistentStateComponent<DebugLevelState.State> {
1515
data class State(
16-
var debugLevel: Int = 1
16+
var debugLevel: Int = 1,
17+
var preloadFile: String? = null,
1718
)
1819

1920
private var myState = State()
@@ -26,13 +27,8 @@ class DebugLevelState : PersistentStateComponent<DebugLevelState.State> {
2627
myState = state
2728
}
2829

29-
fun getDebugLevel(): Int {
30-
return myState.debugLevel
31-
}
32-
33-
fun setDebugLevel(level: Int) {
34-
myState.debugLevel = level
35-
}
30+
var debugLevel: Int by state::debugLevel
31+
var preloadFile: String? by state::preloadFile
3632

3733
companion object {
3834
fun getInstance(project: Project): DebugLevelState {

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ class OpcodesDumperService(var project: Project) : Disposable, DumperServiceInte
4646
// 1>/dev/null
4747

4848
val interpreterPath = interpreter.pathToPhpExecutable ?: return
49-
val debugLevel = max(1, min(2, state.getDebugLevel()))
49+
val debugLevel = max(1, min(2, state.debugLevel))
50+
val preloadFile = state.preloadFile
5051

5152
val commandArgs = buildList {
5253
add(interpreterPath)
@@ -58,6 +59,9 @@ class OpcodesDumperService(var project: Project) : Disposable, DumperServiceInte
5859
add("-dopcache.save_comments=1")
5960
add("-dopcache.opt_debug_level=0x${debugLevel}0000")
6061
add("-dopcache.optimization_level=0")
62+
if (preloadFile != null) {
63+
add("-dopcache.preload=${preloadFile}")
64+
}
6165

6266
add(file)
6367
}
@@ -71,6 +75,7 @@ class OpcodesDumperService(var project: Project) : Disposable, DumperServiceInte
7175
val command = GeneralCommandLine(commandArgs)
7276
command.withRedirectErrorStream(false)
7377

78+
// println("running command ${command.commandLineString}")
7479
val processHandler = KillableColoredProcessHandler.Silent(command)
7580
processHandler.setShouldKillProcessSoftly(false)
7681
processHandler.setShouldDestroyProcessRecursively(true)

0 commit comments

Comments
 (0)