@@ -1459,6 +1459,24 @@ DESTINATION-DIR is the directory where the LSP server will be installed."
14591459
14601460(defvar eglot-java-jdt-uri-handling-patch-applied nil " Whether or not JDT uri handling is already patched." )
14611461
1462+ (defun eglot-java--wrap-eglot--path-to-uri (original-fn &rest args )
1463+ " Hack until eglot is updated.
1464+ ARGS is a list with one element, a file path. If that path names a java
1465+ file inside a `.eglot-java' directory, recover the `jdt://' URI from
1466+ within the matching `.metadata' file. Otherwise, call ORIGINAL-FN."
1467+ (let* ((path (car args))
1468+ (directory-path (file-name-directory path)))
1469+ (if (not (and (string= (file-name-extension path) " java" )
1470+ (string= (file-name-nondirectory (directory-file-name directory-path)) " .eglot-java" )))
1471+ (apply original-fn args)
1472+ (let* ((base-name (file-name-base path))
1473+ (metadata-file (concat directory-path " ." (format " %s .metadata" base-name))))
1474+ (if (not (file-readable-p metadata-file))
1475+ (apply original-fn args)
1476+ (with-temp-buffer
1477+ (insert-file-contents metadata-file)
1478+ (buffer-string )))))))
1479+
14621480(defun eglot-java--wrap-legacy-eglot--path-to-uri (original-fn &rest args )
14631481 " Hack until eglot is updated.
14641482ARGS is a list with one element, a file path or potentially a URI.
@@ -1482,6 +1500,8 @@ handle it. If it is not a jar call ORIGINAL-FN."
14821500(defun eglot-java--jdthandler-patch-eglot ()
14831501 " Patch old versions of Eglot to work with Jdthandler."
14841502 (interactive ) ; ; TODO Remove when eglot is updated in melpa
1503+ (unless (advice-member-p #'eglot-java--wrap-eglot--path-to-uri 'eglot-path-to-uri )
1504+ (advice-add 'eglot-path-to-uri :around #'eglot-java--wrap-eglot--path-to-uri ))
14851505 ; ; See also https://debbugs.gnu.org/cgi/bugreport.cgi?bug=58790
14861506 ; ; See also https://git.savannah.gnu.org/gitweb/?p=emacs.git;a=blob;f=lisp/progmodes/eglot.el#l1558
14871507 (unless (or (and (advice-member-p #'eglot-java--wrap-legacy-eglot--path-to-uri 'eglot--path-to-uri )
0 commit comments