Fork me on GitHub
#calva
<
2022-02-24
>
pez10:02:00

Dear Calva friends, I need help testing a change to how the formatter fetches its configuration. For use without the CLOJURE-LSP config option (see https://calva.io/formatting/#configuration) it should behave exactly as before. For the lsp use it should start working, but also might make formatting unresponsive while clojure-lsp initializes. In any case, the changes are of a nature that I might have introduced bugs, so your help with testing would be awesome. Thanks in advance! 🙏 gratitude ❤️ • VSIX to test: https://18330-125431277-gh.circle-artifacts.com/0/tmp/artifacts/calva-2.0.246-1561-fix-clojure-lsp-format-config-16a7c9a4.vsix

👍 1
pez14:02:55

Alright, it turned out that the released Calva had a serious bug when it comes to formatting on save, so any bugs I introduced with the follow up will most probably be an improvement. I've just released Calva v2.0.246: • Fix: https://github.com/BetterThanTomorrow/calva/issues/1561 • Fix2: https://github.com/BetterThanTomorrow/calva/issues/1556 I'm terribly sorry for any mess the previous version created for people using Format on Save. Thanks @isac_asj91 for 246 testing, review and contributions to this fix! 🙏 ❤️

❤️ 5
👍 1
Grant Horner16:02:52

is there any way to integrate the additional docs provided by clojure.spec.alpha/fdef into the mouse-over tooltip in calva? It’d be great to be able to see that stuff.

pez16:02:15

I was about to say that there isn't, but then remembered that @U02EMBDU2JU added a way to add stuff to the hover recently. So there might be a way. Let's see what Lukas says about it.

Lukas Domagala16:02:22

I haven’t looked at the output of fdef, but if you can do something like (get-fdef-docs ’sym) and get what you want displayed, then Custom REPL hover snippets https://calva.io/custom-commands/ should do the trick

pez16:02:55

We might want to add some priority to these snippets, @U02EMBDU2JU. So that they can appear early in the hover.

Grant Horner16:02:49

@U02EMBDU2JU this is very cool. I think I’m missing something though. Given a snippet like the following:

(spec/def ::thing string?)

(spec/fdef my-foo
  :args (spec/cat :x ::thing)
  :ret ::thing)

(defn my-foo
  [x]
  x)
calling (clojure.repl/doc my-foo) returns
([x])
Spec
  args: (cat :x :my-ns/thing)
  ret: string?
nil
where I just get nil on hover. I think I have an error in my config, which I set like this:
"calva.customREPLHoverSnippets": [
        {
            "name": "show doc on hover",
            "snippet": "(clojure.repl/doc $hover-text)"
        }
    ],
in my settings.json . Do you guys see anything off here?

pez16:02:29

You might need to quote $hover-text

pez16:02:15

But that is not consistent with you getting nil. You would get nothing if that was the error, I think...

Lukas Domagala16:02:35

Calling doc apparently prints the result and returns nil, right? You'd need a function that returns a string you want to show

pez16:02:03

(with-out-string (clojure.repl/doc $hover-text))

Grant Horner16:02:38

You’re right - I tried replacing it with what you suggested @U0ETXRFEW (both with and without \“\” surrounding the $hover-text) but still no dice

pez16:02:03

I meant quote like '$hover-text 😃

pez16:02:10

Does my suggesting work in the REPL? I didn't test it myself. 😃

Grant Horner16:02:36

Woops. We overloaded the word quote by accident. Still is not working for me: I’m assuming the fn name is directly inserted into $hover-text, in which case we wouldn’t want to quote it (i.e. you want (doc fn) , not (doc 'fn) )

Grant Horner16:02:33

The "calva.customREPLHoverSnippets" property should go right into my settings.json file right? Do I need to restart my vs code or anything?

pez16:02:25

It hot reloads.

pez16:02:55

Try a really simple snippet. (str '$howver-text)

Grant Horner16:02:54

yeah still nothing… not sure what I’m doing wrong. It should just show up in the tool tip right? I don’t need to enable it or anything?

...,
"calva.customREPLHoverSnippets": [
        {
            "name": "show doc on hover",
            "repl": "clj",
            "snippet": "(str '$hover-text)"
        }
    ],
...

pez16:02:00

It should just show up. That looks right to me. We have this in Calva's test-data directory:

"calva.customREPLHoverSnippets": [
    {
      "name": "edn hover hover-text",
      "snippet": "(str \"**JSON edn hover hover-text** \" \"$hover-text\")"
    }
  ],

pez16:02:20

You get nil, or you get nothing, btw?

Grant Horner16:02:44

I think nil is just the default output for a fn with no doc string. I tried replacing my calva.customREPLHoverSnippets with the above and I’m still not seeing anything, so I guess my calva is just borked

Grant Horner16:02:32

this should show that long snippet of text somewhere right? I’m really feeling like I’ve got an ID10T user error on my hands over here

pez16:02:32

It should....

pez16:02:11

I get something printed using

{
      "name": "Show doc string",
      "snippet": "(with-out-str (clojure.repl/doc $hover-text))"
    }
No quote, and with-out-str.

pez17:02:02

However, so not quite there yet. 😃

Grant Horner17:02:38

ah… I got it to work using the .calva/config.edn route. Not sure why it wasn’t working with my settings.json .

Grant Horner17:02:53

but yes, it doesn’t like line breaks 🙂

pez17:02:17

Might be something we need to fix, but also might be something the snippet can fix...

pez17:02:11

Very strange that the JSON didn't work...

Lukas Domagala17:02:14

Yeah what ever is coming in is used as if it was markdown. So currently the easiest way would be to have a (doc-md …) function that you define in your own code and call it from the snippet

Grant Horner17:02:53

oh that is really good to know @U02EMBDU2JU

Grant Horner17:02:29

@U02EMBDU2JU how would we insert a newline? I’ve tried \n, <br>, etc. but haven’t figured it out. sorry to keep necroing this thread

Lukas Domagala17:02:45

all good, you’re the first user other than me and I didn’t get the chance to do more then simple tests, so it’s great that you give it a good kicking 🙂

pez17:02:44

Please keep the thread going!

Lukas Domagala18:02:34

mhh, not sure why it’s not handling newlines correctly. The code is just

const hover = new vscode.MarkdownString();
hover.isTrusted = true;
hover.appendMarkdown(_.trim(text, '"'));
But I don’t really have time to play with it until sunday. Any ideas @U0ETXRFEW? You seem to have done the same thing on clojuredocs.ts

chucklehead22:02:04

Looks like you might need to double the newline character: https://github.com/microsoft/vscode/issues/86291

Lukas Domagala00:02:02

Nice find @U015879P2F8, thank you! I’ll play around with the MarkdownString possibilities when I find some time and probably add a :kind field to the snippets. That way you can do markdown if you want but also have an easier out if you don’t need the markdown stuff.

pez12:02:42

Funny that it was a Calva contributor who filed the issue, 😃

orestis19:02:47

In the docs I see "This also creates a hover pane including the full results and a button which will copy the results to the clipboard." However when I evaluate some code I never see this. Is there a setting to get it back?

pez19:02:50

It populates the hover with the results. Try issuing the Show hover command after you have evaluated.

orestis19:02:13

Ah, that's more like it. But the hover disappears the moment I move the mouse... unless I put the mouse where it's going to open 🙂

orestis19:02:35

Is this related to the delay of the hover in general? Because I've set that to be the maximum...

orestis19:02:48

Ohhh the hover window is a singleton? And it contains both the last eval results and whatever else the cursor happens to be on?

pez19:02:58

Yeah, I’m just checking that it works. The hover range is the range of the evaluated text. But VS Code is only showing hovers on something non-whitespace. And if you have disabled hovers, they won't show. Try using a delay of 1500 ms. It’ll give you time to avoid hovers when you don't want them.

orestis19:02:30

OK that clarifies things. I will resume tomorrow. Thanks!

pez06:02:50

I think that if you place the mouse cursor where the hover will appear before you press cmd+k cmd+i you'll be able to inspect the hover contents.

orestis19:02:55

Here's what happens when I evaluate a snippet that produces something long enough to wrap

Stuart21:02:03

Is this because you have pretty printing on, look down bottom right

bringe04:02:08

@U7PBP4UVA Is this related to your previous message about the hovers? If so, it seems you’ve gotten some help there, right?

orestis05:02:40

Yes, it's about hovers. In general it's because for me I can't really work without the output window being visible, since the hover is cumbersome to use, and the inline results show next to nothing.

orestis05:02:19

I guess there's limitation to the UI that can produce the results...

☝️ 1
pez06:02:42

I'd like to be able to display richer inline results. But the vscode team is not prioritizing that kind of UI. https://github.com/microsoft/vscode/issues/3220

orestis09:02:03

I was looking into notebooks but it seems a very heavy handed approach for REPL based development.