proto-repl
proto-repl copied to clipboard
Add support for ClojureScript
It would be great if you could add support to the repl to work with ClojureScript as well!
Thanks for the suggestion. I'm going to start thinking about how this could be done. This admittedly won't be at the top of my priorities right now because I don't use ClojureScript a lot. On the other hand I'm starting to depend more on ClojureScript within Proto REPL itself and it would be handy to have a nice REPL to use in the development of Proto REPL. If you have suggestions for initial changes please comment here.
fig-wheel is using Piggieback to connect to a JS runtime (either Node, Rhino or a browser). Piggieback is exposing a nREPL interface so toggling between clj and cljs shouldn't be too bad.
+1 for ClojureScript / Figwheel support! I tried setting this up with figwheel and react-native (using https://github.com/drapanjanas/re-natal to init the project) by changing the lein arguments in the proto-repl settings from 'repl' to 'figwheel ios'
Works so far as the repl starts, connects and displays a prompt, but I can't send anything to it (or run a manual command)
Second attempt - using figwheel within nrepl (https://github.com/bhauman/lein-figwheel/wiki/Using-the-Figwheel-REPL-within-NRepl)
- Start lein with default 'repl' argument in proto-repl
- Execute the following code:
(def figwheel-config
{:figwheel-options {}
:build-ids ["ios"]
:all-builds
[{:id "ios"
:figwheel true
:source-paths ["src" "env/dev"]
:compiler {:output-to "target/ios/not-used.js"
:main "env.ios.main"
:output-dir "target/ios"
:optimizations :none}}]})
(use 'figwheel-sidecar.repl-api)
(start-figwheel! figwheel-config)
(cljs-repl)
Expected - same behaviour as with 'lein repl' when run from the command line, which is a perfectly working ClojureScript/Figwheel REPL.
Instead I get this when I try to eval something:
(+ 2 3)
=> WARNING: Use of undeclared Var /eval at line 1 <cljs repl>
=> WARNING: Use of undeclared Var /read-string at line 1 <cljs repl>
=> #object[SyntaxError SyntaxError: Unexpected token '.']
=> eval@[native code]
figwheel$client$utils$eval_helper
Any ideas what might be causing this?
I realize there's lots to work on, but I would personally love to see support for CLJS.
Sorry, I should have responded to this earlier. The problem with eval is a result of this line https://github.com/jasongilman/proto-repl/blob/master/lib/repl.coffee#L221
I think eval isn't going to work in ClojureScript. I need a better way to handle this sort of problem. It's possible that the eval wrapping isn't necessary anymore. Proto REPL was originally using direct stdin to write to the REPL. Now that it's using nREPL that may already be handled. I'll have to do some testing.
I'm working on trying to get self hosted ClojureScript working with replumb. I should also be able to get the other kinds of ClojureScript REPLs working hopefully.
The clojurescript branch has replumb incorporated (not into a Proto REPL repl yet). Instructions to try it out:
- check out that branch
- run lein cljsbuild once in edn-reader folder
- Restart atom.
- Run something like this in the JavaScript console:
protoRepl.edn_reader.eval_str("(+ 1 1)", function(v){console.log(v)})
I'm continuing work in this area. I want to be able to use ClojureScript for developing Proto REPL itself. Some of it is in ClojureScript but not as much as I'd like.
I've done some major refactoring to get the self hosted REPL working. I have it working somewhat now. The command pallet can be used to find "Proto REPL start self hosted REPL" and bring up a REPL. Normal Proto REPL commands work. Completion works except for the docs. There's a bit more work to finish this up.
The work here should help with all ClojureScript REPLs. I'll make sure that I can get a rhino or browser connected REPL working as well.
What's great about the self hosted REPL is that it will mean Proto REPL can be used without Java or leiningen. I want the visualization aspects of Proto REPL charts to work as well with the self hosted REPL.
I haven't contributed to any of the code, but I love it that you could develop it in CLJS instead of coffeescript (not hating on coffeescript, btw). And that someone will be able to run it without java or leiningen. It aligns with what power this project has and where it's going - until now there was a pretty big hurdle to start using Clojure - Emacs, paredit key bindings (now we have parinfer), Java/leiningen, We're getting closer and closer to just being able to learn and use the language itself with little friction.
Thank you for doing this.
I just finished and pushed Proto REPL 1.1.0 with support for a self hosted ClojureScript REPL. Many of the issues related to why ClojureScript wasn't working have been resolved. I'm not closing this yet as I haven't tested it fully with different ClojureScript projects. I'd appreciate any help in testing this. If you can try out Proto REPL with your ClojureScript projects and report any issues it would help in getting it supported in Proto REPL faster.
Thanks Jason!
So if I understand from having a play with the repl and reading the "Starting a Self Hosted ClojureScript REPL" section you added to the package docs, I can send code to the repl but the repl can't enter a namespace from my project with in-ns. Does this also mean that at the moment the autocomplete function won't give suggestions from my own vars as proto-repl doesn't have any knowledge of them?
The self hosted REPL has completion by using the special apropos function
from Replumb. It can complete any namespaces and vars it knows about but
the self hosted REPL can't load your project files yet. If you individually
evaluate each block or select a whole file and evaluate the selection that
should work.
Whether this will work or not depends on whether the code your running will make sense inside of an Atom environment. If it's code meant for running in a browser it might work. If you're trying to run a regular ClojureScript project I would also try a regular REPL (The standard proto REPL REPL) using Piggieback to run in Rhino or a browser connected session. This isn't stuff I've tried out yet in Proto REPL with the latest changes so I'm not sure what issues you may run into.
On Mon, Mar 14, 2016 at 11:13 PM, Tom Hutchinson [email protected] wrote:
Thanks Jason!
So if I understand from having a play with the repl and reading the "Starting a Self Hosted ClojureScript REPL" section you added to the package docs, I can send code to the repl but the repl can't enter a namespace from my project with in-ns. Does this mean that at the moment the autocomplete function won't give suggestions from my own vars as proto-repl doesn't have any knowledge of them?
— You are receiving this because you commented. Reply to this email directly or view it on GitHub: https://github.com/jasongilman/proto-repl/issues/54#issuecomment-196631638
Ok, I'll give that a try. What I meant was that when I enable the proto-repl package, it takes over autocomplete even when I'm not in a non-repl clojure(script) file. This is fine when working on clojure as the repl has loaded all my local files but means I lose autocomplete in my local files when I have the proto-repl package enabled and no repl / self hosted repl open.
That's a good point. There should be a fallback if Proto REPL isn't running a REPL.
Sent from my phone
On Mar 15, 2016, at 7:33 AM, Tom Hutchinson [email protected] wrote:
Ok, I'll give that a try. What I meant was that when I enable the proto-repl package, it takes over autocomplete even when I'm not in a non-repl clojure(script) file. This is fine when working on clojure as the repl has loaded all my local files but means I lose autocomplete in my local files when I have the proto-repl package enabled and no repl / self hosted repl open.
— You are receiving this because you commented. Reply to this email directly or view it on GitHub: https://github.com/jasongilman/proto-repl/issues/54#issuecomment-196777197
I've tried connecting proto-repl to my browser-based clojurescript project using figwheel and nREPL.
First I followed the instructions for Using the Figwheel REPL within NRepl and set up figwheel and piggieback in my project.clj. Ran lein repl in terminal and opened a connection to it using proto-repl. It printed:
Starting remote REPL connection on localhost:36458
user=>
Refreshing code...
;; Repl successfuly started
Refresh failed: FileNotFoundException Could not locate user__init.class or user.clj on classpath.
clojure.lang.RT.load (RT.java:449)
I ran (use 'figwheel-sidecar.repl-api) and (start-figwheel!), worked fine. At this point autocompletion is completing clojure(script?) vars in my project but not picking up my own vars of course.
Afterwards, running (cljs-repl) in the proto-repl connects to the code running in my browser. I can punch in (.log js/console "hello") and it will print in the browser console. I can access my project's vars in the repl but I have to use fully qualified names. When I connect to the nREPL server using lein in a separate terminal window I can (in-ns) into my projects namespaces but when I try to in the proto repl I get:
cljs.user=> WARNING: Use of undeclared Var cljs.user/in-ns at line 1 <cljs repl>
cljs.user=> #object[TypeError TypeError: Cannot read property 'call' of undefined]
Autocomplete also stops working entirely in when editing my project files.
I'm still new to all this so I hope this is helpful in some way. One step closer to my dream cljs dev environment!
Thanks that's helpful. I can see a few thing I need to change. The default namespace is user and it probably needs to be more flexible to choose the right one. I think the reason in-ns isn't working is because it gets wrapped in a do block. I think ClojureScript must look for in-ns only as the top function call because it's a special kind of function.
Note that Proto REPL code is in ~/.atom/packages/proto-repl. If you're feeling adventurous try modifying lib/repl.coffee on this line https://github.com/jasongilman/proto-repl/blob/master/lib/repl.coffee#L247
So that the code isn't wrapped in a do block. That would temporarily let you use in-ns presuming that's the problem. You'll need to restart atom or reload for the code changes to take effect.
Removed the do block and in-ns appears to be working.
I just would like to say that I am so happy you integrated replumb in proto repl. I will release version 0.2.0 soon with a couple of additions and fixes.
Good job here!!! I went to explore a bit your repo (trying to find how you stop long evaluations) and found all this! :) Keep it up!
Thanks @arichiardi! What's the best way to stay apprised of Replumb changes? I just started watching the repo. If you have suggestions in the future for how to improve the self hosted bits let me know. I know Clojure (JVM) pretty well but I'm still learning the limitations and differences of the ClojureScript side.
Well I guess I will try to keep you posted, usually we post on Twitter the changes, but for the coming 0.2.0 (that breaks some of your code, sorry about that btw), I will write a blog post. I checked your code and looks ok don't worry!
By the way @jasongilman, feel free to open a PR to add yourself to our README, and if you want to add the replumb logo somewhere it is here. We got to support each other :wink:
I think it works pretty good with Piggieback, except that I can not quit CLJS repl with :cljs/quit.
I'd appreciate any help in testing this. If you can try out Proto REPL with your ClojureScript projects and report any issues it would help in getting it supported in Proto REPL faster.
@jasongilman how can I help testing this with my figwheel project today? Should I be using the clojurescript branch?
If you test the released version of Proto REPL that would be helpful. If you find a problem it would be helpful if you included instructions on how to reproduce it. Thanks for offering to help.
test the released version of Proto REPL
Thanks. I am clueless on how to get started with ClojureScript though. It works with Clojure, I just don't know how to get started with a ClojureScript project.
I have asked on the clojurians Slack #proto-repl for help.
https://anmonteiro.com/2016/11/the-fastest-clojure-repl-in-the-world/
I'm confused as to the status of this issue? It seems like it's working for some people? Can someone document how to at least get partial support working? I just saw your Proto-REPL talk on YouTube and I'm stoked to try it. (great talk btw)
@seantempesta : Here's a way of testing out some of the partial support available.
I tested this with a brand new figwheel project created via the lein-figwheel template:
lein new figwheel foo
It seems that recent versions of the lein-figwheel template will take care of defining most of the setup that was documented in https://github.com/bhauman/lein-figwheel/wiki/Using-the-Figwheel-REPL-within-NRepl .
If you open up that project in Atom, and then start the proto-repl (Ctrl-Alt-, L in my case), you can do the following to get figwheel going:
(use 'figwheel-sidecar.repl-api)
(start-figwheel!)
At that point, with this template anyway, your browser will open up the index page and you'll see that Figwheel is running on localhost:3449. You can edit files in Atom and Figwheel will pick up the changes on save. You can't execute any blocks of Clojurescript, yet though, because you're still in a Clojure REPL. The normal Figwheel output hasn't been printed yet, but you have access to functions like (reset-autobuild) and (fig-status) at this point.
You can start the Clojurescript REPL by executing (cljs-repl). Figwheel spits out the output about its controls (no longer accessible), and now you can start executing Clojurescript blocks (e.g. Ctrl-Alt-, B) from inside a cljs source file in Atom. The REPL is pretty limited, though --- you can't seemingly change namespaces, autocomplete appears to be broken, and I haven't found a way to exit the cljs-repl short of killing all the processes via the terminal. :cljs/quit returns as if it succeeded, but the prompt still shows cljs.user=> and I haven't figured out how to get back to a plain Clojure REPL.
Thanks for that very thorough description of the status quo of Proto REPL and ClojureScript. It sounds like things sort of work (with some squinting) but are definitely not ideal. I don't personally have time to improve this part of Proto REPL right now but I'd really like to see it get better.