Fork me on GitHub
#calva
<
2023-08-14
>
Ingy döt Net15:08:02

Not a big deal but getting red squigglies here because the symbols aren't real, they get transformed in the macro. Is there a way to tell calva not to resolve symbols for a macro call?

👍 2
pez15:08:01

It’s #clj-kondo doing the linting and it’s quite configurable: https://github.com/clj-kondo/clj-kondo/blob/master/doc/config.md Since you are in control of the macro definition you might want to try Inline macro configuration there.

👍 2
sergey.shvets01:08:38

Something like this will do the trick. Replace yournamespace with a proper one.

:linters {:unresolved-symbol {:exclude [(yournamespace/mark-get [Start Line Column End Index])]}

Ingy döt Net01:08:40

@U4EFBUCUE thanks, I'll try it out soon

bringe15:08:45

Since Calva updated cljfmt's version, a coworker of mine and myself noticed a change in indentation, which we've seemed to have fixed by changing :indents in our cljfmt config file to :extra-indents . CC @pez

bringe15:08:47

I went back to the previous Calva version to verify that the issue didn't occur there.

bringe15:08:48

Seems related to this change in 0.11.1 of cljfmt: > • Breaking change: split :indents into :indents and :extra-indents

bringe15:08:49

@pez We might need to update Calva's docs here: https://calva.io/formatting/#indentation-rules.

lread15:08:57

Was that change indentional? Yes, yes, it was. (apologies, I can't help myself).

😂 4
pez15:08:19

I couldn’t help myself either https://github.com/BetterThanTomorrow/calva/pull/2275 (Though that was completely unindentional.)

😄 4
bringe15:08:29

But maybe that usage of :indents in our docs is still valid. In our work project we have custom macro indent rules in :extra-indents.

pez15:08:22

I think a note in the docs (and here) about what to do in a situation like you encountered would be good, @U9A1RLFNV. It’s not clear to me from the changelog entry there…

👍 2
pez16:08:58

Also, how does the Calva indenter cope with this?

bringe16:08:51

Well, when we still used :indents how it used to be used, formatting a file would cause the indentation to look pretty off, I think because we were blowing away the default indent rules provided by cljfmt (with the new version).

bringe16:08:13

> The :indents key has been split into :indents and :extra-indents. The :indents key replaces all default indents, while the :extra-indents key will append to the default indents.

pez16:08:15

Thanks for the link to the info. It seems it is the ^:replace metadata that is replaced with this notation.

👍 2
pez16:08:15

To be clear about “the indenter”. It’s separate from the formatter, but reads the same configuration. It doesn’t know about this :extra-indents thing, and will not replace all default indents for the :indents key. Basically it will behave as if :legacy/merge-indents? true is used…

pez16:08:50

I think we need to do more than just update documentation…

pez16:08:29

I’ll have a look at this tonight. I think I understand the issue now. (Even if I am a bit worried that I haven’t since the ^:replace metadata thing is not mentioned in that update.) Quite unusual with breaking changes like this in Clojure land! It’s no excuse, of course, completely my fault that I overlooked this… But I think it shouldn’t be too hard to fix. This new config makes sense.

Ingy döt Net22:08:08

I made a .cljfmt.edn file with

{:extra-indents #{:closure-fn :closure-params}
}
in it. but I'm not sure how to check in calva for its effects

Ingy döt Net22:08:25

can someone give me a simple thing to try?

Ingy döt Net22:08:35

also the file it in the project root dir, but that's not the git repo root dir

bringe00:08:43

Yeah you can try out the indentation rules in the cljfmt file since Calva will format it. Make sure you tell Calva to use your file if you haven't yet with this VS Code setting:

"calva.fmt.configPath": ".cljfmt.edn",

bringe00:08:56

But make sure your path is correct for your file and project

bringe02:08:37

About to eat dinner here but shoot a question if you got one.

Ingy döt Net02:08:06

Mind looking at a repo to see what I'm doing wrong? It's driving me nuts :)

Ingy döt Net02:08:36

I'm using the repo top level dir as my workspace in vscode (that's the folder I'm opening at least so I assume vscode thinks it's the workspace)

bringe03:08:55

Mind if I take a look tomorrow, if someone else doesn’t get to it by then? I’ll set a reminder. Thanks for the repo too. That helps.

Ingy döt Net03:08:37

Yeah, its not very important.

pez07:08:47

@U05H8N9V0HZ I can’t reproduce the problem with reformatting. The :test-code does not use your rules, though… If I use test code that does, it is reformatted as I expect:

{:extra-indents
 {use-subscribe      [[:inner 0]]
  use-event-listener [[:inner 0]]
  $                  [[:inner 0]]}
 :test-code
 [(use-subscribe foo
    x)
  (concat [2]
          (map #(inc (* % 2))
               (filter #(aget sieved %)
                       (range 1 hn))))]}
However, you are also running into this issue: https://github.com/BetterThanTomorrow/calva/issues/2280 That is, the indenter is not reading :extra-indents, even if the formatter is. Which adds to the confusion.

pez17:08:29

Dear Calva friends: https://github.com/BetterThanTomorrow/calva/releases/tag/v2.0.384https://github.com/BetterThanTomorrow/calva/issues/2278 This makes Calva more resilient (and less confusing) to when there are problems with clojure-lsp binary downloads.

bhurlow18:08:03

not sure if this is universal to other users, but I found my default indentation was incorrect until I swapped :indents for :extra-indents

seancorfield18:08:21

I rolled back to an earlier Calva version while I figured that out so thank you for the hint!

👏 2
seancorfield18:08:03

I have LSP provide the config and it doesn't have :indents or :extra-indents in config.edn so... not quite sure what I need to do to fix this?

pez19:08:51

What is the problem you are experiencing @U04V70XH6?

seancorfield19:08:57

@pez Exactly that problem: indents are broken. But I don't have a cljfmt config file -- I have it configured to pull from LSP -- and the LSP config.edn doesn't have any :cljfmt overrides in it.

seancorfield19:08:50

Oh wait... I do have a .cljfmt.edn file in my home folder... Let's see.

pez20:08:18

Indents are broken how? I need more clues. 😃

seancorfield20:08:09

It's because any local customization replaces all the defaults in cljfmt if you have :indents so every form indents like a function:

(defn foo
      "docstring"
      [args]
      (body))

seancorfield20:08:51

I had a single rule for expecting (from Expectations) and now I've changed it from :indents to :extra-indents everything works on the latest Calva/cljfmt.

pez20:08:49

Thanks for confirming that. Can you also try to instead set :legacy/merge-indents? true in the config and keep :indents?

seancorfield20:08:50

Like this? Doesn't seem to work:

{:legacy/merge-indents? true
 :indents {expecting [[:inner 0]]}}

seancorfield20:08:09

Indentation:

(defn subject
      "Given start time, end time, and alert subjects,
  return subject of email."
      [start-time end-time alert-subjects]
      (str "[Alerts] " alert-subjects " from " start-time " to " end-time))

seancorfield20:08:34

I'll try that again later to be sure (I have to restart Calva each time to be sure). Lunch here.

pez20:08:33

I can reproduce it. Smaklig spis!

seancorfield20:08:44

> Smaklig spis! Thank you! It was avocado toast -- I'm so Californian! 🙂

🥑 4
seancorfield18:08:03

I have LSP provide the config and it doesn't have :indents or :extra-indents in config.edn so... not quite sure what I need to do to fix this?

pez21:08:15

Dear Calva friends: With v2.0.382 of Calva comes a https://github.com/weavejester/cljfmt/blob/master/README.md. If you have been adding indentation rules to the defaults using :indents, you now should be using :extra-indents instead. Please see the note about this in the docs: https://calva.io/formatting/#indentation-rules

👍 2
Ingy döt Net22:08:10

I'm getting no joy with :indents or :extra-indents I'm not sure I have things configged right. Can someone point me at an example .cljfmt.edn file using :extra-indents ? Also I can't figure out how to press tab to reformat an entire form as suggested here: https://calva.io/formatting/#indentation-rules Do I need to highlight the form? Help!

Sam Ferrell22:08:15

Heres my own .cljfmt.edn with the recently updated name

{:extra-indents
 {use-subscribe      [[:inner 0]]
  use-event-listener [[:inner 0]]
  $                  [[:inner 0]]}}

Sam Ferrell22:08:03

With the new name the formatting works properly again

Ingy döt Net00:08:23

@U02FVPF04A1 thanks. I'm new to Calva and I'm not sure how to go about reformatting (indentation) a set of lines. The code section a bit down from https://calva.io/formatting/#indentation-rules says "Save, then hit tab, and the code should get formatted like so:" but hitting the tab key does nothing for me. Where should my cursor be or what should be highlighted when I hit tab?

Ingy döt Net00:08:46

ok, I get it. when i made the indent wacky on all the indented lines, hitting tab anywhere in the form reformatted things.

Ingy döt Net00:08:14

I think it's just my .cljfmt.edn file is in the wrong place, because it's using the old style