Skip to content

Commit eddf2ce

Browse files
committed
feat: use opcodes language to highlight the opcode output
1 parent e26ac31 commit eddf2ce

File tree

3 files changed

+45
-9
lines changed

3 files changed

+45
-9
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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
19+
platformPlugins=com.jetbrains.php:251.23774.318,com.jetbrains.hackathon.indices.viewer:1.30,com.github.xepozz.php_opcodes_language:2025.0.1
2020
# Example: platformBundledPlugins = com.intellij.java
2121
platformBundledPlugins=com.jetbrains.sh
2222

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

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
package com.github.xepozz.php_dump.panel
22

33
import com.github.xepozz.php_dump.PhpDumpIcons
4-
import com.github.xepozz.php_dump.actions.ClearConsoleViewAction
54
import com.github.xepozz.php_dump.actions.RefreshAction
65
import com.github.xepozz.php_dump.configuration.PhpDumpSettingsService
76
import com.github.xepozz.php_dump.configuration.PhpOpcacheDebugLevel
87
import com.github.xepozz.php_dump.services.OpcodesDumperService
9-
import com.intellij.execution.filters.TextConsoleBuilderFactory
10-
import com.intellij.execution.ui.ConsoleViewContentType
8+
import com.github.xepozz.php_opcodes_language.language.PHPOpFileType
119
import com.intellij.icons.AllIcons
1210
import com.intellij.openapi.Disposable
1311
import com.intellij.openapi.actionSystem.ActionManager
1412
import com.intellij.openapi.actionSystem.AnAction
1513
import com.intellij.openapi.actionSystem.AnActionEvent
1614
import com.intellij.openapi.actionSystem.DefaultActionGroup
15+
import com.intellij.openapi.application.ApplicationManager
16+
import com.intellij.openapi.command.WriteCommandAction
17+
import com.intellij.openapi.editor.EditorFactory
18+
import com.intellij.openapi.editor.EditorKind
19+
import com.intellij.openapi.editor.ex.EditorEx
20+
import com.intellij.openapi.editor.highlighter.EditorHighlighterFactory
1721
import com.intellij.openapi.fileChooser.FileChooser
1822
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory
1923
import com.intellij.openapi.fileEditor.FileEditorManager
@@ -34,19 +38,46 @@ class OpcodesTerminalPanel(
3438
val viewComponent: JComponent
3539
val service: OpcodesDumperService = project.getService(OpcodesDumperService::class.java)
3640
val state = PhpDumpSettingsService.getInstance(project)
37-
val consoleView = TextConsoleBuilderFactory.getInstance().createBuilder(project).console
41+
private val document = EditorFactory.getInstance().createDocument("")
42+
private val editor = EditorFactory.getInstance().createViewer(document, project, EditorKind.MAIN_EDITOR) as EditorEx
3843

3944
init {
40-
viewComponent = consoleView.component
45+
viewComponent = editor.component
46+
configureEditor()
4147

4248
createToolBar()
4349
createContent()
4450
}
4551

52+
private fun configureEditor() {
53+
editor.settings.apply {
54+
isBlinkCaret = true
55+
isCaretRowShown = true
56+
isBlockCursor = false
57+
isLineMarkerAreaShown = true
58+
isHighlightSelectionOccurrences = true
59+
}
60+
61+
editor.setCaretEnabled(true)
62+
63+
ApplicationManager.getApplication().runReadAction {
64+
val highlighter = EditorHighlighterFactory.getInstance()
65+
.createEditorHighlighter(project, PHPOpFileType.INSTANCE)
66+
67+
editor.highlighter = highlighter
68+
}
69+
}
70+
4671
private fun createToolBar() {
4772
val actionGroup = DefaultActionGroup().apply {
4873
add(RefreshAction { refresh(project, RefreshType.MANUAL) })
49-
add(ClearConsoleViewAction(consoleView))
74+
add(object : AnAction("Clear Output", "Clear the output", AllIcons.Actions.GC) {
75+
override fun actionPerformed(e: AnActionEvent) {
76+
WriteCommandAction.runWriteCommandAction(project) {
77+
document.setText("")
78+
}
79+
}
80+
})
5081
add(object : AnAction(
5182
"Enable Auto Refresh", "Turns on or off auto refresh of panel context",
5283
if (state.autoRefresh) PhpDumpIcons.RESTART_STOP else PhpDumpIcons.RERUN_AUTOMATICALLY
@@ -142,11 +173,15 @@ class OpcodesTerminalPanel(
142173

143174
val result = runBlocking { service.dump(virtualFile) }
144175

145-
consoleView.clear()
146-
consoleView.print(result as? String ?: "No output", ConsoleViewContentType.NORMAL_OUTPUT)
176+
val content = result as? String ?: "No output"
177+
178+
WriteCommandAction.runWriteCommandAction(project) {
179+
document.setText(content)
180+
}
147181
}
148182

149183
override fun dispose() {
184+
EditorFactory.getInstance().releaseEditor(editor)
150185
}
151186
}
152187

src/main/resources/META-INF/plugin.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<depends>com.intellij.modules.platform</depends>
88
<depends>com.jetbrains.php</depends>
99
<depends>com.jetbrains.sh</depends>
10+
<depends>com.github.xepozz.php_opcodes_language</depends>
1011

1112
<resource-bundle>messages.MyBundle</resource-bundle>
1213

0 commit comments

Comments
 (0)