Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format clojure files with babashka shebang #2218

Closed
jakepearson opened this issue Jun 12, 2023 · 13 comments
Closed

Format clojure files with babashka shebang #2218

jakepearson opened this issue Jun 12, 2023 · 13 comments

Comments

@jakepearson
Copy link
Contributor

I noticed that if I have a babashka shebang on the top of a Clojure file, it is not formatted with Calva. I started with cljfmt, and it turns cljfmt is working (weavejester/cljfmt#306) and will format the file via command line so I think there is something with Calva. To reproduce create a Clojure file with the following contents:

#!/usr/bin/env bb

(ns fmt-test)

(def data
  [{:name "a"}
        {:name "b"}
   {:name "c"}])

I have format on save turned on so I expect b to line up with a and c on save. It does not, but if I comment out the shebang at top the and save, the formatting happens. Is there a setting that I need to change? If this is a bug, I would be happy to work on it if someone can point me in the right direction.

Thanks for the great tool!

@PEZ PEZ added the formatting label Jun 12, 2023
@PEZ
Copy link
Collaborator

PEZ commented Jun 12, 2023

Hi! Thanks for reporting!

I can't reproduce the problem. Format on save happens with or without the shebang...

@bpringe
Copy link
Member

bpringe commented Jun 13, 2023

I also tried and cannot reproduce. Maybe take a look at the values you have for other settings, @jakepearson. I suppose there's also a chance another extension could be interfering.

@jakepearson
Copy link
Contributor Author

Thanks for trying. I'll fiddle around in vscode a bit. Is there a way to show what the formatted is doing in one of the output windows?

@PEZ
Copy link
Collaborator

PEZ commented Jun 13, 2023

Is there a way to show what the formatted is doing in one of the output windows?

There's is no diagnostics for the formatter.

The combination of settings that could be involved is pretty huge. If you haven't been using VS Code Insiders, a way to approach this ”from the other end” is to install it, enable format-on-save, install Calva and see if it still happens. Then, if not, see if pasting your settings json from regular VS Code into that of Insiders provokes it. If that fails, it could be some other extension at play. VS Code has a feature Extension Bisect, that you can reach from the Extensions pane's top meatballs menu. It could potentially help.

@jakepearson
Copy link
Contributor Author

Thanks for the ideas. I'll try it later today.

@jakepearson
Copy link
Contributor Author

jakepearson commented Jun 13, 2023

I did more digging and was able to figure it how to re-pro. If I start with a totally blank project and vscode with just calva installed, the formatter works. But if I add in a cljfmt.edn file set to

{:align-associative? true}

and set "calva.fmt.configPath": ".cljfmt.edn" in my workspace settings the file will not format. If I change :align-associative? to false it will format.

Ideas?

@PEZ
Copy link
Collaborator

PEZ commented Jun 13, 2023

Good hunting!

It's probably that the ancient version of cljfmt that is used for align-associative does not format files starting with a shebang.

@jakepearson
Copy link
Contributor Author

Is there anything I newcomer like myself could do to try to fix this?

@PEZ
Copy link
Collaborator

PEZ commented Jun 13, 2023

I totally appreciate that attitude, @jakepearson. First I want to say that I wish we didn't have the align-associative feature in Calva. I put it there by sheer enthusiasm way back when, and have chosen not to remove it, because I know some people like it and are OK with it not being perfect. If you didn't know, there is an on-demand way of invoking the alignment formatting. So I suggest you do not use that setting.

But, if you want to use it, I am not one to stop you. 😄 If you want to fix this particular issue, I think you could maybe find the commits that fixed the issue in cljfmt and apply them in the old copy of cljfmt that Calva uses for supporting the alignment feature:

https://github.com/BetterThanTomorrow/calva/blob/dev/src/cljs-lib/src/pez_cljfmt/core.cljs

I'd accept a PR doing this.

That said, there are more issues with the ancient cljfmt version, and we're not exactly planning on addressing them.

BTW, maybe it is not fuly clear: For non-alignment formatting we are depending on a recent version of cljfmt. The ancient copy is only for supporting this alignment feature.

@bpringe
Copy link
Member

bpringe commented Jun 14, 2023

FYI, I see there's been work on adding support for aligning associative forms to cljfmt as recent as 3 days ago: weavejester/cljfmt#299. 👏 👏 👏

Maybe soon we can git rid of Calva's modified old version.

@PEZ
Copy link
Collaborator

PEZ commented Jun 14, 2023

Awesome. I've been following that thread a bit. Let's hope it reaches the trunk this time!

@jakepearson
Copy link
Contributor Author

I love the look of align associative, but also didn't realize until this morning that it wasn't part of cljfmt's core feature set (I must have copied my cljfmt config from somewhere in calva's documentation). I'm going to drop it from my team's shared config and will hopefully get to put it back on based on the work going on in cljfmt. Thanks for the great support and for the great product!

@PEZ
Copy link
Collaborator

PEZ commented Jun 18, 2023

You're welcome, @jakepearson!

Closing this, because it is a bit hard to take any action on. Let's hope cljfmt proper will add support soon.

@PEZ PEZ closed this as completed Jun 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants