@@ -722,6 +722,57 @@ function."
722722 (let ((arguments (phpactor--command-argments :source :path )))
723723 (apply #'phpactor-action-dispatch (phpactor--rpc " transform" (append arguments (list :transform " implement_contracts" ))))))
724724
725+ (require 'xref )
726+
727+ (defun xref-phpactor-xref-backend ()
728+ " Xref-phpactor backend for Xref."
729+ 'xref-phpactor )
730+
731+ (cl-defmethod xref-backend-definitions ((_backend (eql xref-phpactor)) symbol)
732+ (xref-phpactor--xref-find-definitions symbol))
733+
734+ (defun xref-phpactor--xref-find-definitions (symbol )
735+ " Return a list of candidates matching SYMBOL."
736+ (seq-map (lambda (candidate )
737+ (xref-phpactor--make-xref candidate))
738+ (xref-phpactor--find-definitions symbol)))
739+
740+ (defun xref-phpactor--make-xref (candidate )
741+ " Return a new Xref object built from CANDIDATE."
742+ (xref-make (map-elt candidate 'match )
743+ (xref-make-file-location (map-elt candidate 'file )
744+ (map-elt candidate 'line )
745+ 0 )))
746+
747+ (defun xref-phpactor--find-definitions (symbol )
748+ " Return a list of definitions for SYMBOL from an ag search."
749+ (xref-phpactor--find-candidates symbol))
750+
751+ (defun xref-phpactor--find-candidates (symbol )
752+ (let ((current-references phpactor-references)
753+ matches)
754+ (dolist (file-reference current-references)
755+ (let ((path (plist-get file-reference :file )))
756+ (dolist (reference (plist-get file-reference :references ))
757+ (when path
758+ (push 'matches (list (cons 'file path)
759+ (cons 'line (plist-get reference :line_no ))
760+ ; ; (cons 'symbol symbol)
761+ ; ; (cons 'match match)
762+ ))))))
763+ matches))
764+
765+ (defun xref-phpactor--candidate (symbol file-reference )
766+ " Return a candidate alist built from SYMBOL and a raw MATCH result.
767+ The MATCH is one output result from the ag search."
768+ (let* ()
769+ ; ; Some minified JS files might match a search. To avoid cluttering the
770+ ; ; search result, we trim the output.
771+ (list (cons 'file (expand-file-name (car attrs) (xref-js2--root-dir)))
772+ (cons 'line (string-to-number (cadr attrs)))
773+ (cons 'symbol symbol)
774+ (cons 'match match ))))
775+
725776;;;### autoload
726777(defun phpactor-find-references ()
727778 " Execute Phpactor RPC references action to find references."
0 commit comments