-
Notifications
You must be signed in to change notification settings - Fork 176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add source artifacts to classpath #64
Comments
I was thinking this would be a good idea. We would probably do it through We could add a task to download available source jars (with necessary It would be up to the user to prevent them from getting included in the |
Though looks like at least downloading the deps is trivial with maven, we |
@gtrak not sure what to take from that link. Source jars are mainly for java libraries (eg, clojure itself, etc). |
Ah, sorry, I didn't notice before now that you had already listed the |
I like the idea of automating this, but should point out that CLJ-1161 continues to be a stumbling block here. Essentially, the sources dep that will be most widely used (Clojure itself) has a bug that, until fixed, will cause the REPL on error on startup. Until this is addressed, we can't make automatically injecting this jar the default behavior -- it would break everybody's setups. |
Might it be possible to work around this by ensuring the sources jar is |
As long as the classloader in use respects that order, yes, that should work. For the sake of clarity: The error originates here when the resource |
If we automate it at runtime instead of lein-time, loading the dependencies |
@gtrak My thoughts exactly! :-) |
Looks like CLJ-1161 will be fixed in 1.8, so we should look into this again. |
FWIW, adding Clojure's sources for 1.8 works for me:
|
I'm sorry for arriving late to the party, but don't we already support jumping to source out-of-the-box? What's being requested by this issue? |
@Malabarba You can only jump to jars listed on the classpath. I opened this CIDER issue when I forgot about that, so I suspect others are confused too. |
@expez I understand the issue you had. It sort of looks like @hugoduncan was talking about sources for clojure artifacts. Which is strange to me, given that most clojure artifact already come with sources AFAIK. |
Not sure about Clojure artifacts, but this is definitely not the case with Java ones. There are always separate source artifacts for them. |
Is that this issue was is then? Trying to pull in java sources by default? |
I'm not a mindreader, but I believe so. I remember that when I was a Java dev Eclipse and Intellij would do this for maven projects - automatically fetch the sources, so their xref functionality would work for third-party code. This was pretty handy. |
Hi all, I'd really love to see this resolved. Pomegranate (now used by leiningen) hints at the intention of adding support for downloading source/javadoc jars (and adding them to the classpath). I've been using several java libs recently, and the lack of doc/jump to source has been causing me a lot of pain. So I've decided to hack together a proof of concept and, while it's far from perfect, it seems to work fine from the repl. What would it take to get something like it added to cider-nrepl? |
Make it generally useful and open a PR. Then be patient during a short period of intense nit-picking ;) Fwiw this is one of the bigger pain points for me too these days. |
@vise890 Still waiting for that PR. ;-) |
@bbatsov I'm afraid I think this is a bit beyond my powers to tackle. If anyone is willing to babysit me a bit, I'm happy to continue working on it though! I've made a leiningen plugin as a proof of concept: lein-pocketbook. As far as I can tell, it works, but it's pretty hacky. I haven't done much in terms of integrating it with emacs. From a clojure file, jumping to a java source works, but, once you're in java, you can't jump around anymore (I'm hoping this is reasonably easy to achieve). |
@vise890 jumping around in java could be left to another extension. Your pocketbook plugin works really well, with the caveats you mentioned considered. I was able to use them for jumping around stacktraces, even into the clojure source code: it was really magical! |
@SevereOverfl0w I'm glad you enjoyed it! I'm pretty sure the jumping around in Java just needs support on the Emacs side. Using Anyway. Do people want a PR to this repo? I can cook something up.. |
@vise890 If you just enable Of course, |
I think this is still a useful suggestion and would be great to have an easy way how to add source artifacts for all java deps on the classpath. |
Mulling over this problem, it seems like updating the dependencies coordinates before lein does dependency resolution is the simplest solution. However, you can't just specify extra coords for the I tried specifying
I'm hoping someone might have thoughts on how to automatically handle this case, so that user intervention can be minimized. I'm also very curious how Eclipse and Cursive handle this problem. Perhaps they just try to resolve these deps every time 🤔 |
It doesn't need to be out of the box. There could be a yes/no prompt or a variable to add the source jars if needed. If some people will want to save time on this, let they do it. Also java disassembler would be handy too, but it would require more work. And jump to java source doesn't work for me even if I include them this way: #64 (comment). An issue related to this is closed: clojure-emacs/cider#1666. I guess nobody does this kind of development here. It's probably either ClojureScript or purity.
The first thing that popped up after installing IntelliJ an putting the deps is whether I'd like that Gradle wrapper would decompile the JAR. Here you go. |
@Invertisment I essentially gave up and waiting if/until cider gets better support. I also keep InteliJ IDEA opened and if I have to look at Java class I just open it there. |
Those looking for browsing java sources, disassembler, debugging java source might use: https://github.com/emacs-lsp/dap-mode/wiki/Clojure:-debugging-and-introspecting-Java-Code |
@Invertisment @jumarko I understand your frustration, but you have to understand that this mostly depends on the tool used to start the REPL. To my knowledge there's no easy way to tell Lein/Boot/tools.deps to just fetch every source jar that exists. If we could do this that'd be the best solution. We can explore hot loading source jars, but we still can't know whether some tool publishes those or not. @futuro Highlights the problem here very well:
|
@yyoncho thanks for the tip!
Then created a new sample lein project and generated pom.xml
Then opened project.clj in spacemacs and run
The I'm also interested in how do you combine this with Cider. |
#64 (comment), I used IntelliJ and I inspected all bits of a library that I wanted. This works. Maybe it's the way to do it. At least for now. |
@jumarko - I think that you pretty much did it - the issue that you had is that you tried to perform xref-find-appropos in buffer that is not managed by the java language server. There are 2 solutions:
I use cider+jdtls in clojure+java projects and from time to time I use the debugger since I interact from clojure with our java codebase |
@yyoncho It'd be nice if you submitted some instructions to CIDER's docs for using it together with LSP for Java. I think this topic comes up every now and then and it'd be nice if we just had some section in the docs where we could point people to. |
Sure. I will try to prepare something when I am in a mood for writing docs. |
Hi, I've implemented a Lein plugin that cleanly fetches all available Java sources/javadocs: https://github.com/threatgrid/clj-experiments/tree/master/resolve-java-sources-and-javadocs It's more complete than previous attempts like lein-pocketbook, lein-ubersource. It certainly works without issue in large, Java-heavy projects even in presence of advanced features like :managed-dependencies, and plugins like lein-sub, lein-monolith. Feel free to give it a spin and let me know if there's anything to tweak for CIDER-friendliness :) Happy New Year! |
Well, I'm guessing if it fetches them and places them on the classpath everything should work just fine in CIDER. I'll test the plugin when I can. |
@vemv Any plans to move this to a separate project repo? I'm guessing this way more people will be inclined to give it a go. :-) |
@vemv the plugin fails with EDIT: I tried with leiningen 2.9.3 before and now, after an upgrade, with lein 2.9.5 - the issue persists. |
Thanks! Yes I use JDK8 (and lein @ latest) so something might have slipped. I'll setup CI in the project sometime in the week and run it against a matrix ideally. ...Over the last couple days I've added https://github.com/threatgrid/clj-experiments/tree/master/resolve-java-sources-and-javadocs/integration-testing (25 real-world, large/significant projects to test against) so my confidence around the plugin has increased greatly. Probably in a matter of days any remaining issues will be ironed out. |
@vemv do you have any update on this? I'm eager to try the plugin again once the issue is fixed. |
Issue is fixed and CI'd. On top of that I've revamped the README. So after quite a few iterations I consider the plugin ready for prime-time - I was simply waiting for some close people to leave feedback. After that last round of feedback I'll extract the project to its own git repo :) |
Now that enrich-classpath (https://github.com/clojure-emacs/enrich-classpath/) is quite mature, I think we can finally close this ticket. |
Is there interest in making the lein plugin automatically add source jars to the classpath?
One possibility is to add source coordinates to the
:dependencies
, but since most artifacts in the clojure world don't have source jars, that could be a problem. The second option is to add locally available source jars (and rely onlein pom; mvn dependency:sources;
to download them).Ritz contained code to add locally available source jars: https://github.com/pallet/ritz/blob/develop/lein-ritz/src/lein_ritz/add_sources.clj
The ritz code added the artifacts via a hooke, which is probably not the nicest way of doing it, as the source artifacts could end up in an uberjar.
The text was updated successfully, but these errors were encountered: