babashka

agorgl 2026-01-06T09:29:59.456509Z

Hello! I'm frequently implementing ad-hoc babashka scripts in various locations (as replacements to bash scripts). I noticed that when creating a script that doesn't have a bb.edn in some parent folder above it, clojure-lsp does not work as expected (for function completion at least). Is there any way to make babashka scripts work globally with clojure-lsp, without requiring them to be in a repo/with a bb.edn on their side?

borkdude 2026-01-06T09:48:56.337159Z

clojure-lsp works with the concept of a project and this needs some place where it can find the dependencies for a project. I don't know how this would work for single scripts, but perhaps clojure-lsp could still offer diagnostics etc without scanning for dependencies. cc @ericdallo

agorgl 2026-01-06T09:58:18.213099Z

I mean bb print-deps --format classpath works without a bb.edn, so..

agorgl 2026-01-06T09:58:27.736899Z

It could work (if clojure-lsp supported it)

borkdude 2026-01-06T09:58:55.924319Z

true, but clojure-lsp looks for a project file, like deps.edn or bb.edn to decide what is the root of a project

borkdude 2026-01-06T09:59:29.263089Z

you could at least just run clj-kondo in a file without clojure-lsp as an intermediate solution

agorgl 2026-01-06T10:00:34.472839Z

Many times, i implement babashka scripts in various git repositories, so it could fallback to this as a project root?

borkdude 2026-01-06T10:01:11.218539Z

if you have a project, you can configure clojure-lsp yourself too

borkdude 2026-01-06T10:01:18.133529Z

outside of the automatic detection

agorgl 2026-01-06T10:01:31.512619Z

(I'm pretty sure it currently autodetects and picks .git repo root as project root, it just doesn't use it for classpath population)

agorgl 2026-01-06T10:03:02.408989Z

So far the simplest way seems to be 'just touch bb.edn' in the root of your repo

borkdude 2026-01-06T10:03:22.148129Z

yep, why not

agorgl 2026-01-06T10:07:00.525129Z

(would love a more auto way to do this though, like a heuristic to check if the current file is a standalone babashka script (check #!/usr/bin/env bb shebang?) and just run the bb print-deps --format classpath command there)

borkdude 2026-01-06T10:07:12.557669Z

discuss with Eric I'd say

agorgl 2026-01-06T10:07:47.335629Z

ok, I'll wait to see if he responds here 🙂

ericdallo 2026-01-06T12:02:37.772759Z

The thing is not know the project root, but know https://github.com/clojure-lsp/clojure-lsp/blob/c2126582f633d78b9fa751028a21e359b6527ce6/lib/src/clojure_lsp/classpath.clj#L183-L223 should we spawn, there are 5-6 kinds of clojure projects so we need to check which file exists to spawn a command, and could be multiple projects like deps.edn + bb.edn and we would spawn both commands

ericdallo 2026-01-06T12:12:47.786009Z

also the order of things is important for LSP, so initialize request which is the first one and the one that makes clojure-lsp spawn those commands and analyze classspath comes before didOpen to know which file was opened, so hard to tell too. It's not a trivial problem, but a problem indeed, feel free to open a iusse so we can think on something

agorgl 2026-01-06T19:29:56.719909Z

@ericdallo fyi, I opened an issue to formally track the above request here: https://github.com/clojure-lsp/clojure-lsp/issues/2199

jmglov 2026-01-06T10:18:21.395839Z

This is perhaps not directly Babashka-related, but I seem to recall borkdude having mentioned some tool that could update EDN whilst maintaining its formatting. For example, I have an EDN file like this:

{:items
 [{:title "foo"
   :author "Alice"}
  {:title "bar"
   :author "Bob"}]}
and I want to programmatically update the title in the Bob map such that my new EDN looks like this:
{:items
 [{:title "foo"
   :author "Alice"}
  {:title "bar is a lie!"
   :author "Bob"}]}
I could of course use (with-str (clojure.pprint/pprint m)) to do this, but then I'd be at the mercy of pprint possibly reordering my keys, inserting commas or other whitespace, etc, and I want to keep the diff small so that my git log makes sense. Is there a thing that can do what I need?

borkdude 2026-01-06T10:19:18.056019Z

perhaps https://github.com/borkdude/rewrite-edn?

💜 1
jmglov 2026-01-06T11:27:02.350989Z

That's the one! Thank you!

jmglov 2026-01-06T15:40:33.236169Z

I think I may have found an issue with rewrite-edn, but the issue may be PEBKAC. Am I holding it wrong?

(require '[borkdude.rewrite-edn :as r])

(let [nodes (-> {:items [{:x 1} {:x 2} {:x 3}]} pr-str r/parse-string)]
  (r/get-in nodes [:items 2 :x]))
;; => {:value 3, :string-value "3"}

(let [nodes (-> {:items [{:x 1} {:x 2} {:x 3}]} pr-str r/parse-string)]
  (r/assoc-in nodes [:items 2 :x] 42))
;; => java.lang.NullPointerException cljcastr.tasks borkdude/rewrite_edn/impl.cljc:193:15

✅ 1
borkdude 2026-01-06T15:57:57.127969Z

I guess zloc is nil here?

borkdude 2026-01-06T15:58:06.638869Z

not sure why, I'd have to look into it later

jmglov 2026-01-06T15:59:15.012149Z

Would you like me to file an issue?

borkdude 2026-01-06T16:08:30.713049Z

I guess I found it:

<forms: {:items [{:x 1} {:x 2} {:x 3} 2 {:x 42}]}>

🎉 1
borkdude 2026-01-06T16:08:38.280889Z

by luck

jmglov 2026-01-06T16:10:01.758979Z

Damn you're quick! 🤩

borkdude 2026-01-06T16:14:53.791169Z

hmm, no to soon. somehow a 2 gets inserted

borkdude 2026-01-06T16:15:53.510649Z

I guess update* assumes a map

borkdude 2026-01-06T16:17:41.457749Z

let me try to quickly fix it...

borkdude 2026-01-06T16:23:22.211359Z

try v0.5.0

1
jmglov 2026-01-06T16:23:46.448459Z

Will do! Thanks!

sg-qwt 2026-01-06T00:55:35.446399Z

Hi, wondering shouldn't built uberscript automatically default with empty BABASHKA_CLASSPATH or --config nil , since that uberscript usecase is used for self contained deployment script, which should not get confused by other bb.edn in running folders when running?

borkdude 2026-01-06T09:50:26.653459Z

I guess so but since currently an uberscript is just a script like any other script: a file with some code in it, bb doesn't have a way to recognize that it shouldn't look at project files

sg-qwt 2026-01-06T09:56:25.577079Z

Instead of wrapping every deploy bb script with empty BABASHKA_CLASSPATH, I wish we can have a flag to set, just like *file* , something like *ignore-config* so we can toggle that to true at beginning of deployed script

borkdude 2026-01-06T09:57:44.873339Z

Feel free to log an issue about this. What you are mentioning is a solution though, not a problem statement, so I think we should start the issue with the problem statement and then list some alternative ideas

👍 1
sg-qwt 2026-01-06T11:32:19.348419Z

here is the issue https://github.com/babashka/babashka/issues/1907

borkdude 2026-01-06T11:32:40.811729Z

did you change your username?

sg-qwt 2026-01-06T11:33:18.460189Z

haha, yes