Function: dape--set-variable

dape--set-variable is a natively compiled function defined in dape.el.

Signature

(dape--set-variable CONN REFERENCE VARIABLE VALUE)

Documentation

Set VARIABLE to VALUE with REFERENCE in for CONN.

Calls :setVariable endpoint if REFERENCE is an number and
:setExpression if not.
Runs the appropriate hooks on non error responses.

Source Code

;; Defined in /nix/store/1fiaif8pifqj2jh65rbg3fkhg3i56q42-emacs-packages-deps/share/emacs/site-lisp/elpa/dape-0.27.1/dape.el
(defun dape--set-variable (conn reference variable value)
  "Set VARIABLE to VALUE with REFERENCE in for CONN.
Calls :setVariable endpoint if REFERENCE is an number and
:setExpression if not.
Runs the appropriate hooks on non error responses."
  (cond
   (;; `variable' from :variable request - with reference
    (and (dape--capable-p conn :supportsSetVariable)
         (numberp reference))
    (dape--with-request-bind
        (body error)
        (dape-request
         conn :setVariable
         (list :variablesReference reference
               :name (plist-get variable :name)
               :value value))
      (if error
          (message "%s" error)
        ;; Would make more sense to update all variables after
        ;; setVariable request but certain adapters cache "variable"
        ;; response so we just update the variable in question in
        ;; place.
        (plist-put variable :variables nil)
        (cl-loop for (key value) on body by 'cddr
                 do (plist-put variable key value))
        (run-hooks 'dape-update-ui-hook))))
   (;; `variable' from :evaluate request - w/o reference
    (and (dape--capable-p conn :supportsSetExpression)
         (or (plist-get variable :evaluateName)
             (plist-get variable :name)))
    (dape--with-request-bind
        (_body error)
        (dape-request
         conn :setExpression
         (list :frameId (plist-get (dape--current-stack-frame conn) :id)
               :expression (or (plist-get variable :evaluateName)
                               (plist-get variable :name))
               :value value))
      (if error
          (message "%s" error)
        ;; Update all variables
        (dape--update conn 'variables nil))))
   ((user-error "Unable to set variable"))))