Fork me on GitHub
#babashka
<
2021-02-04
>
ABeltramo08:02:37

Hello guys, can someone help me setting up Intellij + cursive with babashka? I can't get it to recognise dependencies. Do I have to create a dummy lein project with babashka as a dependency to make it work?

borkdude08:02:35

@beltramo.ale If you want auto-completion things and have Cursive analyze the dependencies then probably it's enough to add a deps.edn with the deps you are using in your script(s)

ABeltramo09:02:50

Thanks, I'll try that! How does it play with pods? I would like to use lispyclouds/docker but my guess is that (require '[pod.lispyclouds.docker :as docker]) will never be accepted by cursive because the dependency from clojure should be: [clj-docker-client.core :as docker] .

borkdude09:02:33

@beltramo.ale If you use the babashka nREPL server you can get auto-completions for this, but pods aren't dependencies that can easily be statically analyzed

ABeltramo09:02:56

Right, I see.. Is there a better IDE for developing babashka scripts? What do you guys use then?

Eamonn Sullivan09:02:17

I'm trying to run an nrepl (`bb --nrepl-server 1667`) with cider in emacs. This seems to work fine, usually, but this morning the repl just dies silently when I try to eval a buffer. I'm sure it's just an error in my code, but I don't get any error messages (either on the bb side, nor on the cider side). Is there a way to see what's going wrong? I tried --verbose with no result.

Eamonn Sullivan09:02:56

Ah, I see what's happening. I'm trying to eval the whole buffer, so it's running the code and spitting out a usage message (i.e., because I don't have the required args). I didn't spot that amidst the "closed unexpectedly" message from cider.

grazfather15:02:36

Should that cause the nrepl to crash, though?

Eamonn Sullivan15:02:17

Nah, just exit normally, with a usage. Cuz that's what I asked it to do. I rewrote the script to have a -main function and then did something like this

(when (= *file* (System/getProperty "babashka.file"))
  (-main))
So now I can eval the whole buffer and use the functions, but the script itself doesn't run.

grazfather15:02:56

Ah, makes sense

borkdude09:02:17

I use emacs

borkdude09:02:41

@beltramo.ale Developing bb scripts should not require a lot from an editor. Just paredit + syntax highlighting maybe. Bb scripts start so fast that you usually barely need a REPL, although many people do prefer one.

borkdude09:02:37

If IntelliJ / Cursive gives you trouble for developing a script, maybe discuss it with the author to add better support for it.

solf09:02:32

Here's the commands I made to spawn and connect to a babashka repl, from emacs/CIDER: https://gist.github.com/llacom/f391f41cbf4de91739b52bf8bb1a6d54

solf09:02:05

I meant to improve them before sharing, but never took the time. It works for me at least :man-shrugging:

ABeltramo09:02:20

Yeah I just saw https://github.com/cursive-ide/cursive/issues/2452 the issue is that since it can't recognise imports just set everything as errors and it's unusable. I'm trying calva and it seems to do the trick. Thanks for the help, and the amazing work behind Babashka!

pez10:02:08

Calva uses both clojure-lsp and nrepl for the completions. And clojure-lsp also makes a lot of other features available. You can probably get a lot of the similar experience in Emacs using CIDER + lsp-mode. But with Calva it is out-of-the-box. Not possible to opt-out, even . 😃

Mno10:02:43

“Oh no I can’t opt out of this very helpful feature”. Now that’s the kind of problems I want.

borkdude10:02:05

I think it's good to have opinions (defaults), but not to be stubborn: always give people a way out, unless your tool can't function without it

David Pham12:02:33

It might not be the right place, but is there any magic trick to have pprint with cider using bb --nrepl-server ?

grazfather23:02:24

it’s merged in now! just update your bb

borkdude12:02:53

@neo2551 There is an open PR for this in babashka.nrepl which is currently stalled. Maybe you could help out by reading the issue and seeing what remains to be done.

borkdude12:02:19

I think it's more or less done

David Pham12:02:21

Thanks! I believe you are too nice with respect to my skills!

David Pham12:02:43

But I will give a shot tomorrow.

David Pham12:02:59

Thanks for pointing me out to the solutoin.

Eamonn Sullivan17:02:49

So, I finished my first moderately-sized https://github.com/eamonnsullivan/backup-scripts/blob/master/src/eamonnsullivan/backup.clj. It will probably make any competent babashka user's eyes bleed, is basically a translation of a bash script, but it was fun to do. I originally had more actual Clojure (as opposed to calls to clojure.java.shell) in it, but I stripped that back after I basically wiped a PC while trying to test it. 😮 (The problem turned out to be an incorrect exclude to rsync, so I was copying over a symlink to / and when I tried to remove the directory using pure and naive Clojure, it went down that rabbit hole.) I am definitely hooked!

👍 4
borkdude17:02:08

@eamonn.sullivan Looks like a legit script to me! Great job and hope you have recovered from your disk erasure well