Olical / conjure

Interactive evaluation for Neovim (Clojure, Fennel, Janet, Racket, Hy, MIT Scheme, Guile, Python and more!)
https://conjure.oli.me.uk
The Unlicense
1.74k stars 109 forks source link

Add viewing of Java source to the Clojure client #142

Open Akeboshiwind opened 3 years ago

Akeboshiwind commented 3 years ago

When I try to go to the definition of a java class from clojure I get:

; def (word): JsonSchema
; Can't open source, it's Java
; com/github/fge/jsonschema/main/JsonSchema.html

Would it be possible to get support for this? Or is it not feasable?

I couldn't find another issue referencing this feature or anything in the docs so I don't know your view on it.

Olical commented 3 years ago

The only thing I could potentially do is open your web browser to a URL that might have the docs in it. There's no way I can open the Java source as far as I know though, someone else may know of a way, if they do, I'm all ears.

As far as I know though, you probably don't have the Java source on your disk, so I can't open it, but I can sometimes get a URL suffix to some documentation (not sure about the host though).

Akeboshiwind commented 3 years ago

But if I'm running a repl, won't I have the code downloaded in a jar somewhere?

I suppose it could be obfuscated?

Olical commented 3 years ago

Nope, you probably just have the .class bytecode, there's no guarantee you'll have the original source. In Clojure land we have access to the Clojure a LOT more often I think? I was never a Java programmer so I'm unsure about this area really, it'd be great to have a more Java-y JVM expert weigh in on if it's possible to find this sort of information consistently or not.

The fact that CIDER doesn't know or return this information doesn't give me too much hope.

Akeboshiwind commented 3 years ago

That's unfortunate, although something must be possible seeing as other editors like intelliJ do it 🤔.

This answer seems to think that IntelliJ tries to use Maven to download the sources automatically.

And this answer seems to be a (leiningen specific) solution, with more info here.

I would guess that it's possible a lot of cases to just download the sources from maven (if the user has that installed) using a similar method to above. How to link that to an "get definition" request is beyond me unfortunately 😅.

philomates commented 1 year ago

wanted to chime in that clojure-lsp supports this https://github.com/clojure-lsp/clojure-lsp/issues/762, so perhaps us clojure users can defer to that tool instead of implementing it here

Olical commented 1 year ago

I am hugely in favour of leaning on LSP for this, it's great at this aspect. Conjure is still trying to just be an eval and response display system, LSP will be much better for things that require static analysis like this. Might just need to update some documentation to point people at it.

Olical commented 1 year ago

Thanks for sharing @philomates!

vemv commented 10 months ago

Starting from CIDER 1.8.0, first-class Java support is a reality in cider-nrepl.

Here's a basic overview: https://docs.cider.mx/cider/config/basic_config.html#use-enrich-classpath

The basic pattern would be to:

Java responses, besides from the usual :doc attributes, include :doc-fragments attributes. Those are documented here.

With those fragments, you can locally render HTML to vim-native info (e.g. stuff in bold, italic, etc), as shown here:

https://github.com/Olical/conjure/assets/1162994/59ab8dde-ba3d-41c6-9d60-857e4ddfa403

Let me know how that sounds. I'd be happy to collaborate.

vemv commented 10 months ago

Regarding clojure-lsp as an alternative, as a cider-nrepl maintainer I'm biased, but my impression is that clojure-lsp has not completed a full offering yet.

(Which is not to say it can't, of course, and I'd be happy if they used some of our bits - it's not a competition)

Olical commented 10 months ago

Ohh this looks fantastic! So I see how to opt in with CIDER in emacs, what does it mean in nREPL terms? Do we just send an op on connection or is it a flag you set when looking up information for a symbol?

vemv commented 10 months ago

Happy to hear!

It's transparent - the nrepl messages do not have to include extra keys or such.

But cider-nrepl has to be started via enrich-classpath. It's essentially wrapper that adds the right resources at the tail of the classpath.

Neither Lein or t.deps offer such a fine-grained API (i.e. add items to the would-be classpath at a specific position). For that and other reasons one has to use that special program instead of bare Lein / t.deps.

(there isn't an equivalent approach - I've know of them, they won't work)

Olical commented 10 months ago

I see, that's interesting. Thanks for bringing this to my attention and teaching me about it! So is there anything we can do from the Conjure side to make this nice? Is it just a documentation thing or maybe something to add to https://github.com/clojure-vim/vim-jack-in?

vemv commented 10 months ago

It would certainly be nice if you could try it out, for verifying that it can comfortably work for Conjure users!

I reckon that https://github.com/clojure-vim/vim-jack-in would be the best place to add it yes.

The other thing that complete clients should do is rendering :doc-fragments into vim-readable strings.

https://docs.cider.mx/cider-nrepl/nrepl-api/ops.html#info

In Emacs land we have a standard library named shr that renders HTML into emacs "propertized strings" i.e. strings with metadata indicating syntax highlighting.

I'd assume that vim has a similar facility?

If you need an abundant corpus of :doc-fragments examples, you can clone https://github.com/clojure-emacs/cider and run:

        cd dev; ../clojure.sh clojure -M:gen; cd -
        # a few files other files like this one will be generated:
        cat test/File.edn

Sneak peek:

{:doc-fragments
 [{:type "text", :content "Converts this abstract pathname into a "}
  {:type "html", :content "<pre>file:</pre> "}
  {:type "text",
   :content
   " URL.  The\nexact form of the URL is system-dependent.  If it can be determined that\nthe file denoted by this abstract pathname is a directory, then the\nresulting URL will end with a slash."}],
 :doc-first-sentence-fragments
 [{:type "text", :content "Converts this abstract pathname into a "}
  {:type "html", :content "<pre>file:</pre> "}
  {:type "text", :content " URL."}],
 :doc-block-tags-fragments
 [{:type "text", :content "\n"}
  {:type "html", :content "<i>Returns</i>:&nbsp;"}
  {:type "text",
   :content "A URL object representing the equivalent file URL\n\n"}
  {:type "html",
   :content
   "<i>Throws</i>:&nbsp;<pre>MalformedURLException</pre>:&nbsp;"}
  {:type "text", :content "If the path cannot be parsed as a URL"}]}

Cheers - V

Olical commented 10 months ago

Gotcha, that should be everything I (or anyone else) should need to get going. Going to do a little more work on clojure-dap but will try to prioritise this when I'm deep in Conjure-land again soon. I'd imagine the basics should work just fine, but we need to integrate the :doc-fragments for sure.

Thank you very much!

On Wed, 1 Nov 2023 at 20:20, vemv @.***> wrote:

It would certainly be nice if you could try it out, for verifying that it can comfortably work for Conjure users!

I reckon that https://github.com/clojure-vim/vim-jack-in would be the best place to add it yes.

The other thing that complete clients should do is rendering :doc-fragments into vim-readable strings.

https://docs.cider.mx/cider-nrepl/nrepl-api/ops.html#info

In Emacs land we have a standard library named shr that renders HTML into emacs "propertized strings" i.e. strings with metadata indicating syntax highlighting.

I'd assume that vim has a similar facility?

If you need an abundant corpus of :doc-fragments examples, you can clone https://github.com/clojure-emacs/cider and run:

    cd dev; ../clojure.sh clojure -M:gen; cd -
    # a few files other files like this one will be generated:
    cat test/File.edn

Sneak peek:

{:doc-fragments [{:type "text", :content "Converts this abstract pathname into a "} {:type "html", :content "

file:
"} {:type "text", :content " URL. The\nexact form of the URL is system-dependent. If it can be determined that\nthe file denoted by this abstract pathname is a directory, then the\nresulting URL will end with a slash."}], :doc-first-sentence-fragments [{:type "text", :content "Converts this abstract pathname into a "} {:type "html", :content "
file:
"} {:type "text", :content " URL."}], :doc-block-tags-fragments [{:type "text", :content "\n"} {:type "html", :content "Returns: "} {:type "text", :content "A URL object representing the equivalent file URL\n\n"} {:type "html", :content "Throws
MalformedURLException
: "} {:type "text", :content "If the path cannot be parsed as a URL"}]}

Cheers - V

— Reply to this email directly, view it on GitHub https://github.com/Olical/conjure/issues/142#issuecomment-1789618034, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACM6XPM4N4QWW7VPFPNHMTYCKVG5AVCNFSM4UL2NBS2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCNZYHE3DCOBQGM2A . You are receiving this because you commented.Message ID: @.***>