Fork me on GitHub
#calva
<
2023-05-02
>
seancorfield18:05:06

At some point in the past, Calva used to indent docstrings like this:

(defn foo
  "This is line one<press enter here>
  and this is where line two was placed automatically."
  [args]
  ..)
but these days you get the following:
(defn foo
  "This is line one<press enter here>
and this is where line two was placed automatically."
  [args]
  ..)
I've gotten used to just pressing <space> twice after a newline in a docstring but is there a config to get the old behavior back?

pez18:05:03

We don’t have a setting for it. We could add that. Please file an issue!

sergey.shvets18:05:42

I will be second to prefer older behavior.

bringe18:05:07

I wonder if some configuration is causing that for you. For me I get the expected/desired behavior. When I press enter in the below after “doc”, my cursor lands where noted.

(defn hello
  "some doc
   |")

seancorfield18:05:08

@U9A1RLFNV Yeah, I have to assume it's something in my setup that maybe I accidentally changed, but I'm not sure what controls that indentation so I don't know where to look to fix it...

seancorfield18:05:31

(and I wasn't sure if there was an intentional change in Calva's behavior here or not)

pez18:05:25

I wonder what could be going wrong…

bringe18:05:29

No intentional change that I know of. If you’re using cljfmt indent config then you may want to check there, otherwise check other Calva settings. I don’t know off hand what might be affecting that.

bringe18:05:37

I guess there’s a chance another extension could affect that too.

pez18:05:37

There’s a conflict with the VIM extension with similar effect, but I think that if Sean was a VIM extension user we would have known. 😃

seancorfield18:05:03

How do you know if someone is a VIM user? They'll tell you! (variant on the vegan joke)

4
😄 2
seancorfield18:05:37

So I have "Calva › Fmt: New Indent Engine" unchecked, which should use cljfmt then... but cljfmt isn't on my path so I assume that's someone Calva handles internally?

pez18:05:42

cljfmt is used as a library by Calva, yes. Might be that with cljfmt you get that behaviour, though. cljfmt does not format inside strings…

pez18:05:18

No, I get the same behaviour with both indent methods…

seancorfield18:05:08

I get this "wrong" docstring indentation in new projects too, so it's something in my global VS Code/Calva config I guess...

seancorfield19:05:41

Could prettyPrintingOptions be affecting this?

pez19:05:14

Nope. It’s probably some other extension.

seancorfield19:05:53

Yup! Another extension! Thank you. The CFML language extension... which I still sort of need for one project but I wouldn't have expected it to mess with Clojure formatting 😞

pez19:05:01

To try track this down we could think a bit about the mechanics involved. When you hit enter, VS Code will create a new line and place your cursor somewhere on that new line. I think that by default it will be column 0. Then it is up to the language configuration. VS Code has a default language configuration for Clojure, but with Calva installed, that is overridden. Iirc we don’t change anything around this so there will be some sort of default indentation. Then extensions might fiddle with it. Calva is one of those,

seancorfield19:05:12

Oh, two extensions maybe... Auto Close Tag also seems to affect this...

pez19:05:26

Since cljfmt does not format inside strings, wherever the cursor ends up, it will stay.

seancorfield19:05:35

Hmm, nope, uninstalled two extensions and reloaded and it's still broken...

pez19:05:18

There is an extension bisect function in VS Code. You’ll find it in the meatballs menu at the top of the Extension pane.

seancorfield19:05:29

In the [clojure] section of my settings, I have "editor.autoIndent": "advanced", -- what would you recommend for that?

seancorfield19:05:14

I switched to the New Indent Engine which gives me this:

(defn foo
  "Hello,
   World!"
  [])
with the W under the H instead of under the " which I don't like but can maybe live with (it's one backspace instead of two spaces to "correct" it).

pez19:05:13

That’s interesting, with cljfmt I get the behaviour you want and with new indent engine I get the same as you get there. That probably means that the new indent engine has some opinion about strings.

pez19:05:41

(Per my reasoning around the mechanics, above).

seancorfield19:05:52

I wonder why I'm getting different behavior to you with cljfmt?

seancorfield19:05:36

I'm happy to use the NIE for now but an option to tweak that "opinion" would be nice 🙂

seancorfield19:05:11

I don't know whether it already has any user-accessible settings to tweak indent behavior?

pez20:05:00

It reads the cljfmt config and tries to indent the same as cljfmt, is all.

pez20:05:43

> In the [clojure] section of my settings, I have "editor.autoIndent": "advanced", -- what would you recommend for that? I forgot to comment on this. I didn’t even know you could set it to advanced. Did you test to remove this setting to see if that was tripping the cljfmt indent?

seancorfield20:05:40

Confirmed that makes no difference to either new/old fmt engines for this docstring issue.

🙏 2
seancorfield18:05:45

(and I mean "indent .. while typing new code and pressing enter for each new line of code")