7272 " If non-nil, use native json parsing if available."
7373 :group 'phpactor
7474 :type 'boolean )
75+
76+ (defcustom phpactor-use-xref t
77+ " Defines phpactor xref backend."
78+ :group 'phpactor
79+ :type 'boolean )
7580
7681; ; Variables
7782(defvar phpactor--debug nil )
@@ -722,57 +727,6 @@ function."
722727 (let ((arguments (phpactor--command-argments :source :path )))
723728 (apply #'phpactor-action-dispatch (phpactor--rpc " transform" (append arguments (list :transform " implement_contracts" ))))))
724729
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-
776730;;;### autoload
777731(defun phpactor-find-references ()
778732 " Execute Phpactor RPC references action to find references."
@@ -781,6 +735,12 @@ The MATCH is one output result from the ag search."
781735 (apply #'phpactor-action-dispatch (phpactor--rpc " references" arguments))
782736 (phpactor-list-references)))
783737
738+ ;;;### autoload
739+ (defun phpactor--find-references ()
740+ " Execute Phpactor RPC references action to find references."
741+ (let ((arguments (phpactor--command-argments :source :path :offset )))
742+ (apply #'phpactor-action-dispatch (phpactor--rpc " references" arguments))))
743+
784744;;;### autoload
785745(defun phpactor-replace-references ()
786746 " Execute Phpactor RPC references action command to replace references."
@@ -872,5 +832,8 @@ The MATCH is one output result from the ag search."
872832 (let ((arguments (phpactor--command-argments :source :path :offset )))
873833 (apply #'phpactor-action-dispatch (phpactor--rpc " change_visibility" arguments))))
874834
835+ (when phpactor-use-xref
836+ (require 'phpactor-xref ))
837+
875838(provide 'phpactor )
876839; ;; phpactor.el ends here
0 commit comments