-
-
Notifications
You must be signed in to change notification settings - Fork 645
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
CIDER gets confused with both a clj and a cljs repl open #2946
Comments
so i think this might be quite simple: if in |
Given all the sesman-related issues in recent years I'm seriously starting to wonder whether it was an improvement over what we had before. 😆 I was under the impression this was working, but it seems that I was mistaken. Btw, are those two REPLs created separately? It seems to me that this might explain the problem as then you'd have two REPLs with exactly the same project context, which makes it impossible for sesman to decide which is the right REPL as I don't think it takes into account REPL types in the relevance resolution. I'll try to investigate the issue further. //cc @vspinu |
Yes the repls are created separately. But i think that if we just get them all and do our own sorting on the CIDER side we would be fine. |
I get the idea, but it's kinda of the opposite of the case for using sesman in the first place - which was that related REPLs should be in the same session. What you describe is basically what CIDER was doing for years without sesman - it just focused on the REPLs. Is there any reason not to want to merge the two REPLs in the same session for you (make them sibling REPLs)? |
When it starts up it asks me to start a sibling repl and i say yes. I honestly don't really understand the implications of that but i believe they are siblings. |
What do you see when you do |
|
No sibling REPLs here - I see just two sessions with 1 REPL each. I wonder if there isn't some bug in the code that proposes to attach the new REPL to the existing session... |
I think I found the problem here #2923
Perhaps you're doing the same thing? |
yeah i guess i am. i always assumed "create a new sibling repl" rather than carry on without doing that. i guess i don't know how to run a clj and a cljs repl in the same project. seems the UX here is not great. |
Agreed, but at least fixing the UX is easier than anything else we've discussed. Can you confirm this is now working properly for you? |
I observe the same behavior when starting the clj repl and then running |
So you do see the two REPLs in the same session, but still the cljs REPL is never selected, right? |
Is there any workaround for this bug yet? I have the same setup and problem like @dpsutton i.e. shadow-cljs frontend with tools.deps backend. And |
@dpsutton I'm interested in this issue as well, and I'd be happy to pair or be mentored to do so. |
Just as another data point, I always start my repls with
|
Normally, that’s how I’d start my REPLs as well. But at my new job, they have clj tools and shadow started already from the CLI, and I simply need to connect via CIDER. So I use |
After some trial and error I finally got I had to
|
@dakra any chance you could share an example? |
Not sure if it helps anyone but when I'm in a cljc file and CIDER thinks I'm in the other session I usually just call But yeah, I'm doing |
@Aleksion what error do you get? It's correct that it starts 2 clj repls but one is then "converted" You need to have shadow-cljs in your classpath too. E.g. I have the following in my ((nil . ((cider-clojure-cli-global-options . "-A:dev:cljs:reveal")
(cider-custom-cljs-repl-init-form . "(do (require '[shadow.cljs.devtools.api :as shadow]) (require '[shadow.cljs.devtools.server :as server]) (server/start!) (shadow/watch :app) (shadow/nrepl-select :app))")
(cider-default-cljs-repl . custom)))) and not forget to have the shadow nrepl middleware in (add-to-list 'cider-jack-in-nrepl-middlewares "shadow.cljs.devtools.server.nrepl/middleware") Then make sure the variables are correctly set in the buffer Happy to help more if needed. |
I wonder if it's due to some of the default settings. (that are appended at the end of the command:
|
@dakra it does seem to complain about |
the current value of (nil . ((cider-jack-in-nrepl-middlewares . ("shadow.cljs.devtools.server.nrepl/middleware")) ;; you're removing the cider nrepl middleware here not sure if this will fix it but it stands out as obviously wrong to me if you intend to use CIDER. |
@dpsutton looking at the resulting command, and the documentation for |
@Aleksion Like @dpsutton said, you removed the Putting Personally I have this in my config: ;; Inject shadowcljs nrepl middleware in cider-jack-in when the `:cljs' alias is set
(defun cider-cli-global-options-contains-cljs? (&rest _)
(and cider-clojure-cli-global-options
(s-contains? ":cljs" cider-clojure-cli-global-options)))
(add-to-list 'cider-jack-in-nrepl-middlewares
'("shadow.cljs.devtools.server.nrepl/middleware" :predicate cider-cli-global-options-contains-cljs?)) which is a bit hacky, but it's enough for me until this issue is fixed. But for you to test, you could simply try hope this helps |
the middleware you ended up with lacked cider's middleware:
At my last job i just made some bespoke functions to jack-in or connect. (when personal/work-machine
(defmacro work-cider-connection (name&dir port)
`(defun ,(intern (format "work-jack-in-%s" (symbol-name name&dir))) ()
,(format "Jack into project %s and open its base directory." name&dir)
(interactive)
(let ((dir ,(format "~/projects/work/proj/src/work/"
(symbol-name name&dir))))
(cider-connect (list :host "local.work.com" :port ,port
:project-dir dir)))))
(work-cider-connection service 7000)
(work-cider-connection jobs 7001)
(work-cider-connection alerter 7002)
(work-cider-connection twilio 7004)) you can adjust as necessary. you could also make something generic that just adds the shadow middleware in a let binding and calls (defun jack-in-shadow-with-deps ()
(let ((cider-jack-in-nrepl-middlewares
(cons "shadow.cljs.devtools.server.nrepl/middleware"
cider-jack-in-nrepl-middlewares)))
(cider-jack-in nil))) |
Here's a toy project documenting how I've worked around this issue. It delivers all the REPL focusing and eval-ing support I need, but it's admittedly a little funky, with its idiosyncratic |
After getting extremely frustrated with always having to move the caret to the relevant repl and not wanting to manage my cljs deps in Steps to profit:
First attemptRelevant code in
Changes: ((listp type)
(mapcar #'cider-maybe-intern type))
((cider-maybe-intern type))))
- (repls (cdr (if ensure
- (sesman-ensure-session 'CIDER)
- (sesman-current-session 'CIDER)))))
+ (repls (if ensure (or (flatten-list (mapcar #'cdr (sesman-current-sessions 'CIDER)))
+ (user-error "No linked %s sessions" 'CIDER))
+ (flatten-list (mapcar #'cdr (sesman-current-sessions 'CIDER))))))
(or (seq-filter (lambda (b)
(cider--match-repl-type type b))
repls) Edit: Add a more refined version which allows toggling on a per-project basis. Better Version
|
- Makes cider-repls return the combination of all sesman sessions associated with a project - Adds a custom var for toggling the new functionality Partially closes clojure-emacs#2946.
- Makes cider-repls return the combination of all sesman sessions associated with a project - Adds a custom var for toggling the new functionality Partially closes clojure-emacs#2946.
- Makes cider-repls return the combination of all sesman sessions associated with a project - Adds a custom var for toggling the new functionality Partially closes clojure-emacs#2946.
- Makes cider-repls return the combination of all sesman sessions associated with a project - Adds a custom var for toggling the new functionality Partially closes clojure-emacs#2946.
- Makes cider-repls return the combination of all sesman sessions associated with a project - Adds a custom var for toggling the new functionality Partially closes clojure-emacs#2946.
- Makes cider-repls return the combination of all sesman sessions associated with a project - Adds a custom var for toggling the new functionality Partially closes clojure-emacs#2946.
- Makes cider-repls return the combination of all sesman sessions associated with a project - Adds a custom var for toggling the new functionality Partially closes clojure-emacs#2946.
- Makes cider-repls return the combination of all sesman sessions associated with a project - Adds a custom var for toggling the new functionality Partially closes clojure-emacs#2946.
- Makes cider-repls return the combination of all sesman sessions associated with a project - Adds a custom var for toggling the new functionality Partially closes clojure-emacs#2946.
- Makes cider-repls return the combination of all sesman sessions or those sessions with same host associated with a project - Adds a custom vars for toggling the new functionality Closes clojure-emacs#2946.
- Makes cider-repls return the combination of all sesman sessions or those sessions with same host associated with a project - Adds a custom vars for toggling the new functionality Closes clojure-emacs#2946.
- Makes cider-repls return the combination of all sesman sessions or those sessions with same host associated with a project - Adds a custom vars for toggling the new functionality Closes clojure-emacs#2946.
- Makes cider-repls return the combination of all sesman sessions or those sessions with same host associated with a project - Adds a custom vars for toggling the new functionality Closes clojure-emacs#2946.
- Makes cider-repls return the combination of all sesman sessions or those sessions with same host associated with a project - Adds a custom vars for toggling the new functionality Closes clojure-emacs#2946.
- Makes cider-repls return the combination of all sesman sessions or those sessions with same host associated with a project - Adds a custom vars for toggling the new functionality Closes clojure-emacs#2946.
- Makes cider-repls return the combination of all sesman sessions or those sessions with same host associated with a project - Adds a custom vars for toggling the new functionality Closes clojure-emacs#2946.
- Makes cider-repls return the combination of all sesman sessions or those sessions with same host associated with a project - Adds a custom var for toggling the new functionality Closes clojure-emacs#2946.
- Makes cider-repls return the combination of all sesman sessions or those sessions with same host associated with a project - Adds a custom var for toggling the new functionality Closes #2946.
CIDER gets confused when you have both a clj and a cljs repl open. Ideally evaluating code in a cljs file would always use the cljs repl and code evaluated in a clj file would always use the clj file. However, the bug is that CIDER attempts to use only the last repl your point was in. Meaning if your point was in the cljs repl and you attempt to evaluate cljs code, it works. But if point was last in the clj buffer nothing happens.
Repo
deps.edn
shadow-cljs.edn
src/clj.clj
src/cljs.cljs
Starting the repls
Just
cider-jack-in
as normal. Then clojurescript, selecting shadow and the browser repl. Then put point in one of the repls and evaluate code in the corresponding source file.point last in clj repl and evaluating in the clojure file
When moving the point into the clojurescript file and doing the inline evaluation, nothing happens.
Suspected cause
This functionality hits
cider-interactive-eval
which uses(cider-map-repls :auto ...)
This calls(cider-repls type ensure))
with typecljs
which returns no repls.(sesman-current-session 'CIDER)
returns only the clj repl.The docstring of that function is
And that's our problem. There's no way to tell sesman what CIDER thinks is relevant (aka, the cljs repl). We can only ask sesman for what it thinks is relevant, which is the most recently focused buffer.
The text was updated successfully, but these errors were encountered: