From e0e946d3b1dca02c29d5072842878aaddcfa5161 Mon Sep 17 00:00:00 2001 From: Alexander Rosenberg Date: Mon, 13 Apr 2026 11:33:33 -0700 Subject: [PATCH] Update zsh-ts-mode.el --- elisp/zsh-ts-mode.el | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/elisp/zsh-ts-mode.el b/elisp/zsh-ts-mode.el index 3fd7713..2396e68 100644 --- a/elisp/zsh-ts-mode.el +++ b/elisp/zsh-ts-mode.el @@ -406,6 +406,33 @@ NODE is the argument to let (possibly with a = in it)." (function (zsh-ts-mode--xref-function-definitions identifier)) (variable (zsh-ts-mode--xref-variable-definitions identifier)))) +(defun zsh-ts-mode--xref-function-references (identifier) + "Find all references for the function IDENTIFIER in the current buffer." + (let ((nodes (treesit-query-capture + (treesit-buffer-root-node) + `((command name: (command_name (word) @name))) + nil nil t)) + (ident-copy (copy-sequence identifier))) + (set-text-properties 0 (length ident-copy) nil ident-copy) + (cl-loop for node in nodes + collect (xref-make + (propertize ident-copy 'face + 'font-lock-function-name-face) + (zsh-ts-mode--treesit-node-location node))))) + +(defun zsh-ts-mode--xref-variable-references (identifier) + "Find all references for the variable IDENTIFIER in the current buffer." + ()) + +(cl-defmethod xref-backend-references ((_backend (eql zsh-ts)) identifier) + "`zsh-ts-mode' implementation for finding xref references for IDENTIFIER." + (append + ;; definitions are references + (xref-backend-definitions 'zsh-ts identifier) + (cl-case (get-text-property 0 'type identifier) + (function (zsh-ts-mode--xref-function-references identifier)) + (variable (zsh-ts-mode--xref-variable-references identifier))))) + ;;;###autoload (define-derived-mode zsh-ts-mode sh-base-mode "Zsh" ;; This function is based mostly on `bash-ts-mode'.