Skip to content

Commit db7a862

Browse files
committed
basic work
1 parent 9dbad1f commit db7a862

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed

src/main/java/com/tang/intellij/lua/debugger/LuaDebugVariableContext.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ class LuaDebugVariableContext(
7373
psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor!!.document)
7474
println("LuaDebugVariableContext: psiFile = $psiFile (${psiFile?.javaClass?.simpleName})")
7575
}
76+
77+
// Configure context immediately after initialization
78+
println("LuaDebugVariableContext: Calling configureContext()...")
79+
configureContext()
80+
println("LuaDebugVariableContext: configureContext() completed")
7681
}
7782
}
7883
}

src/main/java/com/tang/intellij/lua/debugger/emmy/EmmyDebugStackFrame.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import com.intellij.xdebugger.frame.XCompositeNode
2424
import com.intellij.xdebugger.frame.XStackFrame
2525
import com.intellij.xdebugger.frame.XValueChildrenList
2626
import com.intellij.xdebugger.impl.XSourcePositionImpl
27+
import com.tang.intellij.lua.debugger.LuaDebugVariableContext
2728
import com.tang.intellij.lua.debugger.model.DebugStackFrame
2829
import com.tang.intellij.lua.debugger.emmy.value.LuaXValue
2930
import com.tang.intellij.lua.psi.LuaFileUtil
@@ -40,8 +41,21 @@ class EmmyDebugStackFrame(
4041
private var sourcePosition: XSourcePosition? = null
4142
private var sourcePositionInitialized = false
4243

44+
// Variable context for inline values
45+
private var variableContext: LuaDebugVariableContext? = null
46+
4347
override fun getEvaluator() = evaluator
4448

49+
/**
50+
* Get or create variable context for inline values
51+
*/
52+
fun getVariableContext(): LuaDebugVariableContext {
53+
if (variableContext == null) {
54+
variableContext = LuaDebugVariableContext(this)
55+
}
56+
return variableContext!!
57+
}
58+
4559
override fun customizePresentation(component: ColoredTextContainer) {
4660
val fileName = stackData.file.substringAfterLast('/')
4761
.substringAfterLast('\\')
@@ -88,3 +102,4 @@ class EmmyDebugStackFrame(
88102
return sourcePosition
89103
}
90104
}
105+

src/main/java/com/tang/intellij/lua/debugger/emmy/value/LuaXValue.kt

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
package com.tang.intellij.lua.debugger.emmy.value
1818

1919
import com.intellij.icons.AllIcons
20+
import com.intellij.xdebugger.XSourcePosition
2021
import com.intellij.xdebugger.frame.*
22+
import com.tang.intellij.lua.debugger.LuaDebugVariableContext
2123
import com.tang.intellij.lua.debugger.LuaXBoolPresentation
2224
import com.tang.intellij.lua.debugger.LuaXNumberPresentation
2325
import com.tang.intellij.lua.debugger.LuaXStringPresentation
@@ -52,12 +54,52 @@ sealed class LuaXValue(val variable: DebugVariable) : XValue() {
5254

5355
var parent: LuaXValue? = null
5456

57+
// Lazy variable context for inline values support
58+
protected val variableContext: LuaDebugVariableContext? by lazy {
59+
(stackFrame() as? EmmyDebugStackFrame)?.let { frame ->
60+
frame.getVariableContext()
61+
}
62+
}
63+
5564
companion object {
5665
fun create(variable: DebugVariable, frame: EmmyDebugStackFrame): LuaXValue {
5766
return LuaXValueFactory.create(variable, frame)
5867
}
5968
}
6069

70+
/**
71+
* Get the stack frame this value belongs to
72+
*/
73+
protected abstract fun stackFrame(): Any?
74+
75+
/**
76+
* Get evaluation expression for inline values
77+
*/
78+
override fun getEvaluationExpression(): String {
79+
return name
80+
}
81+
82+
/**
83+
* Compute source position for inline values
84+
*/
85+
override fun computeSourcePosition(callback: XNavigatable) {
86+
println("LuaXValue.computeSourcePosition: Computing for variable '${name}'")
87+
88+
val ctx = variableContext
89+
if (ctx == null) {
90+
println("LuaXValue.computeSourcePosition: variableContext is null for '${name}'")
91+
return
92+
}
93+
94+
val position = ctx.getSourcePosition(name)
95+
if (position != null) {
96+
println("LuaXValue.computeSourcePosition: Found position for '${name}': line ${position.line}")
97+
callback.setSourcePosition(position)
98+
} else {
99+
println("LuaXValue.computeSourcePosition: No position found for '${name}'")
100+
}
101+
}
102+
61103
/**
62104
* Build full expression path for eval
63105
*/
@@ -98,6 +140,8 @@ class SimpleXValue(
98140
private val frame: EmmyDebugStackFrame
99141
) : LuaXValue(variable) {
100142

143+
override fun stackFrame() = frame
144+
101145
override fun computePresentation(node: XValueNode, place: XValuePlace) {
102146
node.setPresentation(null, variable.valueTypeName, variable.value, false)
103147
}
@@ -111,6 +155,8 @@ class StringXValue(
111155
private val frame: EmmyDebugStackFrame
112156
) : LuaXValue(variable) {
113157

158+
override fun stackFrame() = frame
159+
114160
override fun computePresentation(node: XValueNode, place: XValuePlace) {
115161
node.setPresentation(null, LuaXStringPresentation(variable.value), false)
116162
}
@@ -124,6 +170,8 @@ class NumberXValue(
124170
private val frame: EmmyDebugStackFrame
125171
) : LuaXValue(variable) {
126172

173+
override fun stackFrame() = frame
174+
127175
override fun computePresentation(node: XValueNode, place: XValuePlace) {
128176
node.setPresentation(null, LuaXNumberPresentation(variable.value), false)
129177
}
@@ -137,6 +185,8 @@ class BoolXValue(
137185
private val frame: EmmyDebugStackFrame
138186
) : LuaXValue(variable) {
139187

188+
override fun stackFrame() = frame
189+
140190
override fun computePresentation(node: XValueNode, place: XValuePlace) {
141191
node.setPresentation(null, LuaXBoolPresentation(variable.value), false)
142192
}
@@ -150,6 +200,8 @@ class GroupXValue(
150200
private val frame: EmmyDebugStackFrame
151201
) : LuaXValue(variable) {
152202

203+
override fun stackFrame() = frame
204+
153205
private val children: List<LuaXValue> by lazy {
154206
variable.children?.sortedWith(compareBy(
155207
{ if (it.isFake) 0 else 1 },
@@ -184,6 +236,8 @@ class TableXValue(
184236
private val frame: EmmyDebugStackFrame
185237
) : LuaXValue(variable) {
186238

239+
override fun stackFrame() = frame
240+
187241
private val children: List<LuaXValue> by lazy {
188242
variable.children?.sortedWith(compareBy(
189243
{ if (it.isFake) 0 else 1 },

0 commit comments

Comments
 (0)