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

Allow connecting to nbb via connect-clj (#3061) #3272

Merged
merged 4 commits into from
Dec 3, 2022

Conversation

benjamin-asdf
Copy link
Contributor

@benjamin-asdf benjamin-asdf commented Dec 1, 2022

This is for nbb, scittle, joyride.
Better support for "pain" repls, support "cljs" without setup.

we want to

  1. connect with a plain client

  2. make any assumptions explicit

  3. connect cljs buffers with those plain repls

  4. Check for cider middleware being present, before using it (already being done)

  5. Check for cider-library-present-p, before relying on anything in the runtime

  6. Make assumptions about the runtime explicit

My suggestion is =cider-connection-capabilities=.
Currently, there was an implicit assumption about the compilation error format.

=cider-connection-capabilities=
Is my suggestion for 2.

=cider-repls=
Now returns cljs, if the repl capabilities include 'cljs This way we can make a "plain" clj client, upgrade on connect with cljs capability and have it be connected in cljs buffers.

This is more a concession / workaround the current repl-type setup.

In the future we might get rid of repl-type?
The only reason we have it, and creaating issue 3., is because we want to be ergonomic about which buffer to use inside a given source buffer.
I found that I am able to juggle multiple clients by swapping to the buffer I want, thereby setting it active.

This can be a user command. Can also make a modeline element that swaps between clj/cljs like calva.

slack discussion:
https://clojurians.slack.com/archives/C04CAKAGADU


This pr also includes a few less consequential fixes that made nbb, scittle and joyride work.
(there was an error in the default repl init form "no such var, repl requires" )

  • The commits are consistent with our contribution guideglines

  • You've added tests (if possible) to cover your change(s)

  • All tests are passing (eldev test)

  • All code passes the linter (eldev lint) which is based on elisp-lint and includes

    • byte-compilation,
      checkdoc,
      check-declare,
      packaging metadata, indentation, and trailing whitespace checks.

      I ran it but it is currently cluttered. I am still 90% certain I
      fixed the ones I would be introducing.

      If some warnings are ignored, please explain how to ignore.

  • You've updated the changelog (if adding/changing user-visible functionality)

  • You've updated the user manual (if adding/changing user-visible functionality)

@benjamin-asdf
Copy link
Contributor Author

benjamin-asdf commented Dec 1, 2022

Don't merge I need to figure out a better way for checking "cljs present".
-> ok good now

This is for nbb, scittle, joyride.
Better support for "pain" repls, support "cljs" without setup.

we want to

1. connect with a plain client
2. make any assumptions explicit
3. connect cljs buffers with those plain repls

1. Check for cider middleware being present, before using it
(already being done)
2. Check for cider-library-present-p, before relying on anything in
the runtime
3. Make assumptions about the runtime explicit
My suggestion is =cider-connection-capabilities=.
Currently, there was an implicit assumption about the compilation
error format.

=cider-connection-capabilities=
Is my suggestion for 2.

=cider-repls=
Now returns cljs, if the repl capabilities include 'cljs
This way we can make a "plain" clj client, upgrade on connect with
cljs capability and have it be connected in cljs buffers.

This is more a concession / workaround the current repl-type setup.

In the future we might get rid of repl-type?
The only reason we have it, and creaating issue 3., is because we want
to be ergonomic about which buffer to use inside a given source
buffer.
I found that I am able to juggle multiple clients by swapping to the
buffer I want, thereby setting it active.

This can be a user command. Can also make a modeline element that
swaps between clj/cljs like calva.

slack discussion:
https://clojurians.slack.com/archives/C04CAKAGADU

Format docstring

Fix cljs check
@bbatsov
Copy link
Member

bbatsov commented Dec 1, 2022

Don't merge I need to figure out a better way for checking "cljs present".

You can also mark PRs as "Draft" to make this visually clear, btw.

(if (cider-nrepl-op-supported-p "stacktrace")
(cider-default-err-op-handler)
(cider-default-err-eval-handler)))
(cond ((cider-nrepl-op-supported-p "stacktrace") (cider-default-err-op-handler))
Copy link
Member

Choose a reason for hiding this comment

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

Seems to me this change won't result in anything different.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, actually the similar names confused me. Now I see the last branch is different.

(defvar-local cider-connection-capabilities '()
"A list of some of the capabilites of this connection buffer.
Aka what assumptions we make about the runtime.
This is more genaral than
Copy link
Member

Choose a reason for hiding this comment

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

general

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

`cider-nrepl-op-supported-p' and `cider-library-present-p'.
But does not need to replace them.")

(defun cider-connection-has-capability-p (capability)
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this operate only on the current buffer? Probably it'd be nice to be able to pass a connection to it explicitly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@@ -303,6 +303,7 @@ focused."
(let* ((font-value (if cider-result-use-clojure-font-lock
(cider-font-lock-as-clojure value)
value))
(font-value (string-trim-right font-value))
Copy link
Member

Choose a reason for hiding this comment

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

I don't quite understand the purpose of this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nbb errors always had a trailing newline and the I think the visual of the overlays is better without the newline.

Copy link
Member

Choose a reason for hiding this comment

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

Got it. This name font-value confused me, as that's just value (which is potentially using font-locking). I was wondering why someone would be trimming the font-value. :D

@@ -778,9 +778,13 @@ Generally you should not disable this unless you run into some faulty check."
:safe #'booleanp
:package-version '(cider . "0.17.0"))

(defun cider-clojurescript-present-p ()
"Return non nil when ClojureScript is present."
(nrepl-dict-get (cider-sync-tooling-eval "cljs.core/demunge") "value"))
Copy link
Member

@bbatsov bbatsov Dec 1, 2022

Choose a reason for hiding this comment

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

what's the advantage of this over the previous check?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#3255 Basically (require 'cljs.core) did not work for nbb.

@ikappaki ikappaki mentioned this pull request Dec 2, 2022
6 tasks
@@ -153,7 +153,8 @@ you'd like to use the default Emacs behavior use
(make-obsolete-variable 'cider-repl-print-level 'cider-print-options "0.21")

(defvar cider-repl-require-repl-utils-code
'((clj . "(clojure.core/apply clojure.core/require clojure.main/repl-requires)")
'((clj . "(when-let [requires (resolve 'clojure.main/repl-requires)]
Copy link
Member

Choose a reason for hiding this comment

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

You'll have to explain me the need for this change.

Copy link
Contributor Author

@benjamin-asdf benjamin-asdf Dec 3, 2022

Choose a reason for hiding this comment

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

When you currently connect to joyride it throws "cannot resolve symbol repl-requires". It was the same for an earlier version of nbb I basiclly want to make the clj connection as un-assuming as possible.

Copy link
Member

Choose a reason for hiding this comment

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

Might be good to mention such things in comments, so those things are clearer someone doesn't optimize this away. As @ikappaki mentioned in #3274 we don't really have integration tests, so it's not hard to imagine someone doing a change that would break this again for other runtimes.

Copy link
Member

Choose a reason for hiding this comment

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

We should also document somewhere that such REPL automatic util requires are limited to Clojure and the hosted ClojureScript.

`cider-nrepl-op-supported-p' and `cider-library-present-p'.
But does not need to replace them.")

(defun cider-connection-has-capability-p (connection-buffer capability)
Copy link
Member

Choose a reason for hiding this comment

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

You can also swap the params if you want to make the connection optional (e.g. the current buffer or current-connection buffer by default).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok!

@bbatsov
Copy link
Member

bbatsov commented Dec 2, 2022

Overall I like how this is shaping up. Apart from my small remarks I think it'd be nice to document somewhere that you can use cider-connect-clj for nbb & friends. Of course, after #3275 you'll be able to connect to native ClojureScript repls normally as well, but in this case I think more is better. :-) I guess we'll quickly make a lot of progress on that front.

@benjamin-asdf
Copy link
Contributor Author

I added a doc in the docs scittle_and_friends.adoc

@bbatsov bbatsov merged commit 24b9891 into clojure-emacs:master Dec 3, 2022
@bbatsov
Copy link
Member

bbatsov commented Dec 3, 2022

Thanks for tackling this! 🙇‍♂️

@mk
Copy link
Contributor

mk commented Dec 3, 2022

@benjamin-asdf @bbatsov great to see this, thank you both!

@jackrusher
Copy link

@benjamin-asdf @bbatsov :D

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