1717package com.tang.intellij.lua.debugger.emmy.value
1818
1919import com.intellij.icons.AllIcons
20+ import com.intellij.xdebugger.XSourcePosition
2021import com.intellij.xdebugger.frame.*
22+ import com.tang.intellij.lua.debugger.LuaDebugVariableContext
2123import com.tang.intellij.lua.debugger.LuaXBoolPresentation
2224import com.tang.intellij.lua.debugger.LuaXNumberPresentation
2325import 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