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?
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
I mean bb print-deps --format classpath works without a bb.edn, so..
It could work (if clojure-lsp supported it)
true, but clojure-lsp looks for a project file, like deps.edn or bb.edn to decide what is the root of a project
you could at least just run clj-kondo in a file without clojure-lsp as an intermediate solution
Many times, i implement babashka scripts in various git repositories, so it could fallback to this as a project root?
if you have a project, you can configure clojure-lsp yourself too
outside of the automatic detection
(I'm pretty sure it currently autodetects and picks .git repo root as project root, it just doesn't use it for classpath population)
So far the simplest way seems to be 'just touch bb.edn' in the root of your repo
yep, why not
(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)
discuss with Eric I'd say
ok, I'll wait to see if he responds here 🙂
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
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
@ericdallo fyi, I opened an issue to formally track the above request here: https://github.com/clojure-lsp/clojure-lsp/issues/2199
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?That's the one! Thank you!
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
I guess zloc is nil here?
not sure why, I'd have to look into it later
Would you like me to file an issue?
I guess I found it:
<forms: {:items [{:x 1} {:x 2} {:x 3} 2 {:x 42}]}>by luck
Damn you're quick! 🤩
hmm, no to soon. somehow a 2 gets inserted
I guess update* assumes a map
let me try to quickly fix it...
try v0.5.0
Will do! Thanks!
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?
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
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
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
here is the issue https://github.com/babashka/babashka/issues/1907
did you change your username?
haha, yes