Fork me on GitHub
#cider
<
2020-05-19
>
Eric Ihli16:05:36

I've got a problem where cider-connect-cljs from a .cljs file is creating a repl buffer with type clj and I'm not able to evaluate anything from the clojurescript buffer. There's no error. Just, nothing happens.

Eric Ihli17:05:59

It's happening here. I found this with a debug-on-entry on cider-set-repl-type

(defun cider-repl--state-handler (response)
  "Handle server state contained in RESPONSE."
  (with-demoted-errors "Error in `cider-repl--state-handler': %s"
    (when (member "state" (nrepl-dict-get response "status"))
      (nrepl-dbind-response response (repl-type changed-namespaces)
        (when (and repl-type cider-repl-auto-detect-type)
          (cider-set-repl-type repl-type))
        (unless (nrepl-dict-empty-p changed-namespaces)
          (setq cider-repl-ns-cache (nrepl-dict-merge cider-repl-ns-cache changed-namespaces))
          (dolist (b (buffer-list))
            (with-current-buffer b
              ;; Metadata changed, so signatures may have changed too.
              (setq cider-eldoc-last-symbol nil)
              (when (or cider-mode (derived-mode-p 'cider-repl-mode))
                (when-let* ((ns-dict (or (nrepl-dict-get changed-namespaces (cider-current-ns))
                                         (let ((ns-dict (cider-resolve--get-in (cider-current-ns))))
                                           (when (seq-find (lambda (ns) (nrepl-dict-get changed-namespaces ns))
                                                           (nrepl-dict-get ns-dict "aliases"))
                                             ns-dict)))))
                  (cider-refresh-dynamic-font-lock ns-dict))))))))))

Eric Ihli16:05:24

From what I can gather, cider-connect-cljs gives the newly created REPL buffer a temporary type, pending-cljs, does some work, then adjusts the buffer's name/type based on something it figures out from the repl command? For some reason, even though I'm starting with the cider-connect-cljs command and giving it a shadow type, it's still resulting in a clj buffer.

Debugger entered--entering a function:
* cider-set-repl-type("clj")
* cider-repl--state-handler((dict ... ;;**** This response has :repl-type clj
* nrepl-client-filter(#<process nrepl-connection> "ender for Clojure.\"2:fn4:truee3:spyd8:arglists64:(...")
  accept-process-output(nil 0.01)
  nrepl-send-sync-request(("op" "eval" "code" "(require 'cljs.core)") #
  ...
  cider-library-present-p("cljs.core")
  cider-verify-clojurescript-is-present()
  cider--check-cljs(shadow)

Eric Ihli17:05:39

So cider is setting my repl type to clj because my repl is including :repl-type clj in its response when nrepl-send-sync-request is called?

Eric Ihli17:05:23

The repl was started with npx shadow-cljs server...

Eric Ihli17:05:01

I manually change the repl type to cljs with (cider-set-repl-type 'cljs) and then evaluate a form in a cljs buffer and the debug-on-entry on cider-set-repl-type gets hit again and it changes the repl buffer back to clj because the nrepl response includes :repl-type clj.

bozhidar19:05:05

The REPL type is set automatically after each request, so there’s little point in trying to force it manually. Most likely something’s not properly setup with the project. For starters - make sure you’re using the most recent shadow-cljs and CIDER.

Eric Ihli21:05:23

Any idea on a next step after that? I'm using shadow-cljs 2.8.107 and cider 0.25.0-alpha1, which are the latest from what I can tell.

bozhidar06:05:34

You can take a look at the nREPL message exchange and see if there’s something weird there.

Michaël Salihi21:05:24

Hi! Is there a way to force clj-refactor to use for eg. deps.edn over project.clj if both exist at project root ? Maybe in dirs-local.el ? When I use for eg. cljr-add-project-dependency , I get cljr--insert-into-leiningen-dependencies: Search failed: ":dependencies" error because as I understand project.clj takes priority over deps.edn. https://github.com/clojure-emacs/clj-refactor.el/blob/8259791e054382457b87d1f78061b5e3ce948907/clj-refactor.el#L818

practicalli-john22:05:40

@admin055 If you have more than one project configuration file (project.clj, deps.edn, build.boot) then cider-jack-in commands should display a prompt allowing you to choose which configuration to use. To specify the default project configuration for CIDER, create a dir-locals.el file in the root of your project directory containing the following

((clojure-mode . ((cider-preferred-build-tool . "clojure-cli"))))
I have not tested this with clj-refactor as I stopped using that library a long while ago. If it doesnt work wth clj-refactor, then consider raising an issue or better yet a PR.

practicalli-john22:05:51

If using Clojure CLI tools you can also set default aliases too, for example

((clojure-mode . ((cider-clojure-cli-global-options . "-A:fig"))))
https://practicalli.github.io/blog/posts/cider-jack-in-to-clojure-cli-projects-from-spacemacs/

practicalli-john22:05:56

And if you have multiple clojure projects under one git repository, you can tell projectile to treat them all as Clojure projects using

((nil . ((projectile-project-type . clojure-cli))))
https://practicalli.github.io/spacemacs/clojure-projects/monorepo-nested-projects.html