Function: claude-code-ide-mcp-xref-find-references

claude-code-ide-mcp-xref-find-references is a natively compiled function defined in claude-code-ide-emacs-tools.el.

Signature

(claude-code-ide-mcp-xref-find-references IDENTIFIER FILE-PATH)

Documentation

Find references to IDENTIFIER in the current session's project.

FILE-PATH specifies which file's buffer context to use for the search. This function uses the session context to operate in the correct project.

Source Code

;; Defined in /nix/store/yjvbhwl7p6zrbw9xlnni7y4hra8sa3pl-emacs-packages-deps/share/emacs/site-lisp/claude-code-ide-emacs-tools.el
;;; Tool Functions

(defun claude-code-ide-mcp-xref-find-references (identifier file-path)
  "Find references to IDENTIFIER in the current session's project.
FILE-PATH specifies which file's buffer context to use for the search.
This function uses the session context to operate in the correct project."
  (if (not file-path)
      (error "file_path parameter is required. Please specify the file where you want to search for %s" identifier)
    (claude-code-ide-mcp-server-with-session-context nil
      (let ((target-buffer (or (find-buffer-visiting file-path)
                               (find-file-noselect file-path)))
            (identifier-str (format "%s" identifier)))
        (with-current-buffer target-buffer
          (condition-case err
              (let ((backend (xref-find-backend)))
                (if (not backend)
                    (format "No xref backend available for %s" file-path)
                  (let ((xref-items (xref-backend-references backend identifier-str)))
                    (if xref-items
                        (mapcar (lambda (item)
                                  (let* ((location (xref-item-location item))
                                         (file (xref-location-group location))
                                         (marker (xref-location-marker location))
                                         (line (with-current-buffer (marker-buffer marker)
                                                 (save-excursion
                                                   (goto-char marker)
                                                   (line-number-at-pos))))
                                         (summary (xref-item-summary item)))
                                    (format "%s:%d: %s" file line summary)))
                                xref-items)
                      (format "No references found for '%s'" identifier-str)))))
            (error
             (format "Error searching for '%s' in %s: %s"
                     identifier-str file-path (error-message-string err)))))))))