Fork me on GitHub
#calva
<
2022-11-25
>
skylize03:11:05

Weird formatting behavior with defprotocol when docstrings are on a separate line from method name. I don't know whether it's worth worrying about. But it feels janky (and unpredictable until putting a lot of thought into understanding it). 🧵

skylize03:11:08

• While typing, the docstring aligns with the parameters. • If the cursor is anywhere within the parentheses that wrap the method definition, then calva-fmt.formatCurrentForm follows the same rule, and aligns the docsctring to the params. • This only applies to the method expression the cursor is inside of. Move the cursor inside a different method expression, and run calva-fmt.formatCurrentForm to also format that form as described above, not effecting alignment of any other method. • Move the cursor to where it is outside of any method expression and run calva-fmt.formatCurrentForm and a different rule takes over. All the docstrings align to the second character of the respective method name. • Same with other format-triggering events (such as paredit.dragSexpForward). So long as the cursor is not within an expression defining a method, all the docstrings align to a +2 character indentation.

; | for cursor

(defprotocol Foo
  (method [_] |"docstring"))

; <Enter>
(defprotocol Foo
  (method [_]
         |"docstring"))

; <calva-fmt.formatCurrentForm>
(defprotocol Foo
  (method [_]
         |"docstring"))

; <move cursor>
(defprotocol Foo
 |(method [_]
          "docstring"))

; <calva-fmt.formatCurrentForm>
(defprotocol Foo
 |(method [_]
    "docstring"))

; <move cursor>
(defprotocol Foo
  (|method [_]
     "docstring"))

; <calva-fmt.formatCurrentForm>
(defprotocol Foo
  (|method [_]
           "docstring"))

bringe23:11:12

I wonder if maybe formatCurrentForm doesn’t have knowledge that the “current form” is inside a defprotocol form when the cursor is inside the method form… An issue is welcome. @U0ETXRFEW might have an idea what’s going on.

Madara Uchiha09:11:53

With calva, I have something like

[:div {:style {:color "red"}} [:span ;; resumes below
And I want to make it so it's
[:div {:style {:color "red"}}
     [:span ;; resumes below
When I just hit enter, I get
[:div {:style {:color "red"}}]
[:span ;; resumes below
Which seriously screws up the rest of the brackets down the line and does crazy things. how do I get the result I want?

orestis09:11:26

What happens if you press tab? You might need to go to a level above but it usually fixes all indentation issues.

Madara Uchiha09:11:01

It already changes the brackets so that it becomes a top level form, TAB doesn't fix it

pez09:11:53

Never seen this. Which versions of VS Code and Calva are you using, @U24MDANHY? Can you reproduce it in all files, or is it only in some?

Madara Uchiha09:11:13

It happened to me every single time for every clojure file I ever cared to open/edit

Madara Uchiha09:11:51

vscode 1.73.1 on ubuntu Not sure how to see the calva version (thanks vscode) - but it's supposedly the latest in the vscode store or whatever, I haven't held it back or anything, and it doesn't tell me to update it

pez09:11:04

What's your VS Code settings for on-type formatting?

Madara Uchiha09:11:58

disabled, but it does tell me it's (Modified elsewhere) and when I hover it tells me that Clojure has different defaults

pez09:11:07

Calva reports it version in the Output pane Calva says. Also Clicking the Calva entry in the Extensions pane should show it.

Madara Uchiha09:11:29

Calva version used: v2.0.320
clojure-lsp version used: 2022.11.03-00.14.57
clj-kondo version used: 2022.11.02

🙏 1
pez09:11:34

Can you try enable it?

Madara Uchiha09:11:55

Enabled, still not working

Madara Uchiha09:11:02

Hold on, posting a screencast

pez09:11:39

Do you use some other Clojure extension?

Madara Uchiha09:11:06

Well, Peek segfaults so no screencast for us 😞

Madara Uchiha09:11:28

I don't, but I do use a nontrivial amount of extension, it's not impossible that there's a collision of some sort

pez09:11:41

There's an extension named Chronicle which is excellent for recording VS Code.

Madara Uchiha09:11:42

Prettier is disabled on cljs files

pez09:11:50

Can you try if you have the same issue in VS Code Insiders?

pez09:11:04

Are you using VIM?

pez09:11:28

(The extension)

Madara Uchiha09:11:37

I do not

🙏 1
pez09:11:44

Please file an issue using VS Code's Help-menu item for it. It will attach some system information and such.

pez09:11:05

> It already changes the brackets so that it becomes a top level form, TAB doesn't fix it This is a clue I think. I have never seen Calva do this, and am thinking it could be some other extension at work. Could of course also be a Calva bug.

pez09:11:42

A broken Parinfer extension could do something like that maybe...

Madara Uchiha09:11:47

It should be noted that I have "Parinfer </> Smart" mode enabled, it might have something to do with it

pez09:11:18

That's probably it.

Madara Uchiha09:11:58

Yeah, in paren mode it works

pez09:11:34

So it's an issue with that extension. There's a #C0F2A0MJN channel where you can ask about it.

Madara Uchiha09:11:31

I should really get more into paredit and put parinfer behind 😢 - but it's too different from what I know and it's a lot of things to learn at once 😅

pez09:11:17

😃 You can have paren mode enabled and learn Paredit in your own pace.

pez09:11:28

The issue is very unlikely to be fixed anytime soon. No-one knows how to implement Parinfer smartmode on VS Code. I have been the closest, I think, but had some other problems with that so had to pause that work.

Madara Uchiha09:11:20

:saluting_face: Thank you for your work, just being able to properly edit clojure in vscode makes it so much more accessible ❤️

🙏 1
pez10:11:46

You are welcome, @U24MDANHY! ❤️

pez12:11:14

Here's another event that might interest Calva friends: https://www.meetup.com/london-clojurians/events/286030325/

sheepy 6
❤️ 2