Skip to content

Commit 85450ca

Browse files
committed
First running prototype
1 parent 010145f commit 85450ca

File tree

8 files changed

+138
-33
lines changed

8 files changed

+138
-33
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
# phpstorm-xdebug-skip Changelog
44

5+
## 0.1.0 - 2021-10-17
6+
### Added
7+
- Initial release
8+
- Use stepinto to exit whereever the breakpoint resolves to a non match.
9+
- Added settings panel to configure the plugin
10+
- Namespace and filepath selector for paths to skip when debugging
11+
- Added extra text as the namespace selector doesn't appear on the first click on +
512
## [Unreleased]
613
### Added
714
- Initial scaffold created from [IntelliJ Platform Plugin Template](https://github.com/JetBrains/intellij-platform-plugin-template)

src/main/kotlin/de/tschallacka/phpstormxdebugskip/MyPluginProjectComponent.kt

-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,4 @@ class MyPluginProjectComponent(private val project: Project) : ProjectComponent
1111
val listener = MyXDebugProcessListener(project)
1212
project.messageBus.connect().subscribe(XDebuggerManager.TOPIC, listener)
1313
}
14-
15-
// Other overridden methods here...
16-
1714
}

src/main/kotlin/de/tschallacka/phpstormxdebugskip/listeners/MyXDebugProcessListener.kt

+32-13
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,50 @@ import com.intellij.xdebugger.XDebuggerManagerListener
55
import com.intellij.openapi.project.Project
66
import com.intellij.openapi.util.Trinity
77
import com.intellij.xdebugger.XDebugSessionListener
8+
import de.tschallacka.phpstormxdebugskip.settings.Settings // Assuming this is the location of your Settings class
89

910
class MyXDebugProcessListener(private val project: Project) : XDebuggerManagerListener {
1011
override fun processStarted(debugProcess: XDebugProcess) {
11-
val session = debugProcess.session;
12+
val session = debugProcess.session
1213
session.addSessionListener(object : XDebugSessionListener {
1314
override fun sessionPaused() {
14-
var frame = session.currentStackFrame;
15-
var frameDataObject = frame?.getEqualityObject();
15+
val frame = session.currentStackFrame
16+
val frameDataObject = frame?.getEqualityObject()
1617
if (frameDataObject is Trinity<*, *, *>) {
17-
var frameData = frameDataObject as Trinity<Integer, String, String>
18-
var path = frameData.second;
19-
var functioName = frameData.third;
20-
var regex = Regex("(.*)->.*");
21-
var match = regex.matchEntire(functioName);
22-
var namespace = match?.groupValues?.get(1);
23-
if (namespace != null && isSkippableNamespace(namespace)) {
24-
session.stepOver(false);
18+
val frameData = frameDataObject as Trinity<Int, String, String>
19+
val path = frameData.second
20+
val functionName = frameData.third
21+
val regex = Regex("(.*)->.*")
22+
val match = regex.matchEntire(functionName)
23+
val namespace = match?.groupValues?.get(1)
24+
if (namespace != null && isSkippableNamespace("\\"+namespace)) {
25+
session.stepInto()
26+
return
27+
}
28+
if (path != null && isSkippableFilePath(path)) {
29+
session.stepInto()
30+
return
2531
}
2632
}
2733
}
2834
})
2935
}
3036

31-
public fun isSkippableNamespace(namespace: String): Boolean {
32-
return namespace.contains("FOO\\Bar");
37+
private fun isSkippableNamespace(namespace: String): Boolean {
38+
val settings = Settings.getInstance()
39+
val namespaces = settings.settingsState.namespaces;
40+
val match = namespaces.any {
41+
ns -> namespace.contains(ns)
42+
}
43+
return match
44+
}
3345

46+
private fun isSkippableFilePath(path: String): Boolean {
47+
val settings = Settings.getInstance()
48+
val filepaths = settings.settingsState.filepaths;
49+
val match = filepaths.any {
50+
filepath -> path.contains(filepath)
51+
}
52+
return match
3453
}
3554
}

src/main/kotlin/de/tschallacka/phpstormxdebugskip/settings/Settings.kt

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import org.jetbrains.annotations.Nullable
66

77
@State(
88
name = "de.tschallacka.phpstormxdebugskip.Settings",
9-
storages = [Storage(StoragePathMacros.WORKSPACE_FILE)]
9+
storages = [Storage("de.tschallacka.phpstormxdebugskip.xml", // File path relative to component container
10+
deprecated = false,
11+
roamingType = RoamingType.DEFAULT,
12+
storageClass = StateStorage::class,
13+
exportable = true)]
1014
)
1115
class Settings : PersistentStateComponent<Settings.State> {
1216

Original file line numberDiff line numberDiff line change
@@ -1,32 +1,110 @@
11
package de.tschallacka.phpstormxdebugskip.settings
22

3+
import com.intellij.openapi.fileChooser.FileChooser
4+
import com.intellij.openapi.fileChooser.FileChooserDescriptor
35
import com.intellij.openapi.options.Configurable
4-
import javax.swing.JComponent
6+
import com.intellij.openapi.project.Project
7+
import com.intellij.openapi.ui.TextFieldWithBrowseButton
8+
import com.intellij.ui.ColoredListCellRenderer
9+
import com.intellij.ui.ToolbarDecorator
10+
import com.intellij.ui.components.JBList
11+
import com.jetbrains.php.config.PhpTreeClassChooserDialog
12+
import java.awt.BorderLayout
13+
import javax.swing.*
514

6-
class SettingsConfigurable : Configurable {
15+
class SettingsConfigurable(private val project: Project) : Configurable {
716

8-
private var settingsDialog: SettingsDialog? = null
17+
private val settings = Settings.getInstance()
918

10-
override fun createComponent(): JComponent? {
11-
settingsDialog = SettingsDialog()
12-
return settingsDialog?.createCenterPanel()
19+
private val modified = false
20+
21+
private val filePathModel = DefaultListModel<String>().apply { addAll(settings.settingsState.filepaths) }
22+
private val namespaceModel = DefaultListModel<String>().apply { addAll(settings.settingsState.namespaces) }
23+
24+
private val filePathList = JBList<String>(filePathModel)
25+
private val namespaceList = JBList<String>(namespaceModel)
26+
27+
override fun createComponent(): JComponent {
28+
val panel = JPanel()
29+
panel.layout = BoxLayout(panel, BoxLayout.Y_AXIS)
30+
JLabel("Don't halt the debugger in these file paths").also { panel.add(it) }
31+
// Create a decorator for file paths
32+
val filePathDecorator = ToolbarDecorator.createDecorator(filePathList)
33+
filePathDecorator.setAddAction { addButton ->
34+
FileChooser.chooseFiles(
35+
FileChooserDescriptor(true, true, false, false, false, true),
36+
project,
37+
null
38+
) { selectedFiles ->
39+
// Assuming you want to add all selected files to the list
40+
selectedFiles.forEach { file ->
41+
filePathModel.addElement(file.path)
42+
}
43+
}
44+
}.setRemoveAction { removeButton ->
45+
val selectedFiles = filePathList.selectedValuesList
46+
selectedFiles.forEach { filePath ->
47+
filePathModel.removeElement(filePath)
48+
}
49+
}
50+
panel.add(filePathDecorator.createPanel())
51+
JLabel("Don't halt the debugger in these namespaces").also { panel.add(it) }
52+
JLabel("Click the + twice to activate the selector. It doesn't display the panel on first click.").also { panel.add(it) }
53+
// Create a decorator for namespaces
54+
val namespaceDecorator = ToolbarDecorator.createDecorator(namespaceList)
55+
namespaceDecorator.setAddAction { addButton ->
56+
namespaceDecorator.setAddAction { addButton ->
57+
val dialog = PhpTreeClassChooserDialog("Select PHP namespaces", project, null)
58+
dialog.showDialog()
59+
val selectedPhpClass = dialog.selected
60+
if (selectedPhpClass != null) {
61+
var selectedNamespace = selectedPhpClass.namespaceName
62+
if (selectedNamespace != null) {
63+
namespaceModel.addElement(selectedNamespace)
64+
}
65+
}
66+
}
67+
}.setRemoveAction { removeButton ->
68+
val selectedNamespaces = namespaceList.selectedValuesList
69+
selectedNamespaces.forEach { namespace ->
70+
namespaceModel.removeElement(namespace)
71+
}
72+
}
73+
panel.add(namespaceDecorator.createPanel())
74+
75+
return panel
1376
}
1477

1578
override fun isModified(): Boolean {
16-
// Here you can implement a check to see if settings have been modified
17-
return false
79+
val filePaths = (0 until filePathModel.size()).map { i -> filePathModel.getElementAt(i) }
80+
val namespaces = (0 until namespaceModel.size()).map { i -> namespaceModel.getElementAt(i) }
81+
return filePaths != settings.settingsState.filepaths || namespaces != settings.settingsState.namespaces
1882
}
1983

2084
override fun apply() {
21-
// Here you should implement applying the settings
85+
val filePathModel = filePathList.model as? DefaultListModel<String>
86+
val namespaceModel = namespaceList.model as? DefaultListModel<String>
87+
88+
settings?.settingsState?.filepaths =
89+
filePathModel?.let { (0 until it.size()).map { i -> it.getElementAt(i) } }?.let { ArrayList(it) }!!
90+
settings?.settingsState?.namespaces =
91+
namespaceModel?.let { (0 until it.size()).map { i -> it.getElementAt(i) } }?.let { ArrayList(it) }!!
2292
}
2393

2494
override fun reset() {
25-
// Here you can implement resetting your settings UI to the stored state
95+
filePathModel.clear()
96+
filePathModel.addAll(settings.settingsState.filepaths)
97+
namespaceModel.clear()
98+
namespaceModel.addAll(settings.settingsState.namespaces)
2699
}
27100

28-
override fun getDisplayName(): String {
29-
// The display name for the settings component
30-
return "PHPStorm Xdebug Skip"
101+
override fun getDisplayName(): String = "PHPStorm Xdebug Skip"
102+
103+
private fun createListRenderer(): ColoredListCellRenderer<String> {
104+
return object : ColoredListCellRenderer<String>() {
105+
override fun customizeCellRenderer(list: JList<out String>, value: String?, index: Int, selected: Boolean, hasFocus: Boolean) {
106+
append(value ?: "")
107+
}
108+
}
31109
}
32110
}

src/main/kotlin/de/tschallacka/phpstormxdebugskip/settings/SettingsDialog.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class SettingsDialog : DialogWrapper(true) {
1515
}
1616

1717
@Nullable
18-
override fun createCenterPanel(): JComponent? {
18+
public override fun createCenterPanel(): JComponent? {
1919
return myMainPanel
2020
}
2121
}

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

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<vendor>tschallacka</vendor>
66

77
<depends>com.intellij.modules.platform</depends>
8+
<depends>com.jetbrains.php</depends>
89

910
<resource-bundle>messages.MyBundle</resource-bundle>
1011
<project-components>
@@ -15,5 +16,6 @@
1516
<extensions defaultExtensionNs="com.intellij">
1617
<!-- Add your extension point here -->
1718
<projectConfigurable instance="de.tschallacka.phpstormxdebugskip.settings.SettingsConfigurable" />
19+
<applicationService serviceImplementation="de.tschallacka.phpstormxdebugskip.settings.Settings"/>
1820
</extensions>
1921
</idea-plugin>
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
name=XDEBUG Skip
22
projectService=Project service: {0}
3-
randomLabel=The random number is: {0}
4-
shuffle=Shuffle

0 commit comments

Comments
 (0)