This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-10-11
Channels
- # announcements (1)
- # babashka (132)
- # beginners (52)
- # calva (46)
- # clj-kondo (8)
- # cljdoc (17)
- # clojure (13)
- # clojure-australia (1)
- # clojure-dev (3)
- # clojure-europe (4)
- # clojurescript (4)
- # cloverage (1)
- # conjure (22)
- # datomic (9)
- # emacs (2)
- # fulcro (16)
- # leiningen (5)
- # malli (26)
- # off-topic (16)
- # pathom (3)
- # portal (5)
- # reagent (10)
- # reitit (5)
- # rewrite-clj (1)
- # ring (1)
- # shadow-cljs (14)
- # spacemacs (6)
- # tools-deps (10)
- # vim (11)
- # vscode (1)
- # xtdb (10)
How do I distinguish a babashka session as being run as a script from it being evaluated in an repl session?
$ bb
Babashka v0.2.2-SNAPSHOT REPL.
Use :repl/quit or :repl/exit to quit the REPL.
Clojure rocks, Bash reaches.
user=> *file*
"<repl>"
Doesn't seem like Calva plays very well with babashka, though 😞 I think I remember it working pretty well...
hmm, what isn't working? i just tried with some success... started an nrepl server in a terminal (`bb --nrepl-server`), connected to the appropriate port, and evaluated a form
When I select: connect to a running REPL not in project > generic, Calva doesn't ask me for more info. It did a while back
yeah, in project did work for me (I'm on the normal Calva plugin from the marketplace)
I think there is a bug with "Not in project”. It is not the problem for me though. I can connect, but Calva relies heavily on the info
op, which doesn't seem to be implemented.
Here are all the implemented ops: https://github.com/babashka/babashka.nrepl/blob/master/src/babashka/nrepl/impl/server.clj#L179 They are also returned in describe, a proper client should handle that ;)
The bb nrepl implements most of the ops listed here: https://nrepl.org/nrepl/ops.html I don't see an info op and have no clue what it does.
Apparently about https://nrepl.org/nrepl/ops.html#lookup
Here's the issue I created: https://github.com/babashka/babashka.nrepl/issues/30
Thanks. I responded in the issue :) Maybe you could past a few example conversations of input + outputs
I think you can do this in emacs using some cider setting where it logs this to a buffer
Thanks. Not sure when this will be implemented and by who, so meanwhile, if you want to support bb, it's best to work with what's returned in describe
Yeah. I probably should implement using el-doc directly. babashka is the first repl I try to support where I can't just inject cider-nrepl. However, info
provides url-paths to the files, as well as line-numbers.
for bb you can eval (meta (resolve 'foo/bar))
which should give you :file
, :line
etc
For some reason I want to use .bb
as file extension. But babashka seems to want me to use .clj
. Is that so?
Let me try again then... So, when I have a file bin/foo.bb
with (ns foo)
and start bb like:
BABASHKA_DEV=true bb --classpath bin --nrepl-server 1337
foo.clj:
(ns foo)
(prn :foo)
(prn (ns-name *ns*))
borkdude@MBP2019 ~ $ lein repl :connect 1337
Connecting to nREPL at 127.0.0.1:1337
user=> (require 'foo)
:foo
foo
nil
Same with http://foo.bb. What's unexpected here?@pez Please use a thread. I don't know how I can repro your problem. Please give more details.
Well, somewhat I can repro it that way. The ns in my case is pimp-my-ride
. The file starts with a bb shabang w/o the --classpath
(b/c I just learned about that). Then (ns pimp-my-ride)
. I start the server like so:
BABASHKA_DEV=true bb --classpath bin --nrepl-server 1337
Then connect and do in-ns
:
$ lein repl :connect localhost:1337
Connecting to nREPL at localhost:1337
clojure.lang.ExceptionInfo: Could not resolve symbol: nrepl.core/version
user=> (in-ns 'pimp-my-ride)
nil
pimp-my-ride=>
babaska prints a huge blob of things but at the end of this is:
Reading! fff519ed-2763-4b2b-88b0-4f04e318b025 0
"Received" {:code "", :id "8d7c713b-4fe9-46b0-9b3f-e19b2afa7b56", :op :eval, :session "f8fc70b8-5f5a-4739-93b6-fb8b07f735ee"}
current ns user
Reading! fff519ed-2763-4b2b-88b0-4f04e318b025 0
"Received" {:code "(in-ns 'pimp-my-ride)", :id "f7074c63-304d-4acc-9db9-96ef59cc0b27", :op :eval, :session "f8fc70b8-5f5a-4739-93b6-fb8b07f735ee"}
current ns user
Reading! fff519ed-2763-4b2b-88b0-4f04e318b025 0
Can you explain what the problem is you're trying to repro. I think I missed the point
Yeah, the problem is that when I use the load-file
op, then babashka doesn't switch namespace when the file ends with .bb
.
No it doesn't?
user=> (load-file "/tmp/bin/foo.clj")
:foo
foo
{:line 6, :column 1, :end-line 6, :end-column 14, :name foo, :ns #object[sci.impl.vars.SciNamespace 0x4b13fc2c "foo"], :file "/tmp/bin/foo.clj", :arglists ([])}
nil
user=>
And also, that is how other nrepl servers behave. So, the symbols in the file gets defined in the ns specified in the (ns ...)
form.
Not sure how to communicate this. 😃 But in any case. I get the behaviour I expect when the file is a .clj file, but not with .bb.
That's weird then. The op doesn't specify an ns switch though: https://nrepl.org/nrepl/ops.html#load-file and clojure.core/load-file also doesn't switch to that ns
No, I don't think it is Calva. Check this.
Reading! 0b694590-8bc8-42e8-9602-16acd712430b 0
"Received" {:op :load-file, :session "6e4ea24d-0df5-4184-bac4-3a994f02cee6", :file "#!/usr/bin/env bb\n(ns foo)\n\n(def bar \"baz\")\n", :id "29", :file-name "", :file-path "/Users/pez/Projects/liberty/cospaia.se/bin/foo.bb"}
current ns user
Reading! 0b694590-8bc8-42e8-9602-16acd712430b 0
"Received" {:id "30", :op :eval, :session "6e4ea24d-0df5-4184-bac4-3a994f02cee6", :code "(in-ns 'foo)", :pprint 0}
current ns foo
Reading! 0b694590-8bc8-42e8-9602-16acd712430b 0
"Received" {:op :load-file, :session "6e4ea24d-0df5-4184-bac4-3a994f02cee6", :file "#!/usr/bin/env bb\n(ns foo)\n\n(def bar \"baz\")\n", :id "31", :file-name "foo.clj", :file-path "/Users/pez/Projects/liberty/cospaia.se/bin/foo.clj"}
current ns foo
You still haven't explained to me what error. I do see a difference, but what's the error? Problem statement?
user=> (println (slurp "/tmp/bin/foo.bb"))
(ns foo)
(defn bar [])
nil
user=> (load-file "/tmp/bin/foo.bb")
#'foo/bar
user=> (ns-name (:ns (meta #'foo/bar)))
foo
when I do cider-load-buffer
in the bb file and then get eldoc for bar, then it says foo/bar
this is with http://foo.bb
"Received" {:op :load-file, :file "#!/usr/bin/env bb\n\n(ns foo)\n\n(defn bar [])\n", :file-path "/tmp/bin/foo.bb", :file-name "", :session "40f03a20-431a-49e8-81ad-e6cbcd38b553", :id "17"}
current ns foo
Reading! ed2457d2-d18e-4ce5-86a4-c297bb686cae 0
I think I know what they do different now. Emacs send the ns with the eval, while Calva doesn't. So I can work around the error by fixing this in Calva.
yes. load-file doesn't cause an ns switch. so the current ns stays user. if you then eval single expressions without setting an ns, they are eval-ed in user
This is all it does:
:load-file (let [file (:file msg)
msg (assoc msg :code file)]
(eval-msg ctx os msg opts)
(recur ctx is os id opts))
hm, so maybe it should switch ns then, since it's the same as when just sending an ns form?
the extension should be irrelevant here since it only does something with the contents of the file
load-file using emacs works the same as with calva. With .clj
files the ns changes, with .bb
files, it doesn't.
For load-file Calva and Emacs send the same things. Not sure if that was what you asked..
.bb
:
"Received" {:id "12", :op :eval, :session "72be4e52-411f-4862-93a6-b60fe02acdbe", :code "(in-ns 'user)", :pprint 0}
current ns user
Reading! 8647947a-b575-4813-a6b3-26e2d917b1cf 0
"Received" {:op :load-file, :session "72be4e52-411f-4862-93a6-b60fe02acdbe", :file "#!/usr/bin/env bb\n(ns foo)\n(def bar \"baz\")", :id "13", :file-name "", :file-path "/Users/pez/Projects/liberty/cospaia.se/bin/foo.bb"}
current ns user
Reading! 8647947a-b575-4813-a6b3-26e2d917b1cf 0
.clj
:
"Received" {:id "14", :op :eval, :session "72be4e52-411f-4862-93a6-b60fe02acdbe", :code "(in-ns 'foo)", :pprint 0}
current ns foo
Reading! 8647947a-b575-4813-a6b3-26e2d917b1cf 0
"Received" {:op :load-file, :session "72be4e52-411f-4862-93a6-b60fe02acdbe", :file "#!/usr/bin/env bb\n(ns foo)\n(def bar \"baz\") \n", :id "15", :file-name "foo.clj", :file-path "/Users/pez/Projects/liberty/cospaia.se/bin/foo.clj"}
current ns foo
Reading! 8647947a-b575-4813-a6b3-26e2d917b1cf 0