GNU bug report logs -
#61371
30.0.50; Adding support for jdt:// file scheme in eglot
Previous Next
Reported by: Theodor Thornhill <theo <at> thornhill.no>
Date: Wed, 8 Feb 2023 19:11:01 UTC
Severity: normal
Found in version 30.0.50
Done: Stefan Kangas <stefankangas <at> gmail.com>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 61371 in the body.
You can then email your comments to 61371 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
joaotavora <at> gmail.com, bug-gnu-emacs <at> gnu.org
:
bug#61371
; Package
emacs
.
(Wed, 08 Feb 2023 19:11:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Theodor Thornhill <theo <at> thornhill.no>
:
New bug report received and forwarded. Copy sent to
joaotavora <at> gmail.com, bug-gnu-emacs <at> gnu.org
.
(Wed, 08 Feb 2023 19:11:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
Hi!
When using Eglot along with Java there are some hacks that needs to be
made to make things functional. One of the more important things is to
add support for the jdt:// file scheme that is sent when you try to
go-to-definition on a system or third party lib.
For completeness sake - consider:
```
import java.util.Li|st;
public Foo {
void foo() {
List foo;
}
}
```
Cursor is now where | is, and if you try to M-., you won't get far.
This is because jdtls uses a convoluted way to retrieve this information
on demand, see [0]. Now the client has to query the language server an
additional time to get the actual content, load it somewhere, _then_
goto-def. I've created one such hack for my own config, but maybe this
is something that could be mainlined, even though eglot itself is trying
hard to be language agnostic? I'm not sure the code needs to live in
eglot, it could live some place other file-handlers live, if such a
place exists. Anyway, the code I use to fix this now looks like this:
```
(defclass eglot-java (eglot-lsp-server) ()
:documentation "A custom class for Java")
(cl-defmethod eglot-execute-command
((_server eglot-java) (_cmd (eql java.apply.workspaceEdit)) arguments)
"Eclipse JDT breaks spec and replies with edits as arguments."
(mapc #'eglot--apply-workspace-edit arguments))
(cl-defmethod eglot-initialization-options ((server eglot-java))
"Passes through required java initialization options"
`( :settings ,eglot-java-config
:workspaceFolders [,(eglot--path-to-uri (project-root (project-current)))]
:extendedClientCapabilities (:classFileContentsSupport t)))
(defun jdt-file-name-handler (operation &rest args)
"Support Eclipse jdtls `jdt://' uri scheme."
(let* ((uri (car args))
(cache-dir "/tmp/.eglot")
(source-file
(expand-file-name
(file-name-concat
cache-dir
(save-match-data
(when (string-match "jdt://contents/\\(.*?\\)/\\(.*\\)\.class\\?" uri)
(format "%s.java" (replace-regexp-in-string "/" "." (match-string 2 uri) t t))))))))
(unless (file-readable-p source-file)
(let ((content (jsonrpc-request (eglot-current-server) :java/classFileContents (list :uri uri)))
(metadata-file (format "%s.%s.metadata"
(file-name-directory source-file)
(file-name-base source-file))))
(unless (file-directory-p cache-dir) (make-directory cache-dir t))
(with-temp-file source-file (insert content))
(with-temp-file metadata-file (insert uri))))
source-file))
(add-to-list
'eglot-server-programs
`(java-mode . (eglot-java . ("jdtls"))))
(add-to-list
'eglot-server-programs
`(java-ts-mode . (eglot-java . ("jdtls"))))
```
As you can see, we need to query the server with
:java/classFileContents, and also register with the server to send it
with the :extendedClientCapabilities on initialization.
Is there a place this code could live? Maybe in the new java-ts-mode?
Theo
[0]: https://github.com/eclipse/eclipse.jdt.ls/issues/2322#issuecomment-1313953316
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#61371
; Package
emacs
.
(Thu, 09 Feb 2023 09:48:01 GMT)
Full text and
rfc822 format available.
Message #8 received at submit <at> debbugs.gnu.org (full text, mbox):
Theodor Thornhill via "Bug reports for GNU Emacs, the Swiss army knife
of text editors" <bug-gnu-emacs <at> gnu.org> writes:
> Hi!
Hi Theo,
> When using Eglot along with Java there are some hacks that needs to be
> made to make things functional. One of the more important things is to
> add support for the jdt:// file scheme that is sent when you try to
> go-to-definition on a system or third party lib.
>
> As you can see, we need to query the server with
> :java/classFileContents, and also register with the server to send it
> with the :extendedClientCapabilities on initialization.
>
> Is there a place this code could live? Maybe in the new java-ts-mode?
There is the jarchive package on GNU ELPA. Could this be used, perhaps extended?
> Theo
Best regards, Michael.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#61371
; Package
emacs
.
(Thu, 09 Feb 2023 09:48:02 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#61371
; Package
emacs
.
(Thu, 09 Feb 2023 10:43:02 GMT)
Full text and
rfc822 format available.
Message #14 received at submit <at> debbugs.gnu.org (full text, mbox):
Michael Albinus <michael.albinus <at> gmx.de> writes:
> Theodor Thornhill via "Bug reports for GNU Emacs, the Swiss army knife
> of text editors" <bug-gnu-emacs <at> gnu.org> writes:
>
>> Hi!
>
> Hi Theo,
>
>> When using Eglot along with Java there are some hacks that needs to be
>> made to make things functional. One of the more important things is to
>> add support for the jdt:// file scheme that is sent when you try to
>> go-to-definition on a system or third party lib.
>>
>> As you can see, we need to query the server with
>> :java/classFileContents, and also register with the server to send it
>> with the :extendedClientCapabilities on initialization.
>>
>> Is there a place this code could live? Maybe in the new java-ts-mode?
>
> There is the jarchive package on GNU ELPA. Could this be used, perhaps extended?
>
>> Theo
>
> Best regards, Michael.
Maybe! Don't know what it does, but I'll check it out - thanks!
Theo
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#61371
; Package
emacs
.
(Thu, 09 Feb 2023 10:43:02 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#61371
; Package
emacs
.
(Fri, 10 Feb 2023 20:38:01 GMT)
Full text and
rfc822 format available.
Message #20 received at submit <at> debbugs.gnu.org (full text, mbox):
Theodor Thornhill <theo <at> thornhill.no> writes:
> Michael Albinus <michael.albinus <at> gmx.de> writes:
>
>> Theodor Thornhill via "Bug reports for GNU Emacs, the Swiss army knife
>> of text editors" <bug-gnu-emacs <at> gnu.org> writes:
>>
>>> Hi!
>>
>> Hi Theo,
>>
>>> When using Eglot along with Java there are some hacks that needs to be
>>> made to make things functional. One of the more important things is to
>>> add support for the jdt:// file scheme that is sent when you try to
>>> go-to-definition on a system or third party lib.
>>>
>>> As you can see, we need to query the server with
>>> :java/classFileContents, and also register with the server to send it
>>> with the :extendedClientCapabilities on initialization.
>>>
>>> Is there a place this code could live? Maybe in the new java-ts-mode?
>>
>> There is the jarchive package on GNU ELPA. Could this be used, perhaps extended?
>>
>>> Theo
>>
>> Best regards, Michael.
>
> Maybe! Don't know what it does, but I'll check it out - thanks!
>
> Theo
JDT urls are outside the scope of jarchive. I would think of them less
as URLs and more as tokens to be decoded by the LSP server that provides
them. JDT urls are intended to be sent back to the LSP server using a
special extension method.
There is an issue open in the eglot-java repo to implement this but I
have been too busy to get around to it
https://github.com/yveszoundi/eglot-java/issues/6
Someone has responded there with some code similar to jarchive that will
parse the JDT urls and try to open them, but I wouldn't consider that a
permanent solution. JDT urls are not standardized and subject to change
by the JDT LSP maintainers.
--
Danny Freeman
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#61371
; Package
emacs
.
(Fri, 10 Feb 2023 20:38:02 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#61371
; Package
emacs
.
(Wed, 15 Feb 2023 18:07:01 GMT)
Full text and
rfc822 format available.
Message #26 received at submit <at> debbugs.gnu.org (full text, mbox):
Danny Freeman <danny <at> dfreeman.email> writes:
> Theodor Thornhill <theo <at> thornhill.no> writes:
>
>> Michael Albinus <michael.albinus <at> gmx.de> writes:
>>
>>> Theodor Thornhill via "Bug reports for GNU Emacs, the Swiss army knife
>>> of text editors" <bug-gnu-emacs <at> gnu.org> writes:
>>>
>>>> Hi!
>>>
>>> Hi Theo,
>>>
>>>> When using Eglot along with Java there are some hacks that needs to be
>>>> made to make things functional. One of the more important things is to
>>>> add support for the jdt:// file scheme that is sent when you try to
>>>> go-to-definition on a system or third party lib.
>>>>
>>>> As you can see, we need to query the server with
>>>> :java/classFileContents, and also register with the server to send it
>>>> with the :extendedClientCapabilities on initialization.
>>>>
>>>> Is there a place this code could live? Maybe in the new java-ts-mode?
>>>
>>> There is the jarchive package on GNU ELPA. Could this be used, perhaps extended?
>>>
>>>> Theo
>>>
>>> Best regards, Michael.
>>
>> Maybe! Don't know what it does, but I'll check it out - thanks!
>>
>> Theo
>
> JDT urls are outside the scope of jarchive. I would think of them less
> as URLs and more as tokens to be decoded by the LSP server that provides
> them. JDT urls are intended to be sent back to the LSP server using a
> special extension method.
>
> There is an issue open in the eglot-java repo to implement this but I
> have been too busy to get around to it
> https://github.com/yveszoundi/eglot-java/issues/6
>
> Someone has responded there with some code similar to jarchive that will
> parse the JDT urls and try to open them, but I wouldn't consider that a
> permanent solution. JDT urls are not standardized and subject to change
> by the JDT LSP maintainers.
I think this bug can be closed now, it was fixed in the eglot-java
package. See: https://github.com/yveszoundi/eglot-java/issues/6
Thank you,
--
Danny Freeman
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#61371
; Package
emacs
.
(Wed, 15 Feb 2023 18:07:01 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#61371
; Package
emacs
.
(Wed, 15 Feb 2023 18:11:01 GMT)
Full text and
rfc822 format available.
Message #32 received at submit <at> debbugs.gnu.org (full text, mbox):
Danny Freeman <danny <at> dfreeman.email> writes:
> Danny Freeman <danny <at> dfreeman.email> writes:
>
>> Theodor Thornhill <theo <at> thornhill.no> writes:
>>
>>> Michael Albinus <michael.albinus <at> gmx.de> writes:
>>>
>>>> Theodor Thornhill via "Bug reports for GNU Emacs, the Swiss army knife
>>>> of text editors" <bug-gnu-emacs <at> gnu.org> writes:
>>>>
>>>>> Hi!
>>>>
>>>> Hi Theo,
>>>>
>>>>> When using Eglot along with Java there are some hacks that needs to be
>>>>> made to make things functional. One of the more important things is to
>>>>> add support for the jdt:// file scheme that is sent when you try to
>>>>> go-to-definition on a system or third party lib.
>>>>>
>>>>> As you can see, we need to query the server with
>>>>> :java/classFileContents, and also register with the server to send it
>>>>> with the :extendedClientCapabilities on initialization.
>>>>>
>>>>> Is there a place this code could live? Maybe in the new java-ts-mode?
>>>>
>>>> There is the jarchive package on GNU ELPA. Could this be used, perhaps extended?
>>>>
>>>>> Theo
>>>>
>>>> Best regards, Michael.
>>>
>>> Maybe! Don't know what it does, but I'll check it out - thanks!
>>>
>>> Theo
>>
>> JDT urls are outside the scope of jarchive. I would think of them less
>> as URLs and more as tokens to be decoded by the LSP server that provides
>> them. JDT urls are intended to be sent back to the LSP server using a
>> special extension method.
>>
>> There is an issue open in the eglot-java repo to implement this but I
>> have been too busy to get around to it
>> https://github.com/yveszoundi/eglot-java/issues/6
>>
>> Someone has responded there with some code similar to jarchive that will
>> parse the JDT urls and try to open them, but I wouldn't consider that a
>> permanent solution. JDT urls are not standardized and subject to change
>> by the JDT LSP maintainers.
>
> I think this bug can be closed now, it was fixed in the eglot-java
> package. See: https://github.com/yveszoundi/eglot-java/issues/6
>
> Thank you,
> --
> Danny Freeman
I agree :-)
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#61371
; Package
emacs
.
(Wed, 15 Feb 2023 18:11:02 GMT)
Full text and
rfc822 format available.
Reply sent
to
Stefan Kangas <stefankangas <at> gmail.com>
:
You have taken responsibility.
(Wed, 06 Sep 2023 00:06:02 GMT)
Full text and
rfc822 format available.
Notification sent
to
Theodor Thornhill <theo <at> thornhill.no>
:
bug acknowledged by developer.
(Wed, 06 Sep 2023 00:06:02 GMT)
Full text and
rfc822 format available.
Message #40 received at 61371-done <at> debbugs.gnu.org (full text, mbox):
Theodor Thornhill <theo <at> thornhill.no> writes:
>> I think this bug can be closed now, it was fixed in the eglot-java
>> package. See: https://github.com/yveszoundi/eglot-java/issues/6
>>
>> Thank you,
>> --
>> Danny Freeman
>
> I agree :-)
Thanks, closed.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Wed, 04 Oct 2023 11:24:35 GMT)
Full text and
rfc822 format available.
This bug report was last modified 1 year and 219 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.