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

Smoother repl start for sci based repls #3255

Closed
benjamin-asdf opened this issue Oct 13, 2022 · 4 comments
Closed

Smoother repl start for sci based repls #3255

benjamin-asdf opened this issue Oct 13, 2022 · 4 comments

Comments

@benjamin-asdf
Copy link
Contributor

benjamin-asdf commented Oct 13, 2022

I would like to do this:

(cider-register-cljs-repl-type 'nbb-or-scittle-or-joyride "(+ 1 2 3)")

(defun mm/cider-connected-hook ()
  (when (eq 'nbb-or-scittle-or-joyride cider-cljs-repl-type)
    (setq-local cider-show-error-buffer nil)
    (cider-set-repl-type 'cljs)))

(add-hook 'cider-connected-hook #'mm/cider-connected-hook)

(defun mm/cider-jack-in-nbb ()
  (interactive)
  (cider-jack-in-cljs
   '(:jack-in-cmd
     "nbb nrepl-server"
     :cljs-repl-type
     nbb-or-scittle-or-joyride)))

This almost works except that cider--check-cljs ends up throwing because "require 'cljs.core" in sci based repls throws an error.
Here is a proposal:

(defun cider-verify-clojurescript-is-present ()
  "Check whether ClojureScript is present."
  (unless
      (nrepl-dict-get (cider-sync-tooling-eval "cljs.core/inc") "value")
    (user-error "ClojureScript is not available.  See https://docs.cider.mx/cider/basics/clojurescript for details")))

checking cljs.core/inc should work everywhere. I already checked my nbb command and connecting to a shadow project repl.
Slack conversation:
https://clojurians.slack.com/archives/C029PTWD3HR/p1665687978090599

@benjamin-asdf
Copy link
Contributor Author

I realized another hurdle for a command like this is that cider-jack-in-resolve-command and similar commands have a predefined set of project types. Irrc there is another discussion around this already? Maybe a really big alist is being called for?
Here is my current command:

(defun mm/cider-jack-in-nbb ()
  "Start a nbb nrepl process and connect."
  (interactive)
  (let* ((cider-allow-jack-in-without-project t)
	 (orig-buffer (current-buffer))
	 (params '(:jack-in-cmd "nbb nrepl-server :port 0"
				:cljs-repl-type nbb-or-scittle-or-joyride))
	 (params (cider--update-project-dir
		  params)))
    (nrepl-start-server-process
     (plist-get params :project-dir)
     (plist-get params :jack-in-cmd)
     (lambda (server-buffer)
       (with-current-buffer
	   orig-buffer
	 (cider-connect-sibling-cljs
	  params
	  server-buffer))))))

also blog post: https://benjamin-asdf.github.io/faster-than-light-memes/jacking-nbb.html

@benjamin-asdf
Copy link
Contributor Author

Update: We since discovered a bug in babashka where cljs.core/inc was defined. To differentiate cljs from clj reples you can check cljs.core/demunge.

@bbatsov
Copy link
Member

bbatsov commented Dec 21, 2022

@benjamin-asdf I guess we can close this, right?

@benjamin-asdf
Copy link
Contributor Author

I close this is fixed

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

No branches or pull requests

2 participants