leoliu / ggtags

Emacs frontend to GNU Global source code tagging system.
http://elpa.gnu.org
577 stars 56 forks source link

ggtags doesn't work with xref in Emacs 27.2 since latest update #214

Closed tttuuu888 closed 2 years ago

tttuuu888 commented 2 years ago

First of all, thanks a lot for this great package. And thank for quick update for Emacs 28 as well. However ggtags doesn't work with xref in Emacs 27.2 since last update(https://github.com/leoliu/ggtags/commit/1442ab8c7f02d246f14150207534fba4a42201ba).

The error message I see from xref-find-definitions and xref-find-references is as below:

cl-no-applicable-method: No applicable method: xref-location-marker, #s(ggtags-xref-location ... ...)

Thanks.

leoliu commented 2 years ago

@tttuuu888 thanks for the report on the breakage. Are you able to test if the following patch works on both 27 and 28? I have only tested Emacs 27 since I don't have 28 built yet. Thanks.

diff --git a/ggtags.el b/ggtags.el
index 85e6fd30..3e9e9bc2 100644
--- a/ggtags.el
+++ b/ggtags.el
@@ -2371,11 +2371,23 @@ (defconst ggtags--xref-limit 1000)

 (cl-defstruct (ggtags-xref-location
                (:constructor ggtags-make-xref-location (file line column project-root)))
-  file project-root)
+  file line column project-root)

 (cl-defmethod xref-location-group ((l ggtags-xref-location))
   (file-relative-name (ggtags-xref-location-file l) (ggtags-xref-location-project-root l)))

+(cl-defmethod xref-location-marker ((l ggtags-xref-location))
+  (let ((buffer (find-file-noselect (ggtags-xref-location-file l))))
+    (with-current-buffer buffer
+      (save-excursion
+        (goto-char (point-min))
+        (forward-line (1- (ggtags-xref-location-line l)))
+        (move-to-column (1- (ggtags-xref-location-column l)))
+        (point-marker)))))
+
+(cl-defmethod xref-location-line ((l ggtags-xref-location))
+  (ggtags-xref-location-line l))
+
 (defun ggtags--xref-backend ()
   (and (ggtags-find-project)
        (let ((tag (ggtags-tag-at-point)))
tttuuu888 commented 2 years ago

@leoliu Thank you for the quick patch. I tested it on Emacs 27.2 and 28 and found it works well. Thank you!

leoliu commented 2 years ago

Thank you very much for the test!