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

cider-repl-type is incorrect during cljs REPL startup #1557

Closed
jonpither opened this issue Feb 11, 2016 · 6 comments
Closed

cider-repl-type is incorrect during cljs REPL startup #1557

jonpither opened this issue Feb 11, 2016 · 6 comments
Assignees
Labels

Comments

@jonpither
Copy link
Contributor

This is about a problem of firing up two buffers using cider-jack-in-clojurescript, and the cljs repl buffer has cider-repl-type set to 'clj', meaning CIDER tries to perform operations such as load-file against the wrong connection-buffer (cljs rather than clj, leading to hanging and other issues).

Background:

The cider-repl-type on the cljs REPL gets set when (cljs-repl) is executed.

There are reasons why someone may have a cljs repl buffer open, but the execution of (cljs-repl) hasn't returned/happened yet. My config uses figwheel, as per below (taken from #1427):

'(cider-cljs-lein-repl
  "(do (use 'figwheel-sidecar.repl-api) (start-figwheel!) (cljs-repl))")

The call to (cljs-repl) hangs until I open up a page in the browser which establishes the browser REPL connection.

The problem is what happens in the in-between state. I use cider-jack-in-clojurescript which fires up two REPL buffers. During the in-between state, BOTH repls report cider-repl-type to be 'clj'. As it happens, usually the default-connection is the cljs one, except now it has the problem of thinking it's 'clj' rather than 'cljs'.

This has the consequence that you can attempt to compile a clj buffer into the cljs connection. This is because when you execute CIDER commands such as load-file, the connection buffer to be used is matched against the source buffer, based on the underlying cider-repl-type of the connection buffer (and whether the source buffer is clojurescript-mode vs clojure-mode).

Unless I'm doing something wrong, I think this is a bug in CIDER. To restate the problem: the developer must have established a browser REPL connection in the CLJS buffer, to avoid having problems; CLJ doesn't compile into the CLJS REPL buffer, and the vice-versa of trying to compile CLJS into CLJ.

For a solution, is there a reason why the connection-buffer spawned via cider-create-sibling-cljs-repl by default has the cider-repl-type set to 'clj' rather than cljs? Or maybe pending-cljs or even unknown.

Other related issues: #1509, #1511, #1400

@Malabarba
Copy link
Member

For a solution, is there a reason why the connection-buffer spawned via cider-create-sibling-cljs-repl by default has the cider-repl-type set to 'clj' rather than cljs? Or maybe pending-cljs or even unknown.

There's no particular reason, but I don't think that is going to work. IIRC, cider sends a couple of Eval requests to a repl immediately after it connects. So even if we set the repl-type to something else it would be immediately reset to clj by the automatic functionality.

Another option is to make it so that the sibling REPL connection is lower priority than the original one. That way, as long as they're both clj, the original one will take precedence.

@jonpither
Copy link
Contributor Author

"make it so that the sibling REPL connection is lower priority than the original one."

This would solve one half of it: when you compile clj source buffers it'll pick the highest priority clj repl connection instead of the default connection. I think there's still an issue of what happens when you try to compile a cljs file without a known cljs connection buffer. In this case, what should officially happen when you try to compile a cljs buffer and there's no established cljs repl connection open?

WRT the priority connection buffers, this feels a fairly fundamental change, but would work (if the above issue is also resolved).

@Malabarba
Copy link
Member

In this case, what should officially happen when you try to compile a cljs buffer and there's no established cljs repl connection open?

It should error out. If that doesn't happen currently then that's yet another bug. ☺

@jonpither
Copy link
Contributor Author

It doesn't error out, currently just hangs.

I will dig into it more, but that's the behaviour I'm seeing.

@Malabarba
Copy link
Member

I think it's a bug in the logic of cider-map-connections. When you invoke commands in a cljs file and there's no ClojureScript REPL it should throw user-error.
However, now that I think about it, I'm not sure if I actually implemented that.

@Malabarba
Copy link
Member

Both of the issues should be settled. Let me know if it seems to work.

Now, if your cljs connection hasn't fully setup yet (such as when it's waiting for you to open a browser page) then doing things like load-file on a cljs file will error out (complaining that a connection does not exist).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants