Skip to content

Commit

Permalink
Debugger WIP 16
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Fantoom committed Aug 2, 2024
1 parent 04b2bc0 commit 14358c5
Show file tree
Hide file tree
Showing 26 changed files with 1,592 additions and 122 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ dependencies {
implementation(libs.bundles.junixsocket)

implementation(libs.lsp4j)
implementation("org.eclipse.lsp4j:org.eclipse.lsp4j.debug:0.23.1")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit")
testImplementation(libs.junit)

Expand Down
24 changes: 0 additions & 24 deletions debugger.ps1

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ import com.intellij.xdebugger.breakpoints.XBreakpointHandler
import com.intellij.xdebugger.breakpoints.XBreakpointProperties
import com.intellij.xdebugger.breakpoints.XBreakpointType
import com.intellij.xdebugger.breakpoints.XLineBreakpoint
import com.jetbrains.rd.util.reactive.Signal

class PowerShellBreakpointHandler(powerShellDebugProcess: PowerShellDebugProcess, breakpointTypeClass: Class<out XBreakpointType<XLineBreakpoint<XBreakpointProperties<*>>, *>>): XBreakpointHandler<XLineBreakpoint<XBreakpointProperties<*>>>(
breakpointTypeClass
) {
val myPowerShellDebugProcess = powerShellDebugProcess;
val myPowerShellDebugProcess = powerShellDebugProcess
val registerBreakpointEvent = Signal<Pair<String, XLineBreakpoint<XBreakpointProperties<*>>>>()
val unregisterBreakpointEvent = Signal<Pair<String, XLineBreakpoint<XBreakpointProperties<*>>>>()

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

override fun unregisterBreakpoint(breakpoint: XLineBreakpoint<XBreakpointProperties<*>>, temporary: Boolean) {
TODO("Not yet implemented")
}
val sourcePosition = breakpoint.sourcePosition
if (sourcePosition == null || !sourcePosition.file.exists() || !sourcePosition.file.isValid) {
return
}
val file = sourcePosition.file
val fileURL: String = getFileURL(file)
val lineNumber: Int = breakpoint.line
if (lineNumber == -1) {
//myXsltDebugProcess.getSession().setBreakpointInvalid(breakpoint, "Unsupported breakpoint position")
return
}
unregisterBreakpointEvent.fire(Pair(fileURL, breakpoint)) }

fun getFileURL(file: VirtualFile?): String {
return VfsUtil.virtualToIoFile(file!!).toURI().toASCIIString()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,109 @@
package com.intellij.plugin.powershell.ide.debugger

import com.intellij.ide.highlighter.XmlFileType
import com.intellij.idea.ActionsBundle
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.fileEditor.FileDocumentManager
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.plugin.powershell.PowerShellFileType
import com.intellij.plugin.powershell.ide.MessagesBundle
import com.intellij.psi.PsiDocumentManager
import com.intellij.ui.components.AnActionLink
import com.intellij.ui.components.JBTextField
import com.intellij.ui.components.Label
import com.intellij.util.ui.JBUI
import com.intellij.xdebugger.XDebuggerManager
import com.intellij.xdebugger.breakpoints.XBreakpointProperties
import com.intellij.xdebugger.breakpoints.XLineBreakpoint
import com.intellij.xdebugger.breakpoints.XLineBreakpointType
import com.intellij.xdebugger.breakpoints.ui.XBreakpointCustomPropertiesPanel
import com.intellij.xdebugger.evaluation.XDebuggerEditorsProvider
import com.intellij.xdebugger.impl.breakpoints.XBreakpointBase
import java.awt.BorderLayout
import java.awt.Component
import java.awt.Dimension
import javax.swing.*

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

val psiFile = PsiDocumentManager.getInstance(project).getPsiFile(document) ?: return false
val fileType = psiFile.fileType
if (fileType != PowerShellFileType.INSTANCE) {
return false
}
return true
return fileType is PowerShellFileType
}

override fun createBreakpointProperties(file: VirtualFile, line: Int): XBreakpointProperties<*>? {
return null
}

override fun getEditorsProvider(
breakpoint: XLineBreakpoint<XBreakpointProperties<*>>,
project: Project
): XDebuggerEditorsProvider {
return PowerShellDebuggerEditorsProvider(XDebuggerManager.getInstance(project).currentSession, "BPTYPE")
}


/*override fun createCustomConditionsPanel(): XBreakpointCustomPropertiesPanel<XLineBreakpoint<XBreakpointProperties<*>>> {
return CollectionBreakpointPropertiesPanel()
}*/
}

class CollectionBreakpointPropertiesPanel : XBreakpointCustomPropertiesPanel<XLineBreakpoint<XBreakpointProperties<*>>>() {
private var myClsName: String? = null
private var myFieldName: String? = "Condition:"
private var mySaveCollectionHistoryCheckBox: JCheckBox? = null

override fun getComponent(): JComponent {

val box = Box.createVerticalBox()

var panel: JPanel = JBUI.Panels.simplePanel()
//panel.add(JTextField())
val textField = JBTextField()
val label = Label("Condition:").apply {
labelFor = textField
alignmentX = Component.LEFT_ALIGNMENT
}
box.add(label)
box.add(textField)
panel.add(box)

return panel
}

override fun saveTo(breakpoint: XLineBreakpoint<XBreakpointProperties<*>>) {
/* val changed =
breakpoint.getProperties().SHOULD_SAVE_COLLECTION_HISTORY !== mySaveCollectionHistoryCheckBox!!.isSelected
breakpoint.getProperties().SHOULD_SAVE_COLLECTION_HISTORY = mySaveCollectionHistoryCheckBox!!.isSelected*/
/*if (true) {
(breakpoint as XBreakpointBase<*, *, *>).fireBreakpointChanged()
}*/
}

override fun loadFrom(breakpoint: XLineBreakpoint<XBreakpointProperties<*>>) {
/*val properties = breakpoint.getProperties()
myClsName = properties.myClassName
myFieldName = properties.myFieldName
mySaveCollectionHistoryCheckBox!!.isSelected = properties.SHOULD_SAVE_COLLECTION_HISTORY*/
}

private inner class MyShowCollectionHistoryAction : AnAction() {
override fun actionPerformed(e: AnActionEvent) {
val clsName = myClsName
val fieldName = myFieldName
if (clsName == null || fieldName == null) {
return
}
val project = getEventProject(e) ?: return
val session = XDebuggerManager.getInstance(project).currentSession ?: return
//DebuggerUtilsEx.addCollectionHistoryTab(session, clsName, fieldName, null)
}
}

companion object {
private const val PREFERRED_PANEL_HEIGHT = 40
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,76 @@ package com.intellij.plugin.powershell.ide.debugger
import com.intellij.execution.ExecutionResult
import com.intellij.execution.ui.ExecutionConsole
import com.intellij.openapi.Disposable
import com.intellij.openapi.application.EDT
import com.intellij.openapi.util.Key
import com.intellij.xdebugger.XDebugProcess
import com.intellij.xdebugger.XDebugSession
import com.intellij.xdebugger.XDebuggerManager
import com.intellij.xdebugger.breakpoints.XBreakpointHandler
import com.intellij.xdebugger.evaluation.XDebuggerEditorsProvider
import com.intellij.xdebugger.frame.XSuspendContext
import com.jetbrains.rd.framework.util.adviseSuspend
import com.jetbrains.rd.util.lifetime.Lifetime
import kotlinx.coroutines.Dispatchers
import org.eclipse.lsp4j.debug.ContinueArguments

class PowerShellDebugProcess(session: XDebugSession, executionResult: ExecutionResult) : XDebugProcess(session), Disposable {
class PowerShellDebugProcess(val xDebugSession: XDebugSession, val executionResult: ExecutionResult, val debuggerManager: XDebuggerManager, val clientSession: PowerShellDebugSession) : XDebugProcess(xDebugSession), Disposable {

val KEY: Key<PowerShellDebugProcess> = Key.create("com.intellij.plugin.powershell.ide.debugger.PowerShellDebugProcess")

val myBreakpointHandler = PowerShellBreakpointHandler(this, PowerShellBreakpointType::class.java)
val myProcessHandler = executionResult.processHandler
init {
myProcessHandler.putUserData(KEY, this)
}
val myExecutionConsole = executionResult.executionConsole
val myEditorsProvider = PowerShellDebuggerEditorsProvider()
val myEditorsProvider = PowerShellDebuggerEditorsProvider(xDebugSession)
init {
com.intellij.openapi.util.Disposer.register(myExecutionConsole, this)
myBreakpointHandler.registerBreakpointEvent.adviseSuspend(Lifetime.Eternal, Dispatchers.EDT) {
pair -> clientSession.setBreakpoint(pair.first, pair.second)
}
myBreakpointHandler.unregisterBreakpointEvent.adviseSuspend(Lifetime.Eternal, Dispatchers.EDT) {
pair -> clientSession.removeBreakpoint(pair.first, pair.second)
}
}

private val myXBreakpointHandlers = arrayOf<XBreakpointHandler<*>>(myBreakpointHandler)

override fun resume(context: XSuspendContext?) {
if(context !is PowerShellSuspendContext) {
return
}
clientSession.continueDebugging(context)
}

private val myXBreakpointHandlers = arrayOf<XBreakpointHandler<*>>(
PowerShellBreakpointHandler(
this,
PowerShellBreakpointType::class.java
),
)
override fun stop() {
clientSession.terminateDebugging()
}

override fun startStepOver(context: XSuspendContext?) {
if(context !is PowerShellSuspendContext) {
return
}
clientSession.startStepOver(context)
}

override fun startStepInto(context: XSuspendContext?) {
if(context !is PowerShellSuspendContext) {
return
}
clientSession.startStepInto(context)
}

override fun startStepOut(context: XSuspendContext?) {
if(context !is PowerShellSuspendContext) {
return
}
clientSession.startStepOut(context)
}

override fun startPausing() {
clientSession.startPausing()
}

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

override fun dispose() {
TODO("Not yet implemented")
clientSession.terminateDebugging()
}
}
Loading

0 comments on commit 14358c5

Please sign in to comment.