Fork me on GitHub
#calva
<
2023-12-06
>
k3nj1g06:12:21

Why Calva is struggling with handle formatting hash-maps that contains namespaced keywords? Even if they were commented. For example, {:foo {:bar ::baz :batman :foz}}

seancorfield06:12:29

If you read the formatting docs, it says that the format and align command uses an old version of cljfmt that was patched to do the vertical alignment and that it is unsupported -- so I suspect the "old version of cljfmt that was patched" predates the more common usage of namespaced keywords that came in with Spec in Clojure 1.9 (despite it being supported for ages before that).

👀 1
pez07:12:40

Yes, if it’s the alignment command, this is why it struggles.

k3nj1g10:12:14

And there's nothing we can do about it?

k3nj1g10:12:43

Ok, I've done some research on this. Basically, the answer is here https://calva.io/formatting/#about-aligning-associative-forms

pez10:12:53

There is a PR on cljfmt about fixing alignment. https://github.com/weavejester/cljfmt/pull/299 As late as Oct 20, James Reeves says it is hight on hist priority list.

👍 1
ChillPillzKillzBillz16:12:53

Cross post from beginners...

phill16:12:10

Today I re-cloned a project in a new directory, hopped into Calva, and tried to start a Leiningen+Shadow REPL, but I got some errors about JS things not found. Well, I had neglected to "npm install" before using Calva; there was no node_modules. Can I configure the "npm install" to be done automatically?

pez17:12:19

Maybe there is some extension that does this. Calva does not have any such extension points. Though, there is custom command line for jack-in. So you if you use that you can do whatever you like.

Raghav17:12:12

Hello! Can anyone help me with this error?

Request workspace/executeCommand failed.
  Message: Internal error
  Code: -32603 
[object Object]
It occurs when I try to add a require via quick fix suggestion.

pez19:12:16

I don’t know what it could be about. I saw that @U9A1RLFNV filed a similar issue https://github.com/BetterThanTomorrow/calva/issues/2354 Maybe @UKFSJSM38 knows what Code: -32603 could mean?

bringe19:12:15

I'm not sure if those are related, aside from being internal clojure-lsp errors. I suspect the issue I filed is something Calva is doing wrong, but I'm not sure.

bringe19:12:40

@U05H1PF60G1 You might find more info in the clojure-lsp server logs that could help @UKFSJSM38 to troubleshoot.

bringe19:12:24

@U0ETXRFEW Our facilities for helping the user open the log file or see its path seem to be broken, at least for me on MacOS. I created this related issue: https://github.com/BetterThanTomorrow/calva/issues/2364.

🙏 1
Raghav20:12:48

2023-12-06T19:22:28.758Z  INFO [clojure-lsp.handlers:475] - :code-actions 87ms
2023-12-06T19:22:28.877Z  INFO [clojure-lsp.handlers:475] - :code-actions 3ms
2023-12-06T19:22:29.070Z  INFO [clojure-lsp.handlers:502] - :semantic-tokens-full 1ms
2023-12-06T19:22:29.739Z  INFO [clojure-lsp.handlers:385] - :clojuredocs-raw 0ms
2023-12-06T19:22:29.739Z  INFO [clojure-lsp.handlers:385] - :clojuredocs-raw 0ms
2023-12-06T19:22:29.937Z  INFO [clojure-lsp.handlers:475] - :code-actions 1ms
2023-12-06T19:22:30.099Z  INFO [clojure-lsp.handlers:302] - :document-highlight 0ms
2023-12-06T19:22:30.362Z  INFO [clojure-lsp.handlers:475] - :code-actions 1ms
2023-12-06T19:22:32.580Z  ERROR [clojure-lsp.server:55] - Error receiving message: Internal error (-32603)
{:id 6808, :method "workspace/executeCommand"}
com.oracle.svm.core.posix.thread.PosixPlatformThreads.pthreadStartRoutine  PosixPlatformThreads.java:  211
            com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine       PlatformThreads.java:  832
                                                     java.lang.Thread.run                Thread.java: 1583
                                                 java.lang.Thread.runWith                Thread.java: 1596
                       java.util.concurrent.ThreadPoolExecutor$Worker.run    ThreadPoolExecutor.java:  642
                        java.util.concurrent.ThreadPoolExecutor.runWorker    ThreadPoolExecutor.java: 1144
                   java.util.concurrent.CompletableFuture$AsyncSupply.run     CompletableFuture.java: 1768
                                                promesa.util.Supplier/get                  util.cljc:   34
                                            promesa.exec/wrap-bindings/fn                  exec.cljc:  163
                                                 clojure-lsp.server/fn/fn                 server.clj:  396
                                     clojure-lsp.handlers/execute-command               handlers.clj:  422
                                            clojure-lsp.handlers/refactor               handlers.clj:  397
                               clojure-lsp.feature.refactor/call-refactor               refactor.clj:  194
                                                                      ...                                 
                                          clojure-lsp.feature.refactor/fn               refactor.clj:   37
                                                       clojure.core/apply                   core.clj:  671
                                                                      ...                                 
           clojure-lsp.feature.add-missing-libspec/add-require-suggestion    add_missing_libspec.clj:  493
                  clojure-lsp.feature.add-missing-libspec/add-known-alias    add_missing_libspec.clj:  255
                 clojure-lsp.feature.add-missing-libspec/add-to-namespace    add_missing_libspec.clj:  241
                clojure-lsp.feature.add-missing-libspec/add-to-namespace*    add_missing_libspec.clj:  124
                                           rewrite-clj.zip.subedit/subzip               subedit.cljc:   76
java.lang.AssertionError: Assert failed: could not create subzipper.
                          zloc'

2023-12-06T19:22:32.588Z  INFO [clojure-lsp.handlers:475] - :code-actions 6ms
Thank you. Here are the clojure-lsp logs. I'm using via wsl (ubuntu).

Alexander Kouznetsov20:12:38

Is it hard to add a feature to sort map keys or sequence values alphabetically in the code? Example:

Sort sequence:
have:
:exclusions [d a c b]

want:
:exclusions [a b c d]

Sort map keys:
have:
:deps {d _d
       a _a
       c _c
       b _b}

want:
:deps {a _a
       b _b
       c _c
       d _d}
I gave deps.edn situations as examples but it applies to many more situations and the most annoying part is when values or keys are multiline, so I can’t resort to sorting lines.

pez20:12:09

I don’t think it’s too hard. But maybe we should check with #CPABC1H61 if they think it belongs there first. I don’t know if you know, but you can move map key value pairs with alt+up/down. For manual sorting.

🙌 1
seancorfield20:12:29

If it's a small map, I tend to reorder manually with alt+up/down since it knows to move pairs not individual items. If it's a larger map, I temporarily add a newline before the first key and after the last value and use the Sort Lines command, then tab to restore formatting.

🙌 2
pez20:12:04

In theory you could also wrap the map like so:

(into (sorted-map) '{d _d
                     a _a
                     c _c
                     b _b})|
(Cursor at |) Then do ctrl+alt+c r , (evaluate and replace with result).

🙌 1
pez20:12:11

I think that in practice, you might run into issues with pretty printing and namespaced keys stuff.

ericdallo11:12:42

That already exists in clojure-lsp, a command/code action called Sort clauses: https://clojure-lsp.io/features/#clojure-lsp-extra-commands

👀 1
❤️ 1
pez11:12:54

Haha, indeed. I just tried it. In Calva this shows up as quick-fixes. Sort map, etcetera.

Alexander Kouznetsov19:12:07

This is awesome! I didn’t know Quick Fixes existed!

ericdallo19:12:12

it's one of the most used features to me :)

❤️ 1
Alexander Kouznetsov19:12:58

I guess a nice to have in Calva would be to sort a selected portion of a map or a vector as sometimes things are organized by themes but should be sorted within the theme. Current workaround would be to temporarily wrap selected portion in a map, or a vector, sort it, and then remove the temporary wrapping.