Fork me on GitHub
#calva
<
2023-08-17
>
Ingy döt Net16:08:40

Just started using clojure.lsp refactoring things. Also got extra-indents working. It seems like refactoring does not go straight to desired indentation. I need to tab the form afterwards.

ericdallo16:08:49

Got any examples?

Ingy döt Net16:08:13

(aaa
  (bbb
    (ccc)))
clojure-lsp Refactor: Thread Last All ->
(->> (ccc)
     bbb
     aaa)
<tab> ->
(->> (ccc)
  bbb
  aaa)

Ingy döt Net16:08:38

is just one...

Ingy döt Net16:08:15

had same experience with Clean NS Form

ericdallo17:08:45

that works to me on emacs using clojure-lsp, so I guess could be Calva formatting?

Ingy döt Net17:08:18

not sure what you mean. what exactly "works" for you?

Ingy döt Net17:08:42

can you show your flow like I did above?

ericdallo17:08:56

(->> (ccc)
     bbb
     aaa)
should be the correct indentation

Ingy döt Net17:08:11

Not with extra-indents which is tonsky style

ericdallo17:08:30

could you elaborate what is the extra-indents?

ericdallo17:08:38

is it a calva feature?

ericdallo17:08:22

got it, so what happens is that clojure-lsp after applies the refactor with hard coded spaces, and the only refactor that we apply formatting is the clean-ns, maybe we should apply it for other refactorings as well

Ingy döt Net17:08:25

clean-ns also formatted differently than tab

Ingy döt Net17:08:38

any refactoring should honor the configured/desired indentation

Ingy döt Net17:08:06

(ns yamlscript.reader
  (:use clojure.pprint)

  (:require
   [clojure.string :as str]
   [fr33m0nk.optional :as optional]
   [faux-combinator.parser :as fcp])

  (:import
   (org.snakeyaml.engine.v2.api LoadSettings)
   (org.snakeyaml.engine.v2.api.lowlevel Parse)
   (org.snakeyaml.engine.v2.common ScalarStyle)
   (org.snakeyaml.engine.v2.events
     MappingStartEvent
     MappingEndEvent
     SequenceStartEvent
     SequenceEndEvent
     ScalarEvent
     AliasEvent)))
clean-ns ->
(ns yamlscript.reader
  (:use clojure.pprint)

  (:require [fr33m0nk.optional :as optional])

  (:import (org.snakeyaml.engine.v2.api LoadSettings)
           (org.snakeyaml.engine.v2.api.lowlevel Parse)
           (org.snakeyaml.engine.v2.events
            AliasEvent
            MappingEndEvent
            MappingStartEvent
            ScalarEvent
            SequenceEndEvent
            SequenceStartEvent)))
tab ->
(:import (org.snakeyaml.engine.v2.api LoadSettings)
           (org.snakeyaml.engine.v2.api.lowlevel Parse)
           (org.snakeyaml.engine.v2.events
             AliasEvent
             MappingEndEvent
             MappingStartEvent
             ScalarEvent
             SequenceEndEvent
             SequenceStartEvent)))

Ingy döt Net17:08:42

is what i got in calva

ericdallo17:08:48

clean-ns has different built-in formatting settings, check the :clean setting, but I agree most if not all refactors should apply formatting automatically, feel free to open an issue on clojure-lsp

Ingy döt Net17:08:42

I think this is a calva issue

Ingy döt Net17:08:41

is cljfmt handled entirely by clojure-lsp?

Ingy döt Net17:08:23

`Calva: Load Current File and Dependencies` doesn't seem to forget prior evaluations this is a problem when I'm wondering if my declare 'd fns are right. if I delete my (declare ...) stuff and Calva: Load Current File and Dependencies things should not work, but they do. if I shut down the repl and restart it, only then does it fail.

pez17:08:42

This is by design, and not really a Calva thing. The REPL never forgets anything unless you tell it to. 😃 There are ways to tell it, though nothing built in to Calva. You can build them in yourself via custom repl commands https://calva.io/custom-commands/ (Once you know what functions to use.)

👍 2
Ingy döt Net17:08:26

Looks like restarting the repl is my friend here

Ingy döt Net17:08:09

I mean just running jack-in again after a repl is already started

pez18:08:04

That’s such a boring way to do it. 😃 Generally, it can be very costly, losing your state and could also be time consuming. I think ns-unmap might be your friend: https://clojuredocs.org/clojure.core/ns-unmap

Ingy döt Net18:08:37

Guess it depends. I tried for several minutes to get that to work. I agree it should. But for what I'm testing and where I'm at, restarting the repl from calva is my best flow.

pez21:08:47

Whatever floats your boat. 😃 But @U018D6NKRA4 might have a message for you: https://twitter.com/CarnunMP/status/1692283044139319784?s=20

😆 2
Ingy döt Net22:08:31

The issue to solve here is how to make sure your code will one pass compile, and what needs to be declared. The best solution solution would probably be a clojure-lsp Refactor one.

carnundotcom22:08:41

Hmm. So the problem is to figure out which declares can be safely removed without jeopardising future REPL startups... without restarting the REPL? :thinking_face:

carnundotcom22:08:06

What's going wrong with ns-unmap?

Ingy döt Net22:08:32

nothing per se. I just had trouble getting it to work in calva

Ingy döt Net22:08:14

I'll try again now in lein repl just to verify

carnundotcom22:08:05

How are you evaluating it?

Ingy döt Net22:08:13

ok this does what I need:

(->> (keys (ns-publics *ns*)) (map #(ns-unmap *ns* %)))
thanks!

👌 2
Ingy döt Net22:08:14

An lsp refactor action, or linter thing would still be great for getting declare's right, I think.

Ingy döt Net22:08:46

I'm still an infant in clj

carnundotcom23:08:06

aren't we all :))

🍼 4
pez17:08:42

This is by design, and not really a Calva thing. The REPL never forgets anything unless you tell it to. 😃 There are ways to tell it, though nothing built in to Calva. You can build them in yourself via custom repl commands https://calva.io/custom-commands/ (Once you know what functions to use.)

👍 2