From dba18b777cd9a7b5996f4d85be320b2a97e56343 Mon Sep 17 00:00:00 2001 From: Simon Pugnet Date: Sat, 26 Nov 2022 18:18:58 +0100 Subject: [PATCH] Error in symex-ts--handle-tree-modification for internal TS library Support for handling tree changes needs to be implemented differently for the internal tree sitter library. --- symex-transformations-ts.el | 67 +++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/symex-transformations-ts.el b/symex-transformations-ts.el index c4dd3c50..ba395e87 100644 --- a/symex-transformations-ts.el +++ b/symex-transformations-ts.el @@ -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."