jasongilman / proto-repl

A Clojure Development Environment package for the Atom editor
https://atom.io/packages/proto-repl
MIT License
563 stars 50 forks source link

Add support for ClojureScript #54

Open ZainRizvi opened 8 years ago

ZainRizvi commented 8 years ago

It would be great if you could add support to the repl to work with ClojureScript as well!

jasongilman commented 8 years ago

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.

puppybits commented 8 years ago

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.

gnl commented 8 years ago

+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)

gnl commented 8 years ago

Second attempt - using figwheel within nrepl (https://github.com/bhauman/lein-figwheel/wiki/Using-the-Figwheel-REPL-within-NRepl)

  1. Start lein with default 'repl' argument in proto-repl
  2. 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?

jefffriesen commented 8 years ago

I realize there's lots to work on, but I would personally love to see support for CLJS.

jasongilman commented 8 years ago

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.

jasongilman commented 8 years ago

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.

jasongilman commented 8 years ago

The clojurescript branch has replumb incorporated (not into a Proto REPL repl yet). Instructions to try it out:

  1. check out that branch
  2. run lein cljsbuild once in edn-reader folder
  3. Restart atom.
  4. Run something like this in the JavaScript console: protoRepl.edn_reader.eval_str("(+ 1 1)", function(v){console.log(v)})
jasongilman commented 8 years ago

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.

jefffriesen commented 8 years ago

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.

jasongilman commented 8 years ago

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.

tomisme commented 8 years ago

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?

jasongilman commented 8 years ago

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 notifications@github.com 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

tomisme commented 8 years ago

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.

jasongilman commented 8 years ago

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 notifications@github.com 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

tomisme commented 8 years ago

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!

jasongilman commented 8 years ago

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.

tomisme commented 8 years ago

Removed the do block and in-ns appears to be working.

arichiardi commented 8 years ago

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!

jasongilman commented 8 years ago

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.

arichiardi commented 8 years ago

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!

arichiardi commented 8 years ago

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:

DogLooksGood commented 8 years ago

I think it works pretty good with Piggieback, except that I can not quit CLJS repl with :cljs/quit.

naartjie commented 8 years ago

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?

jasongilman commented 8 years ago

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.

naartjie commented 8 years ago

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.

arestov commented 7 years ago

https://anmonteiro.com/2016/11/the-fastest-clojure-repl-in-the-world/

seantempesta commented 7 years ago

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)

klsmithphd commented 7 years ago

@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.

jasongilman commented 7 years ago

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.

klsmithphd commented 7 years ago

I've really enjoyed using proto-repl for several months now, and I'm interested and motivated to help out here. I'm just not sure how best to do that. I tried installing nrepl-transcript middleware so I could inspect what messages were being sent to proto-repl as the cljs-repl gets started. I thought I'd try to compare that with what CIDER does. I can get some very detailed (verbose) output from the proto-repl transcript, but very little from CIDER. At least out of the box, that didn't help me see how the two REPL tools behave differently.

I'm a relatively new Clojure/Clojurescript developer and haven't looked at the internals of any Atom projects previously, so I'd be very open to any guidance or recommendations about where I could/should look to help push this along. This is all motivated self-interest --- I'd much prefer to stick with the Atom ecosystem than use Emacs like seemingly everyone else.

naartjie commented 7 years ago

This is what happens when connecting to a running nRepl of a boot-clj cljs project, created from the https://github.com/martinklepsch/tenzing template:

Create a new project. Add [proto-repl "0.3.1"] to dependencies in build.boot Run boot dev. Open the project in Atom, and open an nRepl session to it.

And run these commands:

(in-ns 'boot.user)
(start-repl)

You will then see:

<< started Weasel server on ws://127.0.0.1:52195 >>
<< waiting for client to connect ... 
Connection is ws://localhost:52195
Writing boot_cljs_repl.cljs...

Which is very exciting :-) When the browser connects:

connected! >>
To quit, type: :cljs/quit

After that, every character I type, seems to create this error output:

java.lang.RuntimeException: Unable to resolve symbol: require in this context
clojure.lang.Compiler$CompilerException: java.lang.RuntimeException: Unable to resolve symbol: require in this context, compiling:(/var/folders/t3/y0t3vzwj4rz37crrbg378z480000gn/T/boot.user6233645903598692515.clj:1:5)

But running (println "hi") works, in that I can see the output in the browser. Coolness ;-)

@jasongilman Is there any more logs I can take a look at? Any pointers on the next step for me to try and help. I am pretty new to this environment, but not scared to take a look at some internals, ok, maybe a little scared, since I haven't peeked at proto-repl's source at all yet ;-P

Edit: I added proto-repl as a dep to my project...

jasongilman commented 7 years ago

Try disabling auto complete in the settings and see if the errors go away. I think that's where the errors are coming from.

Sent from my phone

On Jan 18, 2017, at 1:28 AM, Marcin Jekot notifications@github.com wrote:

This is what happens when connecting to a running nRepl of a boot-clj cljs project, created from the https://github.com/martinklepsch/tenzing template:

Create a new project. Run boot dev. Open the project in Atom, and open an nRepl session to it.

And run these commands:

(in-ns 'boot.user) (start-repl) You will then see:

<< started Weasel server on ws://127.0.0.1:52195 >> << waiting for client to connect ... Connection is ws://localhost:52195 Writing boot_cljs_repl.cljs... Which is very exciting :-) When the browser connects:

connected! >> To quit, type: :cljs/quit After that, every character I type, seems to create this error output:

java.lang.RuntimeException: Unable to resolve symbol: require in this context clojure.lang.Compiler$CompilerException: java.lang.RuntimeException: Unable to resolve symbol: require in this context, compiling:(/var/folders/t3/y0t3vzwj4rz37crrbg378z480000gn/T/boot.user6233645903598692515.clj:1:5) But running (println "hi") works, in that I can see the output in the browser. Coolness ;-)

@jasongilman Is there any more logs I can take a look at? Any pointers on the next step for me to try and help. I am pretty new to this environment, but not scared to take a look at some internals, ok, maybe a little scared, since I haven't peeked at proto-repl's source at all yet ;-P

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

naartjie commented 7 years ago

@jasongilman Thanks. confirmed, the errors have gone away after disabling the auto-complete. At first glance the REPL seems usable.

Although I can't figure out how to do basic tasks - like I can't eval anything in my cljs files, and I can't seem to call any of my libraries loaded like (taoensso.timbre/log :foo), but that might just be me not knowing how to drive this thing.

rgdelato commented 7 years ago

@Ken-2scientists As of this latest Proto REPL version, you should now be able to run :cljs/quit and have it work correctly to exit and return to the plain Clojure REPL.

danpicton commented 7 years ago

Nice one folks. I've just tried :cljs/quit in Proto REPL and can confirm it works. I don't have any auto-complete options available in the CLJS REPL though - is that to be expected at the moment?

jasongilman commented 7 years ago

Yeah auto complete doesn't work with cljs in proto REPL.

Sent from my phone

On Aug 8, 2017, at 3:04 PM, Dan Picton notifications@github.com wrote:

Nice one folks. I've just tried :cljs/quit in Proto REPL and can confirm it works. I don't have any auto-complete options available in the CLJS REPL though - is that to be expected at the moment?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

loganpowell commented 6 years ago

First, thank you for Proto REPL! I'm using shadow-cljs with Proto (I wrote up a blog post about it), but I keep getting kicked out of my shadow cljs REPL and put into a Clojure REPL. Is there a way I can set it to use cljs for the session? Right now, The caveats in the Proto REPL section of the guide are pretty thick. I don't want to give bad advice if there's a simpler workflow.