@@ -121,7 +121,9 @@ var breakpoint_locations: dict<any>
121121var BreakpointSigns: list <string>
122122
123123var evalFromBalloonExpr: bool
124- var evalFromBalloonExprResult: string
124+ var evalInPopup: bool
125+ var evalPopupId: number
126+ var evalExprResult: string
125127var ignoreEvalError: bool
126128var evalexpr: string
127129# Remember the old value of ' signcolumn' for each buffer that it's set in , so
@@ -202,7 +204,9 @@ def InitScriptVariables()
202204 BreakpointSigns = []
203205
204206 evalFromBalloonExpr = false
205- evalFromBalloonExprResult = ' '
207+ evalInPopup = false
208+ evalPopupId = -1
209+ evalExprResult = ' '
206210 ignoreEvalError = false
207211 evalexpr = ' '
208212 # Remember the old value of ' signcolumn' for each buffer that it's set in , so
@@ -1478,10 +1482,23 @@ def SendEval(expr: string)
14781482 evalexpr = exprLHS
14791483enddef
14801484
1485+ # Returns whether to evaluate in a popup or not, defaults to false.
1486+ def EvaluateInPopup (): bool
1487+ if exists (' g:termdebug_config' )
1488+ return get (g: termdebug_config , ' evaluate_in_popup' , false)
1489+ endif
1490+ return false
1491+ enddef
1492+
14811493# :Evaluate - evaluate what is specified / under the cursor
14821494def Evaluate (range : number , arg: string )
14831495 var expr = GetEvaluationExpression (range , arg)
1484- echom $ " expr: {expr}"
1496+ if EvaluateInPopup ()
1497+ evalInPopup = true
1498+ evalExprResult = ' '
1499+ else
1500+ echomsg $ ' expr: {expr}'
1501+ endif
14851502 ignoreEvalError = false
14861503 SendEval (expr )
14871504enddef
@@ -1541,6 +1558,37 @@ def Balloon_show(expr: string)
15411558 endif
15421559enddef
15431560
1561+ def Popup_format (expr : string ): list <string>
1562+ var lines = expr
1563+ - >substitute (' {' , ' {\n' , ' g' )
1564+ - >substitute (' }' , ' \n}' , ' g' )
1565+ - >substitute (' ,' , ' ,\n' , ' g' )
1566+ - >split (' \n' )
1567+ var indentation = 0
1568+ var formatted_lines = []
1569+ for line in lines
1570+ var stripped = line - >substitute (' ^\s\+' , ' ' , ' ' )
1571+ if stripped = ~ ' ^}'
1572+ indentation -= 2
1573+ endif
1574+ formatted_lines- >add (repeat (' ' , indentation) .. stripped)
1575+ if stripped = ~ ' {$'
1576+ indentation += 2
1577+ endif
1578+ endfor
1579+ return formatted_lines
1580+ enddef
1581+
1582+ def Popup_show (expr : string )
1583+ var formatted = Popup_format (expr )
1584+ if evalPopupId != -1
1585+ popup_close (evalPopupId)
1586+ endif
1587+ # Specifying the line is necessary, as the winbar seems to cause issues
1588+ # otherwise. I.e ., the popup would be shown one line too high.
1589+ evalPopupId = popup_atcursor (formatted, {' line' : ' cursor-1' })
1590+ enddef
1591+
15441592def HandleEvaluate (msg: string )
15451593 var value = msg
15461594 - >substitute (' .*value="\(.*\)"' , ' \1' , ' ' )
@@ -1555,13 +1603,12 @@ def HandleEvaluate(msg: string)
15551603 #\ - >substitute (' \\0x00' , NullRep, ' g' )
15561604 #\ - >substitute (' \\0x\(\x\x\)' , {- > eval (' "\x' .. submatch (1 ) .. ' "' )}, ' g' )
15571605 - >substitute (NullRepl, ' \\000' , ' g' )
1558- if evalFromBalloonExpr
1559- if empty (evalFromBalloonExprResult )
1560- evalFromBalloonExprResult = $ ' {evalexpr}: {value}'
1606+ if evalFromBalloonExpr || evalInPopup
1607+ if empty (evalExprResult )
1608+ evalExprResult = $ ' {evalexpr}: {value}'
15611609 else
1562- evalFromBalloonExprResult ..= $ ' = {value}'
1610+ evalExprResult ..= $ ' = {value}'
15631611 endif
1564- Balloon_show (evalFromBalloonExprResult)
15651612 else
15661613 echomsg $ ' "{evalexpr}": {value}'
15671614 endif
@@ -1570,8 +1617,12 @@ def HandleEvaluate(msg: string)
15701617 # Looks like a pointer, also display what it points to .
15711618 ignoreEvalError = true
15721619 SendEval ($ ' *{evalexpr}' )
1573- else
1620+ elseif evalFromBalloonExpr
1621+ Balloon_show (evalExprResult)
15741622 evalFromBalloonExpr = false
1623+ elseif evalInPopup
1624+ Popup_show (evalExprResult)
1625+ evalInPopup = false
15751626 endif
15761627enddef
15771628
@@ -1588,7 +1639,7 @@ def TermDebugBalloonExpr(): string
15881639 return ' '
15891640 endif
15901641 evalFromBalloonExpr = true
1591- evalFromBalloonExprResult = ' '
1642+ evalExprResult = ' '
15921643 ignoreEvalError = true
15931644 var expr = CleanupExpr (v: beval_text )
15941645 SendEval (expr )
0 commit comments