joaotavora / eglot

A client for Language Server Protocol servers
GNU General Public License v3.0
2.26k stars 200 forks source link

Find definition won't work for external dependencies in Clojure #661

Closed Andre0991 closed 1 year ago

Andre0991 commented 3 years ago

Hi. I'm experimenting with using eglot with Clojure.

I've had no issues so far except that xref-find-definitions won't work for external dependencies. When I use it on some symbol that refers to an external lib, Emacs asks me if I want to create the directory:

Directory `/Users/andreperictavares/dev/peric/clj-new/src/clj_new/file:/Users/andreperictavares/.m2/repository/org/clojure/clojure/1.10.1/clojure-1.10.1.jar!/clojure/java/' does not exist! Create it? (y or n) y

The expected behaviour would be to open a buffer with the contents of the file in the jar (and manage it in the same project? Not sure).

Here's the an eglot log sample for this issue:

[client-request] (id:7) Sun Apr  4 21:44:24 2021:
(:jsonrpc "2.0" :id 7 :method "textDocument/definition" :params
          (:textDocument
           (:uri "file:///Users/andreperictavares/dev/nu/luna/src/luna/logic/error.clj")
           :position
           (:line 4 :character 23)))
[server-reply] (id:7) Sun Apr  4 21:44:25 2021:
(:jsonrpc "2.0" :id 7 :result
          (:uri "jar:file:////Users/andreperictavares/.m2/repository/prismatic/schema/1.1.9/schema-1.1.9.jar!/schema/core.clj" :range
                (:start
                 (:line 0 :character 4)
                 :end
                 (:line 0 :character 15))))

Steps to reproduce

  1. Download the clojure binary

  2. Download the native clojure-lsp binary in https://github.com/clojure-lsp/clojure-lsp/releases

  3. Configure eglot to use it

    (add-to-list 'eglot-server-programs '(clojure-mode . ("clojure-lsp")))
  4. Clone clj-new and install its dependencies.

    git clone https://github.com/seancorfield/clj-new.git
    clj
  5. Open the project in Emacs, go to clj-new/src/clj/generate/def.clj and use xref-find-definitions on some external lib like clojure.java.io (line 5 in this file).

Note: I'm using Doom Emacs. I think this does not affect anything in regards to this behaviour. Unfortunately, I don't have a clean Emacs for confirming this easily right now. If you suspect this is Doom specific, I can setup a barebones Emacs in a few days.

dannyfreeman commented 1 year ago

Posting a final resolution here. Installing my jarchive package resolves this issue: https://git.sr.ht/~dannyfreeman/jarchive It's available on ELPA. The eglot-extend-to-xref setting works with it as well.

@abcdw you may want to update your guix recipe with a newer commit. Thank you for sharing that here.

Andre0991 commented 1 year ago

Hi @dannyfreeman.

I see that there are no new messages in the Emacs bug tracker 1 – will Emacs get a patch too or is jarchive a permanent solution?

dannyfreeman commented 1 year ago

I see that there are no new messages in the Emacs bug tracker 1 – will Emacs get a patch too or is jarchive a permanent solution?

There is still discussion on that ticket in the 2022-11 archives. I think this is the latest message at the time of me writing this. The way the mailing list archives are displayed can be confusing.

The way I see it, jarchive is the solution for now, and it is on ELPA: https://elpa.gnu.org/packages/jarchive.html which is the most available place for it to be next to emacs core IMO.

Maybe down the line jarchive or something like it will make its way into Emacs. I think that would be nice and I'll keep discussing it. Until then ELPA is a nice proving ground for this functionality.

Andre0991 commented 1 year ago

Oh, indeed, I missed the newest messages.

Thank you so much for tackling this – I just installed jarchive and LSP+Clojure is 100% supported by Emacs now.

pesterhazy commented 1 year ago

FWIW, I just tried jarchive, and it doesn't fix the issue for me. I get an error like this:

Error in post-command-hook (#[0 "\303\304\301\242\305#\210\300\306!\205r\211q\210
?\205\307\310\311 \")\207" [#<buffer fs.cljc> (#0) eglot--managed-mode remove-hook post-command-hook nil buffer-live-p apply eglot--connect eglot--guess-contact] 4]): (file-missing "Setting current directory" "No such file or directory" "/Users/user/.m2/repository/babashka/fs/0.1.2/fs-0.1.2.jar::babashka/")