Fork me on GitHub
#calva
<
2024-02-09
>
Karol Wójcik15:02:13

How to make the macro to be treated like a defn and indented as such?

pez16:02:28

You need to create clj-kondo linter config, and cljfmt config. (The above link should point you to the latter.) For the former it will be something like:

{:lint-as {your.namespace/your-macro clojure.core/defn}}

Karol Wójcik16:02:26

Hmm, this doesn't work with: fulcrologic.guardrails:

(ns guardrails.core
  (:require
   [com.fulcrologic.guardrails.core :as gr]))


(gr/>defn ranged-rand
          [start end]
          [int? int? | #(< start end) => int? | #(>= % start) #(< % end)]
          (+ start (long (rand (- end start)))))

Karol Wójcik16:02:02

.lsp/config.edn

{:cljfmt
 {:indents {com.fulcrologic.guardrails.core/>defn [[:inner 0]]}}}

Karol Wójcik16:02:28

Calva version used: v2.0.410
clojure-lsp version used: 2024.02.01-11.08.46-nightly
clj-kondo version used: 2023.12.15
clojure-lsp version used: 2024.02.01-11.08.46-nightly
clj-kondo version used: 2023.12.15
clojure-lsp version used: 2024.02.01-11.08.46-nightly
clj-kondo version used: 2023.12.15

pez16:02:28

What’s your calva.fmt.configPath setting?

pez16:02:36

Regarding linter config for Guardrails, I think you won’t need to add. Iirc it is provided by the library.

Karol Wójcik16:02:04

I don't have it set.

Karol Wójcik16:02:04

Removing the configs doesn't help either.

pez19:02:34

If you don’t have the path set you should place the file in the project root.

Karol Wójcik20:02:54

I’ll make a repro

pez21:02:14

I think it will work placing the config at .cljfmt.edn and at the root of the config map:

{:indents {com.fulcrologic.guardrails.core/>defn [[:inner 0]]}}

pez22:02:43

Unless you have reasons to host the formatter config with clojure-lsp. If so you need to set the cljfmtPath to CLOJURE-LSP, per instruction at: https://calva.io/formatting/#providing-configuration-via-clojure-lsp

Karol Wójcik10:02:23

Hey @U0ETXRFEW! Thank you so much for all the support. Could you kindly check this repro: https://github.com/FieryCod/calva-repro?

pez11:02:28

Thanks! I can’t reproduce the problem. I know you say you haven’t set your calva.fmt.configPath, but I suspect it is set to something. Maybe try resetting it?

Karol Wójcik12:02:51

Thanks @U0ETXRFEW. Tried doing that, but no luck. On fresh profile with just Calva >defn is not correctly formatted either.

Karol Wójcik12:02:14

I can confirm that using regular cljfmt the code is formatted correctly. Where does calva store cljfmt binary?

pez14:02:30

The rule needs to match the symbol fully. So if you are sometimes using it unqualified and sometimes qualified, you may be better suited with a regex:

:extra-indents                   {#re "/?>defn" [[:inner 0]]}
 :test                            (comment
                                    (com.fulcrologic.guardrails.core/>defn hello []
                                      {:a   a
                                       :aa  a
                                       :bbb bbb})
                                    (>defn hello-again []
                                      {:a   a
                                       :aa  a
                                       :bbb bbb}))
Calva only formats the current parent form, so cljfmt does not get to do its magic with figuring things out from the ns form. Calva doesn’t use a separate binary. We’re using cljfmt as a library.

pez14:02:48

It will of course first take that we get any rule to work. I don’t understand what goes wrong for you. Maybe it’s more effective we share screens and investigate together. Let me know if that works for you.

Raghav21:02:51

silly question but is it possible to move and use the repl down from the terminal tab section?

seancorfield21:02:37

Can you explain what you mean? The Calva REPL is a "file" editor. Terminals are separate things.

Raghav21:02:30

Yes, that's what I mean. In vscode, I want to access the repl from the section where the terminal tab resides.

Bob B21:02:35

Not currently possible, though there were some discussions around a change to the way the REPL outputs: <https://github.com/BetterThanTomorrow/calva/discussions/2238>. At the moment, the arrangement you have there is probably the closest it'll get (not sure if it's possible to split a file and the terminal window on the bottom "row")

pez21:02:26

VS Code is quite stupid with how it allows things to be placed.

seancorfield21:02:42

You can move Terminal tabs and other windows around

seancorfield22:02:23

Here I have the Calva says terminal window and the REPL in the bottom chunk of the screen:

seancorfield22:02:53

(I usually have them both on the right hand side, but moved them down to show you it is possible)

seancorfield22:02:45

This is my usual setup:

seancorfield22:02:51

Well, my usual setup has two Portal windows on the right. Top-right is tap> output and usually the REPL tab. Bottom-right is the middleware/logging Portal window and at least one Terminal for running builds etc.