meain/evil-textobj-tree-sitter

java switch_expression node causing errors.

Closed this issue · 6 comments

Hello again!

I have found a bug in the java queries where the switch_expression node type is being called as invalid.
commenting out the query (line 30) in question fixes this but is not ideal for obvious reasons.
I may be able to provide a replacement but not for a bit as I have the first round of {tests, coursework} coming up and I won't have the time for a couple of weeks


backtrace:

Debugger entered--Lisp error: (tsc-query-invalid-node-type "switch_expression" (30 . 1) 655)
  signal(tsc-query-invalid-node-type ("switch_expression" (30 . 1) 655))
  (if (not (memq (car err) '(end-of-line end-of-buffer))) (signal (car err) (cdr err)) (message (error-message-string err)))
  (prog1 nil (evil-repeat-abort) (if (not (memq (car err) '(end-of-line end-of-buffer))) (signal (car err) (cdr err)) (message (error-message-string err))))
  (condition-case err (let ((repeat-type (evil-repeat-type motion t))) (if (functionp repeat-type) (funcall repeat-type 'pre)) (if (condition-case nil (let ((inhibit-quit nil)) (setq range (call-interactively motion)) t) (quit (setq quit-flag t) (eval '(ignore nil)))) nil (evil-repeat-abort) (setq quit-flag t)) (if (functionp repeat-type) (funcall repeat-type 'post))) (error (prog1 nil (evil-repeat-abort) (if (not (memq (car err) '(end-of-line end-of-buffer))) (signal (car err) (cdr err)) (message (error-message-string err))))))
  (let ((current-prefix-arg count) (evil-this-type (or type (evil-type motion 'exclusive)))) (condition-case err (let ((repeat-type (evil-repeat-type motion t))) (if (functionp repeat-type) (funcall repeat-type 'pre)) (if (condition-case nil (let ((inhibit-quit nil)) (setq range (call-interactively motion)) t) (quit (setq quit-flag t) (eval '...))) nil (evil-repeat-abort) (setq quit-flag t)) (if (functionp repeat-type) (funcall repeat-type 'post))) (error (prog1 nil (evil-repeat-abort) (if (not (memq (car err) '...)) (signal (car err) (cdr err)) (message (error-message-string err)))))) (cond ((evil-range-p range)) ((evil-visual-state-p) (setq range (evil-visual-range))) ((region-active-p) (setq range (evil-range (region-beginning) (region-end) evil-this-type))) (t (setq range (evil-expand-range (evil-normalize evil-motion-marker (point) evil-this-type))))) (if (or (null type) (eq (evil-type range) type)) nil (evil-set-type range type) (evil-expand-range range)) (evil-set-range-properties range nil) range)
  (unwind-protect (let ((current-prefix-arg count) (evil-this-type (or type (evil-type motion 'exclusive)))) (condition-case err (let ((repeat-type (evil-repeat-type motion t))) (if (functionp repeat-type) (funcall repeat-type 'pre)) (if (condition-case nil (let (...) (setq range ...) t) (quit (setq quit-flag t) (eval ...))) nil (evil-repeat-abort) (setq quit-flag t)) (if (functionp repeat-type) (funcall repeat-type 'post))) (error (prog1 nil (evil-repeat-abort) (if (not (memq ... ...)) (signal (car err) (cdr err)) (message (error-message-string err)))))) (cond ((evil-range-p range)) ((evil-visual-state-p) (setq range (evil-visual-range))) ((region-active-p) (setq range (evil-range (region-beginning) (region-end) evil-this-type))) (t (setq range (evil-expand-range (evil-normalize evil-motion-marker (point) evil-this-type))))) (if (or (null type) (eq (evil-type range) type)) nil (evil-set-type range type) (evil-expand-range range)) (evil-set-range-properties range nil) range) (if evil-inhibit-operator nil (set-buffer obuffer) (evil-move-mark omark) (goto-char opoint)) (move-marker evil-motion-marker nil))
  (let ((evil-restriction-stack (cons (cons (point-min) (point-max)) evil-restriction-stack))) (evil-narrow (field-beginning) (field-end)) (unwind-protect (let ((current-prefix-arg count) (evil-this-type (or type (evil-type motion 'exclusive)))) (condition-case err (let ((repeat-type (evil-repeat-type motion t))) (if (functionp repeat-type) (funcall repeat-type 'pre)) (if (condition-case nil (let ... ... t) (quit ... ...)) nil (evil-repeat-abort) (setq quit-flag t)) (if (functionp repeat-type) (funcall repeat-type 'post))) (error (prog1 nil (evil-repeat-abort) (if (not ...) (signal ... ...) (message ...))))) (cond ((evil-range-p range)) ((evil-visual-state-p) (setq range (evil-visual-range))) ((region-active-p) (setq range (evil-range (region-beginning) (region-end) evil-this-type))) (t (setq range (evil-expand-range (evil-normalize evil-motion-marker ... evil-this-type))))) (if (or (null type) (eq (evil-type range) type)) nil (evil-set-type range type) (evil-expand-range range)) (evil-set-range-properties range nil) range) (if evil-inhibit-operator nil (set-buffer obuffer) (evil-move-mark omark) (goto-char opoint)) (move-marker evil-motion-marker nil)))
  (save-restriction (let ((evil-restriction-stack (cons (cons (point-min) (point-max)) evil-restriction-stack))) (evil-narrow (field-beginning) (field-end)) (unwind-protect (let ((current-prefix-arg count) (evil-this-type (or type (evil-type motion ...)))) (condition-case err (let ((repeat-type ...)) (if (functionp repeat-type) (funcall repeat-type ...)) (if (condition-case nil ... ...) nil (evil-repeat-abort) (setq quit-flag t)) (if (functionp repeat-type) (funcall repeat-type ...))) (error (prog1 nil (evil-repeat-abort) (if ... ... ...)))) (cond ((evil-range-p range)) ((evil-visual-state-p) (setq range (evil-visual-range))) ((region-active-p) (setq range (evil-range ... ... evil-this-type))) (t (setq range (evil-expand-range ...)))) (if (or (null type) (eq (evil-type range) type)) nil (evil-set-type range type) (evil-expand-range range)) (evil-set-range-properties range nil) range) (if evil-inhibit-operator nil (set-buffer obuffer) (evil-move-mark omark) (goto-char opoint)) (move-marker evil-motion-marker nil))))
  (progn (evil-save-transient-mark-mode) (evil-transient-mark 1) (save-restriction (let ((evil-restriction-stack (cons (cons (point-min) (point-max)) evil-restriction-stack))) (evil-narrow (field-beginning) (field-end)) (unwind-protect (let ((current-prefix-arg count) (evil-this-type (or type ...))) (condition-case err (let (...) (if ... ...) (if ... nil ... ...) (if ... ...)) (error (prog1 nil ... ...))) (cond ((evil-range-p range)) ((evil-visual-state-p) (setq range ...)) ((region-active-p) (setq range ...)) (t (setq range ...))) (if (or (null type) (eq ... type)) nil (evil-set-type range type) (evil-expand-range range)) (evil-set-range-properties range nil) range) (if evil-inhibit-operator nil (set-buffer obuffer) (evil-move-mark omark) (goto-char opoint)) (move-marker evil-motion-marker nil)))))
  (unwind-protect (progn (evil-save-transient-mark-mode) (evil-transient-mark 1) (save-restriction (let ((evil-restriction-stack (cons (cons ... ...) evil-restriction-stack))) (evil-narrow (field-beginning) (field-end)) (unwind-protect (let ((current-prefix-arg count) (evil-this-type ...)) (condition-case err (let ... ... ... ...) (error ...)) (cond (...) (... ...) (... ...) (t ...)) (if (or ... ...) nil (evil-set-type range type) (evil-expand-range range)) (evil-set-range-properties range nil) range) (if evil-inhibit-operator nil (set-buffer obuffer) (evil-move-mark omark) (goto-char opoint)) (move-marker evil-motion-marker nil))))) (evil-restore-transient-mark-mode))
  (let ((inhibit-quit t) evil-transient-vals) (unwind-protect (progn (evil-save-transient-mark-mode) (evil-transient-mark 1) (save-restriction (let ((evil-restriction-stack (cons ... evil-restriction-stack))) (evil-narrow (field-beginning) (field-end)) (unwind-protect (let (... ...) (condition-case err ... ...) (cond ... ... ... ...) (if ... nil ... ...) (evil-set-range-properties range nil) range) (if evil-inhibit-operator nil (set-buffer obuffer) (evil-move-mark omark) (goto-char opoint)) (move-marker evil-motion-marker nil))))) (evil-restore-transient-mark-mode)))
  (let ((opoint (point)) (omark (mark t)) (obuffer (current-buffer)) (evil-motion-marker (move-marker (make-marker) (point))) range) (let ((inhibit-quit t) evil-transient-vals) (unwind-protect (progn (evil-save-transient-mark-mode) (evil-transient-mark 1) (save-restriction (let ((evil-restriction-stack ...)) (evil-narrow (field-beginning) (field-end)) (unwind-protect (let ... ... ... ... ... range) (if evil-inhibit-operator nil ... ... ...) (move-marker evil-motion-marker nil))))) (evil-restore-transient-mark-mode))))
  evil-motion-range(evil-textobj-tree-sitter-function--class\.outer nil nil)
  (setq range (evil-motion-range motion count type))
  (let ((evil-state 'operator) mark-active) (setq range (evil-motion-range motion count type)))
  (progn (let ((evil-state 'operator) mark-active) (setq range (evil-motion-range motion count type))))
  (if motion (progn (let ((evil-state 'operator) mark-active) (setq range (evil-motion-range motion count type)))))
  (progn (if motion nil (evil-change-state 'operator) (let ((keys (nth 2 (evil-extract-count (this-command-keys))))) (setq keys (listify-key-sequence keys)) (let ((--dotimes-limit-- (length keys)) (--dotimes-counter-- 0)) (while (< --dotimes-counter-- --dotimes-limit--) (let ((var --dotimes-counter--)) (define-key evil-operator-shortcut-map (vconcat ...) 'evil-line-or-visual-line)) (setq --dotimes-counter-- (1+ --dotimes-counter--))))) (setq command (evil-read-motion motion) motion (nth 0 command) count (nth 1 command) type (or type (nth 2 command)))) (cond ((eq motion #'undefined) (setq range (if return-type '(nil nil nil) '(nil nil)) motion nil)) ((or (null motion) (evil-get-command-property motion :suppress-operator)) (if (fboundp 'evil-repeat-abort) (progn (evil-repeat-abort))) (setq quit-flag t motion nil)) (evil-repeat-count (setq count evil-repeat-count evil-repeat-count nil)) ((or count current-prefix-arg) (setq count (* (prefix-numeric-value count) (prefix-numeric-value current-prefix-arg))))) (if motion (progn (let ((evil-state 'operator) mark-active) (setq range (evil-motion-range motion count type))))) (setq evil-this-motion motion evil-this-motion-count count type (evil-type range type) evil-this-type type))
  (unwind-protect (progn (if motion nil (evil-change-state 'operator) (let ((keys (nth 2 (evil-extract-count ...)))) (setq keys (listify-key-sequence keys)) (let ((--dotimes-limit-- (length keys)) (--dotimes-counter-- 0)) (while (< --dotimes-counter-- --dotimes-limit--) (let (...) (define-key evil-operator-shortcut-map ... ...)) (setq --dotimes-counter-- (1+ --dotimes-counter--))))) (setq command (evil-read-motion motion) motion (nth 0 command) count (nth 1 command) type (or type (nth 2 command)))) (cond ((eq motion #'undefined) (setq range (if return-type '(nil nil nil) '(nil nil)) motion nil)) ((or (null motion) (evil-get-command-property motion :suppress-operator)) (if (fboundp 'evil-repeat-abort) (progn (evil-repeat-abort))) (setq quit-flag t motion nil)) (evil-repeat-count (setq count evil-repeat-count evil-repeat-count nil)) ((or count current-prefix-arg) (setq count (* (prefix-numeric-value count) (prefix-numeric-value current-prefix-arg))))) (if motion (progn (let ((evil-state 'operator) mark-active) (setq range (evil-motion-range motion count type))))) (setq evil-this-motion motion evil-this-motion-count count type (evil-type range type) evil-this-type type)) (if (buffer-live-p buf) (progn (save-current-buffer (set-buffer buf) (evil-change-state old-state)))))
  (let* ((evil-state evil-state) (evil-previous-state evil-previous-state) (evil-previous-state-alist (copy-tree evil-previous-state-alist)) (evil-next-state evil-next-state) (old-state evil-state) (inhibit-quit t) (buf (current-buffer))) (unwind-protect (progn (if motion nil (evil-change-state 'operator) (let ((keys (nth 2 ...))) (setq keys (listify-key-sequence keys)) (let ((--dotimes-limit-- ...) (--dotimes-counter-- 0)) (while (< --dotimes-counter-- --dotimes-limit--) (let ... ...) (setq --dotimes-counter-- ...)))) (setq command (evil-read-motion motion) motion (nth 0 command) count (nth 1 command) type (or type (nth 2 command)))) (cond ((eq motion #'undefined) (setq range (if return-type '... '...) motion nil)) ((or (null motion) (evil-get-command-property motion :suppress-operator)) (if (fboundp 'evil-repeat-abort) (progn (evil-repeat-abort))) (setq quit-flag t motion nil)) (evil-repeat-count (setq count evil-repeat-count evil-repeat-count nil)) ((or count current-prefix-arg) (setq count (* (prefix-numeric-value count) (prefix-numeric-value current-prefix-arg))))) (if motion (progn (let ((evil-state ...) mark-active) (setq range (evil-motion-range motion count type))))) (setq evil-this-motion motion evil-this-motion-count count type (evil-type range type) evil-this-type type)) (if (buffer-live-p buf) (progn (save-current-buffer (set-buffer buf) (evil-change-state old-state))))))
  (cond ((and evil-ex-p evil-ex-range) (setq range evil-ex-range)) ((and (not evil-ex-p) (evil-visual-state-p)) (setq range (evil-visual-range))) ((and (not evil-ex-p) (region-active-p)) (setq range (evil-range (region-beginning) (region-end) (or evil-this-type 'exclusive)))) (t (let* ((evil-state evil-state) (evil-previous-state evil-previous-state) (evil-previous-state-alist (copy-tree evil-previous-state-alist)) (evil-next-state evil-next-state) (old-state evil-state) (inhibit-quit t) (buf (current-buffer))) (unwind-protect (progn (if motion nil (evil-change-state 'operator) (let (...) (setq keys ...) (let ... ...)) (setq command (evil-read-motion motion) motion (nth 0 command) count (nth 1 command) type (or type ...))) (cond ((eq motion ...) (setq range ... motion nil)) ((or ... ...) (if ... ...) (setq quit-flag t motion nil)) (evil-repeat-count (setq count evil-repeat-count evil-repeat-count nil)) ((or count current-prefix-arg) (setq count ...))) (if motion (progn (let ... ...))) (setq evil-this-motion motion evil-this-motion-count count type (evil-type range type) evil-this-type type)) (if (buffer-live-p buf) (progn (save-current-buffer (set-buffer buf) (evil-change-state old-state))))))))
  (progn (evil-echo-area-save) (cond ((and evil-ex-p evil-ex-range) (setq range evil-ex-range)) ((and (not evil-ex-p) (evil-visual-state-p)) (setq range (evil-visual-range))) ((and (not evil-ex-p) (region-active-p)) (setq range (evil-range (region-beginning) (region-end) (or evil-this-type 'exclusive)))) (t (let* ((evil-state evil-state) (evil-previous-state evil-previous-state) (evil-previous-state-alist (copy-tree evil-previous-state-alist)) (evil-next-state evil-next-state) (old-state evil-state) (inhibit-quit t) (buf (current-buffer))) (unwind-protect (progn (if motion nil (evil-change-state ...) (let ... ... ...) (setq command ... motion ... count ... type ...)) (cond (... ...) (... ... ...) (evil-repeat-count ...) (... ...)) (if motion (progn ...)) (setq evil-this-motion motion evil-this-motion-count count type (evil-type range type) evil-this-type type)) (if (buffer-live-p buf) (progn (save-current-buffer ... ...))))))) (if (evil-range-p range) (progn (if (or (null type) (eq (evil-type range) type)) nil (evil-contract-range range) (evil-set-type range type) (evil-expand-range range)) (evil-set-range-properties range nil) (if return-type nil (evil-set-type range nil)) (setq evil-operator-range-beginning (evil-range-beginning range) evil-operator-range-end (evil-range-end range) evil-operator-range-type (evil-type range)))) range)
  (unwind-protect (progn (evil-echo-area-save) (cond ((and evil-ex-p evil-ex-range) (setq range evil-ex-range)) ((and (not evil-ex-p) (evil-visual-state-p)) (setq range (evil-visual-range))) ((and (not evil-ex-p) (region-active-p)) (setq range (evil-range (region-beginning) (region-end) (or evil-this-type 'exclusive)))) (t (let* ((evil-state evil-state) (evil-previous-state evil-previous-state) (evil-previous-state-alist (copy-tree evil-previous-state-alist)) (evil-next-state evil-next-state) (old-state evil-state) (inhibit-quit t) (buf (current-buffer))) (unwind-protect (progn (if motion nil ... ... ...) (cond ... ... ... ...) (if motion ...) (setq evil-this-motion motion evil-this-motion-count count type ... evil-this-type type)) (if (buffer-live-p buf) (progn ...)))))) (if (evil-range-p range) (progn (if (or (null type) (eq (evil-type range) type)) nil (evil-contract-range range) (evil-set-type range type) (evil-expand-range range)) (evil-set-range-properties range nil) (if return-type nil (evil-set-type range nil)) (setq evil-operator-range-beginning (evil-range-beginning range) evil-operator-range-end (evil-range-end range) evil-operator-range-type (evil-type range)))) range) (evil-echo-area-restore))
  (let ((inhibit-quit t) evil-echo-area-message evil-write-echo-area) (unwind-protect (progn (evil-echo-area-save) (cond ((and evil-ex-p evil-ex-range) (setq range evil-ex-range)) ((and (not evil-ex-p) (evil-visual-state-p)) (setq range (evil-visual-range))) ((and (not evil-ex-p) (region-active-p)) (setq range (evil-range (region-beginning) (region-end) (or evil-this-type ...)))) (t (let* ((evil-state evil-state) (evil-previous-state evil-previous-state) (evil-previous-state-alist ...) (evil-next-state evil-next-state) (old-state evil-state) (inhibit-quit t) (buf ...)) (unwind-protect (progn ... ... ... ...) (if ... ...))))) (if (evil-range-p range) (progn (if (or (null type) (eq ... type)) nil (evil-contract-range range) (evil-set-type range type) (evil-expand-range range)) (evil-set-range-properties range nil) (if return-type nil (evil-set-type range nil)) (setq evil-operator-range-beginning (evil-range-beginning range) evil-operator-range-end (evil-range-end range) evil-operator-range-type (evil-type range)))) range) (evil-echo-area-restore)))
  (let* ((evil-ex-p (and (not (minibufferp)) (evil-ex-p))) (motion (or evil-operator-range-motion (if evil-ex-p (progn 'evil-line)))) (type evil-operator-range-type) (range (evil-range (point) (point))) command count) (setq evil-this-type-modified nil) (let ((inhibit-quit t) evil-echo-area-message evil-write-echo-area) (unwind-protect (progn (evil-echo-area-save) (cond ((and evil-ex-p evil-ex-range) (setq range evil-ex-range)) ((and (not evil-ex-p) (evil-visual-state-p)) (setq range (evil-visual-range))) ((and (not evil-ex-p) (region-active-p)) (setq range (evil-range ... ... ...))) (t (let* (... ... ... ... ... ... ...) (unwind-protect ... ...)))) (if (evil-range-p range) (progn (if (or ... ...) nil (evil-contract-range range) (evil-set-type range type) (evil-expand-range range)) (evil-set-range-properties range nil) (if return-type nil (evil-set-type range nil)) (setq evil-operator-range-beginning (evil-range-beginning range) evil-operator-range-end (evil-range-end range) evil-operator-range-type (evil-type range)))) range) (evil-echo-area-restore))))
  evil-operator-range(t)
  (append (evil-operator-range t) (list evil-this-register (evil-yank-handler)))
  (prog1 (append (evil-operator-range t) (list evil-this-register (evil-yank-handler))) (setq orig (point) evil-inhibit-operator-value evil-inhibit-operator) (if nil (if (evil-visual-state-p) (progn (evil-visual-expand-region))) (if (or (evil-visual-state-p) (region-active-p)) (progn (setq deactivate-mark t)))) (cond ((evil-visual-state-p) (evil-visual-rotate 'upper-left)) ((evil-get-command-property 'evil-yank :move-point) (goto-char (or evil-operator-range-beginning orig))) (t (goto-char orig))))
  (let* ((evil-operator-range-motion (if (evil-has-command-property-p 'evil-yank :motion) (progn (or (evil-get-command-property 'evil-yank :motion) #'undefined)))) (evil-operator-range-type (evil-get-command-property 'evil-yank :type)) (orig (point)) evil-operator-range-beginning evil-operator-range-end evil-inhibit-operator) (setq evil-inhibit-operator-value nil evil-this-operator this-command) (setq evil-operator-start-col (current-column)) (prog1 (append (evil-operator-range t) (list evil-this-register (evil-yank-handler))) (setq orig (point) evil-inhibit-operator-value evil-inhibit-operator) (if nil (if (evil-visual-state-p) (progn (evil-visual-expand-region))) (if (or (evil-visual-state-p) (region-active-p)) (progn (setq deactivate-mark t)))) (cond ((evil-visual-state-p) (evil-visual-rotate 'upper-left)) ((evil-get-command-property 'evil-yank :move-point) (goto-char (or evil-operator-range-beginning orig))) (t (goto-char orig)))))
  #<subr call-interactively>(evil-yank nil nil)
  apply(#<subr call-interactively> (evil-yank nil nil))
  explain-pause--wrap-call-interactively(#<subr call-interactively> evil-yank nil nil)
  apply(explain-pause--wrap-call-interactively #<subr call-interactively> (evil-yank nil nil))
  call-interactively(evil-yank nil nil)
  command-execute(evil-yank)
meain commented

Thanks for reporting. Looks like, in the grammar that elisp-tree-sitter uses, it actually called switch_statement instead of switch_expression. It is switch_expression in current master of the java grammar.

I think the ideal route would be for elisp-tree-sitter to bump to the new version. I will open an issue upstream to discuss about this.


meain commented
diff --git a/queries/java/textobjects.scm b/queries/java/textobjects.scm
index 92a8a04..2b8efff 100644
--- a/queries/java/textobjects.scm
+++ b/queries/java/textobjects.scm
@@ -27,7 +27,7 @@
   alternative: (_)? @conditional.inner
   ) @conditional.outer
 
-(switch_expression
+(switch_statement
   body: (_)? @conditional.inner) @conditional.outer
 
 ;; blocks

This would fix the queries for now, but I think it if better it if fixed upstream. If there is a significant delay in the upstream update, I can fix it temporarily here.

Ok ill make an issue to tree-sitter-langs and see if they can bump java and report back

meain commented

emacs-tree-sitter/tree-sitter-langs#56 this should fix the issue when merged

meain commented

Looks like this is now fixed. Thanks @jeetelongname