Skip to content

Commit aec9ef3

Browse files
FantoomForNeVeR
authored andcommitted
Debugger WIP 16
Add Variables cache see PowerShell/PowerShellEditorServices#2169 Debugger WIP 15 Catch value modification errors Debugger WIP 15 Debugger eval completion Debugger WIP 14 Add id to document Debugger WIP 13 Remove useless files Debugger WIP 12 Add Variable Test Debugger WIP 11.2 Remove useless comments Debugger WIP 11.1 Change hardcoded parameter to variable remove unused variable from EvaluationTest.testEvaluation Debugger WIP 11 Call clientSession.terminateDebugging() on dispose Change PowerShellDebuggerVariableValue supertype to XNamedValue update formatting Test: Update BreakpointTest Add EvaluationTest Add StepTest Debugger WIP 10 Add tests Add BreakpointTest Debugger WIP 9 Set variable value Debugger WIP 8 run project file instead hardcoded file set all breakpoints on start Debugger WIP 7 Step Over/In/Out support Terminate support Debugger WIP 6 Conditional and log support Debugger WIP 5 IDE Breakpoints support Resume (continue) support Debugger WIP 5 Variable list Complex objects Debugger WIP 3 variable list eval Debugger WIP 2 Debugger WIP
1 parent 9304788 commit aec9ef3

26 files changed

+1585
-122
lines changed

build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ dependencies {
7171

7272
implementation(libs.bundles.junixsocket)
7373
implementation(libs.lsp4j)
74+
implementation("org.eclipse.lsp4j:org.eclipse.lsp4j.debug:0.23.1")
7475
testImplementation("org.jetbrains.kotlin:kotlin-test-junit")
7576
testImplementation(libs.junit)
7677
testImplementation(libs.openTest4J)

debugger.ps1

-24
This file was deleted.

src/main/kotlin/com/intellij/plugin/powershell/ide/actions/PowerShellStartDebugAction.kt

-48
This file was deleted.

src/main/kotlin/com/intellij/plugin/powershell/ide/debugger/PowerShellBreakpointHandler.kt

+17-3
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@ import com.intellij.xdebugger.breakpoints.XBreakpointHandler
99
import com.intellij.xdebugger.breakpoints.XBreakpointProperties
1010
import com.intellij.xdebugger.breakpoints.XBreakpointType
1111
import com.intellij.xdebugger.breakpoints.XLineBreakpoint
12+
import com.jetbrains.rd.util.reactive.Signal
1213

1314
class PowerShellBreakpointHandler(powerShellDebugProcess: PowerShellDebugProcess, breakpointTypeClass: Class<out XBreakpointType<XLineBreakpoint<XBreakpointProperties<*>>, *>>): XBreakpointHandler<XLineBreakpoint<XBreakpointProperties<*>>>(
1415
breakpointTypeClass
1516
) {
16-
val myPowerShellDebugProcess = powerShellDebugProcess;
17+
val myPowerShellDebugProcess = powerShellDebugProcess
18+
val registerBreakpointEvent = Signal<Pair<String, XLineBreakpoint<XBreakpointProperties<*>>>>()
19+
val unregisterBreakpointEvent = Signal<Pair<String, XLineBreakpoint<XBreakpointProperties<*>>>>()
1720

1821
override fun registerBreakpoint(breakpoint: XLineBreakpoint<XBreakpointProperties<*>>) {
1922
val sourcePosition = breakpoint.sourcePosition
@@ -28,6 +31,7 @@ class PowerShellBreakpointHandler(powerShellDebugProcess: PowerShellDebugProcess
2831
//myXsltDebugProcess.getSession().setBreakpointInvalid(breakpoint, "Unsupported breakpoint position")
2932
return
3033
}
34+
registerBreakpointEvent.fire(Pair(fileURL, breakpoint))
3135
/*try {
3236
val manager: BreakpointManager = myPowerShellDebugProcess.getBreakpointManager()
3337
var bp: Breakpoint
@@ -48,8 +52,18 @@ class PowerShellBreakpointHandler(powerShellDebugProcess: PowerShellDebugProcess
4852
}
4953

5054
override fun unregisterBreakpoint(breakpoint: XLineBreakpoint<XBreakpointProperties<*>>, temporary: Boolean) {
51-
TODO("Not yet implemented")
52-
}
55+
val sourcePosition = breakpoint.sourcePosition
56+
if (sourcePosition == null || !sourcePosition.file.exists() || !sourcePosition.file.isValid) {
57+
return
58+
}
59+
val file = sourcePosition.file
60+
val fileURL: String = getFileURL(file)
61+
val lineNumber: Int = breakpoint.line
62+
if (lineNumber == -1) {
63+
//myXsltDebugProcess.getSession().setBreakpointInvalid(breakpoint, "Unsupported breakpoint position")
64+
return
65+
}
66+
unregisterBreakpointEvent.fire(Pair(fileURL, breakpoint)) }
5367

5468
fun getFileURL(file: VirtualFile?): String {
5569
return VfsUtil.virtualToIoFile(file!!).toURI().toASCIIString()
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,109 @@
11
package com.intellij.plugin.powershell.ide.debugger
22

3-
import com.intellij.ide.highlighter.XmlFileType
3+
import com.intellij.idea.ActionsBundle
4+
import com.intellij.openapi.actionSystem.AnAction
5+
import com.intellij.openapi.actionSystem.AnActionEvent
46
import com.intellij.openapi.fileEditor.FileDocumentManager
57
import com.intellij.openapi.project.Project
68
import com.intellij.openapi.vfs.VirtualFile
79
import com.intellij.plugin.powershell.PowerShellFileType
810
import com.intellij.plugin.powershell.ide.MessagesBundle
911
import com.intellij.psi.PsiDocumentManager
12+
import com.intellij.ui.components.AnActionLink
13+
import com.intellij.ui.components.JBTextField
14+
import com.intellij.ui.components.Label
15+
import com.intellij.util.ui.JBUI
16+
import com.intellij.xdebugger.XDebuggerManager
1017
import com.intellij.xdebugger.breakpoints.XBreakpointProperties
18+
import com.intellij.xdebugger.breakpoints.XLineBreakpoint
1119
import com.intellij.xdebugger.breakpoints.XLineBreakpointType
20+
import com.intellij.xdebugger.breakpoints.ui.XBreakpointCustomPropertiesPanel
21+
import com.intellij.xdebugger.evaluation.XDebuggerEditorsProvider
22+
import com.intellij.xdebugger.impl.breakpoints.XBreakpointBase
23+
import java.awt.BorderLayout
24+
import java.awt.Component
25+
import java.awt.Dimension
26+
import javax.swing.*
1227

13-
//XsltDebuggerBundle.message("title.xslt.breakpoints")
1428
class PowerShellBreakpointType : XLineBreakpointType<XBreakpointProperties<*>>("powershell", MessagesBundle.message("powershell.debugger.breakpoints.title")) {
1529
override fun canPutAt(file: VirtualFile, line: Int, project: Project): Boolean {
1630
val document = FileDocumentManager.getInstance().getDocument(file) ?: return false
1731

1832
val psiFile = PsiDocumentManager.getInstance(project).getPsiFile(document) ?: return false
1933
val fileType = psiFile.fileType
20-
if (fileType != PowerShellFileType.INSTANCE) {
21-
return false
22-
}
23-
return true
34+
return fileType is PowerShellFileType
2435
}
36+
2537
override fun createBreakpointProperties(file: VirtualFile, line: Int): XBreakpointProperties<*>? {
2638
return null
2739
}
40+
41+
override fun getEditorsProvider(
42+
breakpoint: XLineBreakpoint<XBreakpointProperties<*>>,
43+
project: Project
44+
): XDebuggerEditorsProvider {
45+
return PowerShellDebuggerEditorsProvider(XDebuggerManager.getInstance(project).currentSession, "BPTYPE")
46+
}
47+
48+
49+
/*override fun createCustomConditionsPanel(): XBreakpointCustomPropertiesPanel<XLineBreakpoint<XBreakpointProperties<*>>> {
50+
return CollectionBreakpointPropertiesPanel()
51+
}*/
52+
}
53+
54+
class CollectionBreakpointPropertiesPanel : XBreakpointCustomPropertiesPanel<XLineBreakpoint<XBreakpointProperties<*>>>() {
55+
private var myClsName: String? = null
56+
private var myFieldName: String? = "Condition:"
57+
private var mySaveCollectionHistoryCheckBox: JCheckBox? = null
58+
59+
override fun getComponent(): JComponent {
60+
61+
val box = Box.createVerticalBox()
62+
63+
var panel: JPanel = JBUI.Panels.simplePanel()
64+
//panel.add(JTextField())
65+
val textField = JBTextField()
66+
val label = Label("Condition:").apply {
67+
labelFor = textField
68+
alignmentX = Component.LEFT_ALIGNMENT
69+
}
70+
box.add(label)
71+
box.add(textField)
72+
panel.add(box)
73+
74+
return panel
75+
}
76+
77+
override fun saveTo(breakpoint: XLineBreakpoint<XBreakpointProperties<*>>) {
78+
/* val changed =
79+
breakpoint.getProperties().SHOULD_SAVE_COLLECTION_HISTORY !== mySaveCollectionHistoryCheckBox!!.isSelected
80+
breakpoint.getProperties().SHOULD_SAVE_COLLECTION_HISTORY = mySaveCollectionHistoryCheckBox!!.isSelected*/
81+
/*if (true) {
82+
(breakpoint as XBreakpointBase<*, *, *>).fireBreakpointChanged()
83+
}*/
84+
}
85+
86+
override fun loadFrom(breakpoint: XLineBreakpoint<XBreakpointProperties<*>>) {
87+
/*val properties = breakpoint.getProperties()
88+
myClsName = properties.myClassName
89+
myFieldName = properties.myFieldName
90+
mySaveCollectionHistoryCheckBox!!.isSelected = properties.SHOULD_SAVE_COLLECTION_HISTORY*/
91+
}
92+
93+
private inner class MyShowCollectionHistoryAction : AnAction() {
94+
override fun actionPerformed(e: AnActionEvent) {
95+
val clsName = myClsName
96+
val fieldName = myFieldName
97+
if (clsName == null || fieldName == null) {
98+
return
99+
}
100+
val project = getEventProject(e) ?: return
101+
val session = XDebuggerManager.getInstance(project).currentSession ?: return
102+
//DebuggerUtilsEx.addCollectionHistoryTab(session, clsName, fieldName, null)
103+
}
104+
}
105+
106+
companion object {
107+
private const val PREFERRED_PANEL_HEIGHT = 40
108+
}
28109
}

src/main/kotlin/com/intellij/plugin/powershell/ide/debugger/PowerShellDebugProcess.kt

+54-10
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,76 @@ package com.intellij.plugin.powershell.ide.debugger
33
import com.intellij.execution.ExecutionResult
44
import com.intellij.execution.ui.ExecutionConsole
55
import com.intellij.openapi.Disposable
6+
import com.intellij.openapi.application.EDT
67
import com.intellij.openapi.util.Key
78
import com.intellij.xdebugger.XDebugProcess
89
import com.intellij.xdebugger.XDebugSession
10+
import com.intellij.xdebugger.XDebuggerManager
911
import com.intellij.xdebugger.breakpoints.XBreakpointHandler
1012
import com.intellij.xdebugger.evaluation.XDebuggerEditorsProvider
13+
import com.intellij.xdebugger.frame.XSuspendContext
14+
import com.jetbrains.rd.framework.util.adviseSuspend
15+
import com.jetbrains.rd.util.lifetime.Lifetime
16+
import kotlinx.coroutines.Dispatchers
17+
import org.eclipse.lsp4j.debug.ContinueArguments
1118

12-
class PowerShellDebugProcess(session: XDebugSession, executionResult: ExecutionResult) : XDebugProcess(session), Disposable {
19+
class PowerShellDebugProcess(val xDebugSession: XDebugSession, val executionResult: ExecutionResult, val debuggerManager: XDebuggerManager, val clientSession: PowerShellDebugSession) : XDebugProcess(xDebugSession), Disposable {
1320

1421
val KEY: Key<PowerShellDebugProcess> = Key.create("com.intellij.plugin.powershell.ide.debugger.PowerShellDebugProcess")
15-
22+
val myBreakpointHandler = PowerShellBreakpointHandler(this, PowerShellBreakpointType::class.java)
1623
val myProcessHandler = executionResult.processHandler
1724
init {
1825
myProcessHandler.putUserData(KEY, this)
1926
}
2027
val myExecutionConsole = executionResult.executionConsole
21-
val myEditorsProvider = PowerShellDebuggerEditorsProvider()
28+
val myEditorsProvider = PowerShellDebuggerEditorsProvider(xDebugSession)
2229
init {
2330
com.intellij.openapi.util.Disposer.register(myExecutionConsole, this)
31+
myBreakpointHandler.registerBreakpointEvent.adviseSuspend(Lifetime.Eternal, Dispatchers.EDT) {
32+
pair -> clientSession.setBreakpoint(pair.first, pair.second)
33+
}
34+
myBreakpointHandler.unregisterBreakpointEvent.adviseSuspend(Lifetime.Eternal, Dispatchers.EDT) {
35+
pair -> clientSession.removeBreakpoint(pair.first, pair.second)
36+
}
37+
}
38+
39+
private val myXBreakpointHandlers = arrayOf<XBreakpointHandler<*>>(myBreakpointHandler)
40+
41+
override fun resume(context: XSuspendContext?) {
42+
if(context !is PowerShellSuspendContext) {
43+
return
44+
}
45+
clientSession.continueDebugging(context)
2446
}
2547

26-
private val myXBreakpointHandlers = arrayOf<XBreakpointHandler<*>>(
27-
PowerShellBreakpointHandler(
28-
this,
29-
PowerShellBreakpointType::class.java
30-
),
31-
)
48+
override fun stop() {
49+
clientSession.terminateDebugging()
50+
}
51+
52+
override fun startStepOver(context: XSuspendContext?) {
53+
if(context !is PowerShellSuspendContext) {
54+
return
55+
}
56+
clientSession.startStepOver(context)
57+
}
58+
59+
override fun startStepInto(context: XSuspendContext?) {
60+
if(context !is PowerShellSuspendContext) {
61+
return
62+
}
63+
clientSession.startStepInto(context)
64+
}
65+
66+
override fun startStepOut(context: XSuspendContext?) {
67+
if(context !is PowerShellSuspendContext) {
68+
return
69+
}
70+
clientSession.startStepOut(context)
71+
}
72+
73+
override fun startPausing() {
74+
clientSession.startPausing()
75+
}
3276

3377
override fun createConsole(): ExecutionConsole {
3478
return myExecutionConsole
@@ -42,6 +86,6 @@ class PowerShellDebugProcess(session: XDebugSession, executionResult: ExecutionR
4286
}
4387

4488
override fun dispose() {
45-
TODO("Not yet implemented")
89+
clientSession.terminateDebugging()
4690
}
4791
}

0 commit comments

Comments
 (0)