Skip to content

Commit

Permalink
Error in symex-ts--handle-tree-modification for internal TS library
Browse files Browse the repository at this point in the history
Support for handling tree changes needs to be implemented differently
for the internal tree sitter library.
  • Loading branch information
polaris64 authored and countvajhula committed Feb 19, 2025
1 parent ae8f97c commit dba18b7
Showing 1 changed file with 34 additions and 33 deletions.
67 changes: 34 additions & 33 deletions symex-transformations-ts.el
Original file line number Diff line number Diff line change
Expand Up @@ -38,41 +38,42 @@ selected according to the ranges that have changed."
;; TODO: Implement symex-ts--handle-tree-modification for the internal tree sitter library
'(error "Unable to perform edit: the Emacs internal tree sitter library is not yet supported")

(let ((prev-tree (gensym))
(res (gensym))
(changed-ranges (gensym))
(orig-pos (gensym)))

`(let ((,prev-tree tree-sitter-tree)
(,orig-pos (point)))

`(let ((,prev-tree tree-sitter-tree))

;; Execute BODY, bind to RES
(let ((,res (progn ,@body)))

;; Move point to the first changed range if possible
(when (and (> (length ,changed-ranges) 0)
(> (length (elt ,changed-ranges 0)) 0))
(let ((new-pos (elt (elt ,changed-ranges 0) 0)))
;; don't move point to before the
;; original point location
(if (< new-pos ,orig-pos)
(goto-char ,orig-pos)
(goto-char new-pos)
;; If the change starts on a carriage return, move
;; forward one character
(when (char-equal ?\C-j (char-after))
(forward-char 1))))))

;; Update current node from point and reindent if necessary
(symex-ts-set-current-node-from-point)
(when symex-highlight-p
(symex--update-overlay))
(indent-according-to-mode))
(let ((prev-tree (gensym))
(res (gensym))
(changed-ranges (gensym)))

`(let ((,prev-tree tree-sitter-tree))

;; Execute BODY, bind to RES
(let ((,res (progn ,@body)))

;; Get changes from previous to current tree
(let ((,changed-ranges (tsc-changed-ranges ,prev-tree tree-sitter-tree)))

;; Move point to the first changed range if possible
(when (and (> (length ,changed-ranges) 0)
(> (length (elt ,changed-ranges 0)) 0))
(goto-char (elt (elt ,changed-ranges 0) 0))

;; If the change starts on a carriage return, move
;; forward one character
(when (char-equal ?\C-j (char-after))
(forward-char 1)))

;; Update current node from point and reindent if necessary
(symex-ts-set-current-node-from-point)
(when symex-highlight-p
(symex--update-overlay))
(indent-according-to-mode))

;; Return the result of evaluating BODY
,res))))
,res)))))

(defun symex-ts-change-node-forward (&optional count)
"Delete COUNT nodes forward from the current node and enter Insert state."
(interactive "p")
(save-excursion (symex-ts-delete-node-forward count t))
(evil-insert-state 1))

(defun symex-ts-clear ()
"Clear contents of symex."
Expand Down

0 comments on commit dba18b7

Please sign in to comment.