Skip to content
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

Use revamped enrich-classpath plugin #3364

Merged
merged 35 commits into from
Aug 26, 2023
Merged

Use revamped enrich-classpath plugin #3364

merged 35 commits into from
Aug 26, 2023

Conversation

vemv
Copy link
Member

@vemv vemv commented Jul 5, 2023

  • Bump enrich-classpath
  • Introduce clojure.sh script for Clojure CLI usage
  • Use a reworked middleware for Leiningen integration
;;  Startup: java -cp /Users/vemv/how-to-ns/how-to-ns/test:/Users/vemv/how-to-ns/how-to-ns/src:/Users/vemv/how-to-ns/how-to-ns/dev-resources:/Users/vemv/how-to-ns/how-to-ns/resources:/Users/vemv/how-to-ns/how-to-ns/target/classes:/Users/vemv/.m2/repository/org/clojure/core.specs.alpha/0.1.24/core.specs.alpha-0.1.24.jar:/Users/vemv/.m2/repository/org/clojure/spec.alpha/0.1.143/spec.alpha-0.1.143.jar:/Users/vemv/.m2/repository/clojure-complete/clojure-complete/0.2.5/clojure-complete-0.2.5.jar:/Users/vemv/.m2/repository/com/googlecode/java-diff-utils/diffutils/1.2.1/diffutils-1.2.1.jar:/Users/vemv/.m2/repository/org/clojure/test.check/0.10.0-alpha3/test.check-0.10.0-alpha3.jar:/Users/vemv/.m2/repository/org/clojure/clojure/1.9.0/clojure-1.9.0.jar:/Users/vemv/.m2/repository/refactor-nrepl/refactor-nrepl/3.7.0/refactor-nrepl-3.7.0.jar:/Users/vemv/.m2/repository/nrepl/nrepl/1.0.0/nrepl-1.0.0.jar:/Users/vemv/.m2/repository/cider/cider-nrepl/0.31.0/cider-nrepl-0.31.0.jar:/Users/vemv/.mx.cider/enrich-classpath/1601/2516905847/1773208541.jar:/Users/vemv/.mx.cider/unzipped-jdk-sources/1601:/Library/Java/JavaVirtualMachines/adoptopenjdk-16.jdk/Contents/Home/lib/src.zip -XX:-OmitStackTraceInFastThrow -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -Dclojure.compile.path=/Users/vemv/how-to-ns/how-to-ns/target/classes clojure.main -m nrepl.cmdline --middleware "[refactor-nrepl.middleware/wrap-refactor refactor-nrepl.middleware/wrap-refactor cider.nrepl/wrap-apropos cider.nrepl/wrap-classpath cider.nrepl/wrap-clojuredocs cider.nrepl/wrap-complete cider.nrepl/wrap-content-type cider.nrepl/wrap-debug cider.nrepl/wrap-enlighten cider.nrepl/wrap-format cider.nrepl/wrap-info cider.nrepl/wrap-inspect cider.nrepl/wrap-macroexpand cider.nrepl/wrap-ns cider.nrepl/wrap-out cider.nrepl/wrap-slurp cider.nrepl/wrap-profile cider.nrepl/wrap-refresh cider.nrepl/wrap-resource cider.nrepl/wrap-spec cider.nrepl/wrap-stacktrace cider.nrepl/wrap-test cider.nrepl/wrap-trace cider.nrepl/wrap-tracker cider.nrepl/wrap-undef cider.nrepl/wrap-version cider.nrepl/wrap-xref refactor-nrepl.middleware/wrap-refactor cider.nrepl/wrap-apropos cider.nrepl/wrap-classpath cider.nrepl/wrap-clojuredocs cider.nrepl/wrap-complete cider.nrepl/wrap-content-type cider.nrepl/wrap-debug cider.nrepl/wrap-enlighten cider.nrepl/wrap-format cider.nrepl/wrap-info cider.nrepl/wrap-inspect cider.nrepl/wrap-macroexpand cider.nrepl/wrap-ns cider.nrepl/wrap-out cider.nrepl/wrap-slurp cider.nrepl/wrap-profile cider.nrepl/wrap-refresh cider.nrepl/wrap-resource cider.nrepl/wrap-spec cider.nrepl/wrap-stacktrace cider.nrepl/wrap-test cider.nrepl/wrap-trace cider.nrepl/wrap-tracker cider.nrepl/wrap-undef cider.nrepl/wrap-version cider.nrepl/wrap-xref refactor-nrepl.middleware/wrap-refactor cider.nrepl/wrap-apropos cider.nrepl/wrap-classpath cider.nrepl/wrap-clojuredocs cider.nrepl/wrap-complete cider.nrepl/wrap-content-type cider.nrepl/wrap-debug cider.nrepl/wrap-enlighten cider.nrepl/wrap-format cider.nrepl/wrap-info cider.nrepl/wrap-inspect cider.nrepl/wrap-macroexpand cider.nrepl/wrap-ns cider.nrepl/wrap-out cider.nrepl/wrap-slurp cider.nrepl/wrap-profile cider.nrepl/wrap-refresh cider.nrepl/wrap-resource cider.nrepl/wrap-spec cider.nrepl/wrap-stacktrace cider.nrepl/wrap-test cider.nrepl/wrap-trace cider.nrepl/wrap-tracker cider.nrepl/wrap-undef cider.nrepl/wrap-version cider.nrepl/wrap-xref]"

The /Users/vemv/.mx.cider/enrich-classpath/1601/2516905847/1773208541.jar:/Users/vemv/.mx.cider/unzipped-jdk-sources/1601:/Library/Java/JavaVirtualMachines/adoptopenjdk-16.jdk/Contents/Home/lib/src.zip part indicates what Enrich is adding.

Because those artifacts are appended at the tail of the classpath (as guaranteed by using a bespoke java command, as opposed to delegating classpath construction to Lein), they won't give problems.

Under this code path, Lein users now run just one JVM!

cider.el Outdated Show resolved Hide resolved
@bbatsov
Copy link
Member

bbatsov commented Jul 5, 2023

Might be good to also mention some of things you've written in the description of the PR in the docs.

@vemv vemv marked this pull request as ready for review July 5, 2023 15:05
@vemv vemv requested a review from bbatsov July 5, 2023 15:05
@vemv
Copy link
Member Author

vemv commented Jul 5, 2023

Ready. I've kept QAing this and adding resilience.

Doc got some updates but I'm also leaving a bit minimalistic.

A follow-up PR will add Clojure CLI compat - that work is done already.

@vemv vemv marked this pull request as draft July 6, 2023 11:59
@vemv
Copy link
Member Author

vemv commented Jul 6, 2023

Moving this to draft again because I'll want to also QA this for figwheel repls.

(I had for shadow-cljs repls only, as far as cljs is concerned)

Otherwise the PR is reviewable.


For Lein users, it has the additional benefit of running a single JVM, instead of the two JVMs that Lein programs typically involve.

`enrich-classpath` is still in beta and defaults to being disabled.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to slap a NOTE: before this.


You can enable it by setting the `cider-enrich-classpath` defcustom to `t`.

With it enable, `cider-jack-in` will activate enrich-classpath, given the following conditions:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enabled


* You are on macOS/Linux
* You are on Leiningen
* You are launching a vanilla JVM repl (and not a cljs, or clj+cljs one)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you launch a mixed REPL? In general I find the 3rd bullet point a bit confusing

@@ -22,7 +22,7 @@ commands:
name: Install Emacs latest
command: |
echo "HOMEBREW_NO_AUTO_UPDATE=1" >> $BASH_ENV
brew install homebrew/cask/emacs
brew install homebrew/cask/emacs || brew install homebrew/cask/emacs || brew install homebrew/cask/emacs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to retry this? I haven't noticed it failing often.

cider.el Outdated
@@ -855,7 +855,7 @@ middleware and dependencies."
(cider-jack-in-normalized-lein-plugins)
(if cider-enrich-classpath
(append cider-jack-in-lein-middlewares
'("cider.enrich-classpath/middleware"))
'("cider.enrich-classpath.plugin-v2/middleware"))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self: avoid this when the intended repl type is not 'clj.

Not that it's problematic, but seems a sensible way to start.

Copy link
Member Author

@vemv vemv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Mostly a note to self)

For Lein users, it would be important to evaluate the Lein :init code.

Perhaps CIDER can make this happen, e.g. we determine the final :init value (after applying profiles, plugins, etc), persist it or store it in memory, and then we evaluate CIDER-side it as the first thing that happens after a successful (and enriched, i.e. no fallback was applied) connection.

edit: maybe it simply can be a clojure.main arg here https://github.com/clojure-emacs/enrich-classpath/blob/585f80f12b610b2438492e7523582796c5c1ee03/lein-plugin/src/cider/enrich_classpath/plugin_v2.clj#L90

@vemv
Copy link
Member Author

vemv commented Aug 14, 2023

@bbatsov: this is starting to look great, however I plan to merge it after the 1.8.0 release to contain risks.

This way, users can choose to use 1.8.0 or master.

Copy link
Member Author

@vemv vemv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been refining the Clojure CLI integration (both in https://github.com/clojure-emacs/enrich-classpath itself and the clojure.sh wrapper script, now included in the PR).

I'm more confident about it now and have successfully tried with CIDER in large projects.

cider.el Outdated
(lambda ()
(when (symbol-file 'cider-jack-in-command)
(concat (file-name-directory (symbol-file 'cider-jack-in-command))
"clojure.sh")))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I intend to ship the clojure.sh wrapper into the artifact to be unzipped into ~/.emacs.d/elpa/cider[...]

symbol-file would help me find that.

SGTY? @bbatsov

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bundled with what - CIDER or enrich?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see it's bundled with CIDER. I'm not sure what symbol-file does, but there's package-user-dir or something like this that specifies the path to ELPA, so it seems you can use it instead.

Copy link
Contributor

@iarenaza iarenaza Aug 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just want to mention that package-user-dir seems to only be used by package.el. So if you are using something like straigth.el to manage your Emacs packages (like I do), my CIDER files won't be in the directory contained in package-user-dir. E.g., package-user-dir in my case contains "~/.emacs.d/elpa", but my packages are at ~/.emacs.d/straight-emacs-29/straight/build/ (for Emacs 29.1; I keep a separate package directory per Emacs version).

(symbol-file 'cider-jack-in-command) on the other hand gives me "/home/iarenaza/.emacs.d/straight-emacs-29/straight/build/cider/cider.elc" which seems about right 😄

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with @iarenaza to not use package-user-dir (personally I use borg as package manager).

I think using locate-library is pretty common and I saw it a few times where the packages needs to find the sources for compiling a native module like vterm or jinx.

For cider this would be something like:
(file-name-directory (locate-library "cider.el" t))

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, I keep forgetting not everyone is using ELPA. :-) I agree that locate-library is probably the best approach (mostly because it's obvious what you're trying to do with it).

@vemv vemv marked this pull request as ready for review August 22, 2023 23:43
@bbatsov
Copy link
Member

bbatsov commented Aug 23, 2023

Seems the windows integration tests are failing all the time now. Perhaps there's some real problem with them?

cider.el Outdated
"clojure.sh")))
"The location of enrich-classpath's clojure.sh wrapper script."
:package-version '(cider . "1.8.0")
:type 'function)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems weird that something that looks like a filename should be a function IMO.

cider.el Outdated
('clojure-cli (cider--resolve-command cider-clojure-cli-command))
('clojure-cli (if (and cider-enrich-classpath
(not (eq system-type 'windows-nt))
(executable-find (funcall cider-enrich-classpath-clojure-cli-script)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it also looks that this is a function. Perhaps you can just have a function that just expands properly whatever is in the defcustom (e.g. tries to find whatever was specified by the user and falls back to clojure.sh)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tentatively left this as a simple defun, and with a clearer name. Users would rarely have the need to point elsewhere for the script.

One can always edit the script inline, create a symlink, etc.

clojure.sh Show resolved Hide resolved
@vemv
Copy link
Member Author

vemv commented Aug 23, 2023

Seems the windows integration tests are failing all the time now. Perhaps there's some real problem with them?

Probably not. In Circle they're passing as usual, while GHA's jobs have been more flaky.

Maybe their Win servers were having a slow day.

@bbatsov
Copy link
Member

bbatsov commented Aug 26, 2023

Looks OK to me in the current state. I guess we'll squash this down to 1 commit, right?

@vemv
Copy link
Member Author

vemv commented Aug 26, 2023

Thanks!

I'm fixing something in enrich itself, will squash afterwards.

@vemv vemv merged commit d823bd1 into master Aug 26, 2023
26 checks passed
@vemv vemv deleted the enrich-plugin-v2 branch August 26, 2023 21:40
vemv added a commit to vemv/melpa that referenced this pull request Aug 27, 2023
@vemv
Copy link
Member Author

vemv commented Aug 27, 2023

clojure.sh will be melpa-distributed after melpa/melpa#8706 is in

@vemv
Copy link
Member Author

vemv commented Aug 28, 2023

clojure.sh will be melpa-distributed after melpa/melpa#8706 is in

It now is in. clojure.sh works when distributed by melpa and located CIDER-side.

@iarenaza, @dakra, given that you had the generosity to review, you might also want to give it a spin?

Doc lives at https://docs.cider.mx/cider/config/basic_config.html#use-enrich-classpath

Cheers - V

@iarenaza
Copy link
Contributor

Am I right in assuming that I need master for that to work? (just to make sure, as I'm running CIDER 1.7.0 right now).

@bbatsov
Copy link
Member

bbatsov commented Aug 29, 2023

@iarenaza Yeah, you need to be on master.

@vemv
Copy link
Member Author

vemv commented Aug 29, 2023

Be advised, I already got quite some feedback, nothing critical, but enough for not bothering more people (yet).

Either way, CIDER 1.7.0 -> 1.8.0 has lots of reliability improvements (changelog), so feedback for all those other areas would be most useful.

github-actions bot pushed a commit to akirak/melpa that referenced this pull request Sep 24, 2023
akirak pushed a commit to akirak/melpa that referenced this pull request Sep 24, 2023
github-actions bot pushed a commit to akirak/melpa that referenced this pull request Nov 2, 2023
github-actions bot pushed a commit to akirak/melpa that referenced this pull request Nov 2, 2023
github-actions bot pushed a commit to akirak/melpa that referenced this pull request Nov 2, 2023
github-actions bot pushed a commit to akirak/melpa that referenced this pull request Nov 2, 2023
github-actions bot pushed a commit to akirak/melpa that referenced this pull request Nov 2, 2023
github-actions bot pushed a commit to akirak/melpa that referenced this pull request Nov 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants