Fork me on GitHub
#calva
<
2022-09-07
>
ikitommi14:09:18

for ts, there is https://github.com/rikukissa/typehole, could there be such a thing for Clojure? Both Spec and Malli have type providers. Not sure how useful this would be, but cool anyway.

pez14:09:07

Wow, that sure looked very cool! Would be interesting with an example with how it could look like using Malli and/or spec.

bringe04:09:07

Hey @U055NJ5CC. Thanks for your work on malli simple_smile. Are you referring to convenience editor support for this feature of malli? https://github.com/metosin/malli#inferring-schemas. So, basically a command / UI menu for generating a schema for a data structure at the cursor (or something like that)?

ikitommi15:09:35

Yes, you could do typehole-thing with, malli, mallireika in finnish 🙂 But, I’m not sure if that would be super useful, just cool I guess. But, If there is anything in calva where malli could be used to help, I’m all ears and happy to help.

👍 1
bringe22:09:05

Definitely could be a cool convenience feature for some users. Haven’t thought this through all the way, but with current Calva features, maybe a custom repl command could be used in conjunction with a malli call to generate a schema for the current form, and maybe the result could be printed in the file below the current form, or copied to the clipboard, or something like that.

bringe22:09:49

Of course, more first-class support could be added too if desired/necessary.

👍 1
ikitommi15:09:35

if there is an easy way to do that with custom repl command, please write a "typehole with calva & malli" post and share it :)

bringe18:09:02

@U0ETXRFEW Any interest in trying this? 😄

pez19:09:04

Typehole looks really awesome. (Even if I am actually struggling with understanding what is happening in that gif.) Building something like it for Clojure should be quite possible. It's a bit outside of Calva's scope but Calva's API could be leveraged by another extension. Or #joyride, of course. Might be that we need to expose some pretty printing facilities in that API.

pez19:09:23

Something simpler, yet probably useful, could probably be done with a custom command, as you are suggesting, @U9A1RLFNV. I'll have a look at it.

👍 1
pez20:09:02

It's not a ”Typehole with Calva & Malli” so I didn't call it that. At least not in a way that most people can understand 😃 https://www.youtube.com/watch?v=MW-1Ov8ynWw

pez20:09:04

This is the Custom REPL Command keybinding definition:

{
        "key": "ctrl+alt+m ctrl+enter",
        "command": "calva.runCustomREPLCommand",
        "args": {
            "repl": "clj",
            "snippet": "(require '[malli.provider :as mp]) (mp/provide $current-form)",
        }
    },

pez06:09:48

@U055NJ5CC it would be nice with a chat where we try to envision a more dynamic typehole-thing. At first to figure out if it is something within reasonable reach and worth some efforts.

Yehonathan Sharvit14:09:13

Not strictly related to Calva, but to VSCode: When I navigate to a file from a JAR, sometimes I want to edit the code in order to reload it in the REPL. However VSCode doesn’t let me and says “Cannot edit in read-only editor”.

pez14:09:58

I've seen some discussion around this somewhere. Can't recall where right now... Anyway, what I do is that I load the file and then paste the code I want to change in the REPL window and edit and re-evaluate it there. Not super straight-forward, but anyway.

Yehonathan Sharvit14:09:50

How could it be that it’s so hard to convince VSCode to let me edit a buffer?

Yehonathan Sharvit14:09:03

I am not asking for saving my changes in JAR!

pez15:09:03

¯\(ツ)

pez15:09:14

Here's an issue on a vscode extension discussing it a bit. It leads to another issue (on vscode) where the answer to your question seems to be able to find. (TL;DR: Because reasons). https://github.com/alefragnani/vscode-read-only-indicator/issues/20

pez15:09:48

btw. That extension has a toggle for readonly files. But it only works if they are loaded from the file system.

Yehonathan Sharvit16:09:48

Does it work if the file is loaded from a jar?

pez16:09:37

No, only from the file system. It cheats. Since VS Code has no API for toggling readonly, this extension chmods the file.

skylize22:09:10

Shouldn't be too hard to read the editor contents into a new editable file. https://github.com/BetterThanTomorrow/joyride if you want have a go at it. And this should help get you going. https://stackoverflow.com/a/41069687

Lukas Domagala17:09:17

If you actually have the code locally you could also connect into the REPL from that project. clojure-lsp would handle it correctly. (that’s what I do at work)

pez08:09:26

Instead of copy paste to the REPL window, another workaround is to simply copy the entire readonly document, open a new untitled document, paste the code there. cmd+a cmd+c cmd+n cmd+v. Edit and re-evaluate at will. And like @U90R0EPHA says, Joyride can help in automating it:

(p/let [text (vscode/window.activeTextEditor.document.getText)
          doc (vscode/workspace.openTextDocument #js {:language "clojure", :content text})] 
    (vscode/window.showTextDocument doc #js {:preview false, :preserveFocus false}))
Binding that to a shortcut can be done in some different ways, the most straightforward being:
{
        "key": "alt+ctrl+r",
        "command": "joyride.runCode",
        "args": "(p/let [text (vscode/window.activeTextEditor.document.getText)\n doc (vscode/workspace.openTextDocument\n #js {:language \"clojure\", :content text})]\n (vscode/window.showTextDocument doc #js {:preview false, :preserveFocus false}))"
    }

Kiyanosh Kamdar16:09:54

Hello, is there a way to print the “jackInEnv” key/value pairs to the repl?

pez16:09:20

Not that I can think of. What's the use case, if I may be curious?

Kiyanosh Kamdar16:09:29

My repl instances do a lot of communication with AWS and other systems to get tokens and such. Normally I export these from the shell. I “think” I got them in the jackInEnv settings, but would be good to have a way to confirm it.

pez17:09:20

Would it help if Calva printed the jackInEnv it uses before it executes the jack-in command?

Kiyanosh Kamdar17:09:55

that would be great

pez18:09:48

Please file an issue about it. I think it is something we should consider.