Fork me on GitHub
#calva
<
2022-10-08
>
Kari Marttila06:10:28

I guess there is no Calva Paredit: Copy Sexp Forward command? I.e. using that keyboard shortcut you could copy the sexp into the clipboard but the original code stays intact.

pez08:10:11

Correct. There is no such command. What I do is that I run Select forward sexp, Copy, Cursor Undo in succession. So: shift+alt+right cmd+c cmd+u. You can use #joyride to automate this. There are several ways. Two of which: 1. Place a function like this in your user_activate.cljs script:

(defn copy-forward-sexp []
  (p/do 
   (vscode/commands.executeCommand "paredit.selectForwardSexp")
   (vscode/commands.executeCommand "editor.action.clipboardCopyAction")
   (vscode/commands.executeCommand "cursorUndo")))
Then in keybindings.json :
{
        "key": "shift+ctrl+alt+right",
        "command": "joyride.runCode",
        "args": "(copy-forward-sexp)"       
    },
2. Or put the whole sequence in the keybinding:
{
        "key": "shift+ctrl+alt+right",
        "command": "joyride.runCode",
        "args": "(require '[\"vscode\" :as vscode]) (p/do (vscode/commands.executeCommand \"paredit.selectForwardSexp\") (vscode/commands.executeCommand \"editor.action.clipboardCopyAction\") (vscode/commands.executeCommand \"cursorUndo\"))"       
    },

pez08:10:55

You can use the Keyboard Shortcuts panel to copy command ids.

Kari Marttila12:10:48

Just configured this and it works great! Just had to restart VSCode, which I didn't immediately realize. Thanks! I put this hint to my new blog post. 🙂

pez14:10:04

You shouldn't need to restart Calva for this. Evaluating the function in the Joyride REPL is the civilized way to do it. 😃 Or, if starting that REPL is inconvenient right there and then: Joyride: Run User Script... and select user_activate.cljs (if that is where you put the function). The default activate script is designed to support reloading.

pez14:10:42

As for restarting VS Code. Generally each VS Code window is pretty isolated, so Developer: Reload Window is often enough, for less dynamic things than Joyride scripts.

Kari Marttila14:10:23

Ah, good to know!

Kari Marttila14:10:31

I add that in my new blog post. 🙂

metal 1
pez15:10:21

Let me know if you want me to check that post before posting it. 😃

Kari Marttila15:10:32

Damn. I thought I keep this blog post article open for a few days but I already have quite a lot of stuff there. I think I post this part 2 today, and start working with part 3 immediately. 🙂

Kari Marttila15:10:04

I make a PDF conversion and send it to you in private chat for review, if that is not too much trouble. 🙂

pez15:10:58

Oh, no problem at all. And I don't think it needs a review per se, just that if there are some things I know how to do, that seems that you don't, I can let you know.

Kari Marttila07:10:30

How to configure in Calva so that when I e.g. ctrl+click some Clojure function (like range) then Calva opens core.clj file in another tab in editor and scrolls the editor view to show the (defn range ... ?

pez07:10:47

That’s the default behavior. cmd+click if you’re on a Mac.

Kari Marttila07:10:16

Ah. I'm on Linux. I investigate why it is not working. Thanks!

Kari Marttila08:10:51

Hm. For some reason I can't make it work. In context help there is Go to Definition / Go to Declaration , but VSCode says: No definition found for comment (if trying in (comment ... ).

pez08:10:31

Maybe you haven't started the REPL with dependencies that Calva needs? There is a command Calva: Copy Jack-in Command Line ... something something, that will give you a command line that starts the REPL with the dependencies met. (Or use Jack-in.)

skylize15:10:31

On Linux myself, and Ctrl-`<click>` or <F12>does as described through Go to Definition command. Repl connection is not required, but you do need clojure-lsp to be running.

Kari Marttila18:10:43

Works now with:

@backend-calva-kari:
    clj -M:dev:test:common:backend:calva:kari  -i -C
and in deps.edn:
;; Calva specific
           :calva {:extra-deps {cider/cider-nrepl {:mvn/version,"0.28.5"}}
                   :main-opts ["-m" "nrepl.cmdline" "--middleware" "[cider.nrepl/cider-middleware]"]}

pez18:10:20

Happy it works! You mean you don't need that for CIDER, @U76D9RZRR?

Kari Marttila18:10:56

Öö, what do you mean: I don't need that for CIDER?

Kari Marttila18:10:48

Calva is really good. I didn't find any issues. I didn't find anything that is missing compared using IntelliJ/Cursive or Emacs/Cider (in short evaluation). I start using Calva in my Clojure programming, let's see if I can find anything that I miss in Cursive.

❤️ 1
pez19:10:15

At least you're not a Parinfer user. 😃

😄 1
Kari Marttila08:10:42

Having some troubles to customize my Leuven theme with VSCode / Calva. If you have information about this and want to help, see 🧵 🙂

Kari Marttila08:10:17

So, I'd like to change some of the off-the-shelf colors of VSCode Leuven theme.

Kari Marttila08:10:38

E.g. to change the colors of numbers and keywords.

Kari Marttila08:10:15

In settings.json perhaps edit something like this:

"[Leuven Light]": {
      "enabled": true,
      "rules": {
        // different color for all constants
        "property.readonly": "#dc93b4",
        // make all symbol declarations bold and italic
        "*.declaration": {"bold": true, "italic": true}
      }
    },

pez14:10:50

I'm not familiar with how to do this. Have you found this one? https://code.visualstudio.com/api/extension-guides/color-theme#syntax-colors

skylize15:10:28

My favorite theme Shades of Purple has basically no features for Lisp dialects. I added this prop to my settings.json to cover the basics. (... I keep meaning to add more detail and make a pull request for it. :face_with_peeking_eye:). Choose Developer: Inspect Editor Tokens and Scopes from the Command Palette for a floating window that lists the active scopes for wherever you move the cursor.

"editor.tokenColorCustomizations": {
        "[Shades of Purple]": {
            "textMateRules": [
                {
                    "scope": "entity.name.variable.clojure",
                    "settings": {
                        "foreground": "#9EFFFF",
                    }
                },
                {
                    "scope": "entity.name.function.clojure",
                    "settings": {
                        "foreground": "#FFEE80",
                    }
                },
                {
                    "scope": "storage.control.clojure",
                    "settings": {
                        "foreground": "#FF9D00",
                    }
                },
                {
                    "scope": "entity.global.clojure",
                    "settings": {
                        "foreground": "#FAD000",
                    }
                },
                {
                    "scope": "meta.metadata.simple.clojure,meta.metadata.simple.clojure entity.name.variable.clojure",
                    "settings": {
                        "foreground": "#d09fff"
                    }
                },
            ],
        },
    },

Kari Marttila17:10:59

Thanks. I now managed to configure my VSCode/Calva pretty much the same look I have in my IntelliJ/Cursive:

Kari Marttila17:10:24

I'm writing a blog post about VSCode evaluation, I give more detailed instructions there.

🙏 1
🎉 1
Kari Marttila17:10:37

So, the look part has been tackled now. 🙂

Dallas Surewood08:10:39

How can I set up my project so I can easily switch between repl ports? I have a clj/cljs project, but it's a pain to manually switch between them Also, when I use the calva command to start a project for deps.edn + shadow-cljs, it fails to start the cljs repl because it doesn't have the dependencies inside shadow-cljs.edn. It's running as though all it has access to is the deps.edn dependencies. Does the deps.edn + shadow.cljs command not work?

pez09:10:11

This is a common culprit. If it is two projects you will have to use two VS Code windows, as a Calva instance only connects to one project at a time. https://calva.io/workspace-layouts/#one-folder-two-windows in the Calva docs for some pointers on how to set this up. I think it sucks a bit, so maybe this is what you are doing today? The deps.edn + shadow-cljs sequence works. Though, since what it does is to start clojure, and clojure will not read shadow-cljs dependencies, you will not have those in your REPL. You could possibly use add-lib together with a custom Calva connect sequence to get this to work, but I say that without having tried it. For the smoothest Calva experience with this, you should let shadow-cljs use deps.edn for its dependencies. Then you can use the either the deps.edn + shadow-cljs, or the shadow+cljs project type. I recommend the latter. I've written an article about this here: https://blog.agical.se/en/posts/shadow-cljs-clojure-cljurescript-calva-nrepl-basics/ and there is also a video on @danielamber2’s channel about it: https://www.youtube.com/watch?v=islMjv55cN8 Check out @sakalli’s comment there which beautifully summarizes what I try to say with all those words.

👍 1
Dallas Surewood09:10:09

Thanks for the reply. I'm trying the approach you blogged aout but I'm getting this: Could not locate shadow/cljs/devtools/cli__init.class, shadow/cljs/devtools/cli.clj or shadow/cljs/devtools/cli.cljc on classpath.

Dallas Surewood09:10:19

Even though I have clojurescript and shadow-cljs in deps

pez09:10:37

Which project type are you using at Jack-in?

Dallas Surewood09:10:49

I did try deps + shadow-cljs as well

Dallas Surewood09:10:58

I set deps to true in shadow-cljs.edn and added this to my deps.edn

:shadow {:extra-deps {binaryage/devtools {:mvn/version "1.0.6"}
                                 cljs-ajax/cljs-ajax {:mvn/version "0.8.4"}
                                 thheller/shadow-cljs            {:mvn/version "2.20.2"}
                                 org.clojure/clojurescript {:mvn/version "1.11.54"}
                                 thheller/shadow-devtools {:mvn/version "1.0.20170516"}}}

Dallas Surewood09:10:21

Some of those just cause that's what was in my shadow-cljs

pez10:10:01

You'll need to either move that dependency out in the main deps declaration or tell shadow-cljs to include that alias. Instead of :deps true do :deps {:aliases [:shadow]} (from memory, but something similar to this).

Dallas Surewood10:10:38

Oh alright, got it

Dallas Surewood10:10:23

Okay that is building. But how would I evaluate my .clj code? Would I need to explicitly have shadow-cljs use every dependency listed in deps.edn?

Dallas Surewood10:10:07

Your blog seems to say we will use the Clojure Repl now for clj files, but I just get missing dependency errors if I try to evaluate things on the backend

pez10:10:03

If you have other dependencies needed for the backend that is in aliases, you’ll need to add those to shadow-cljs.edn

Dallas Surewood10:10:42

Ah. So there's no way to switch between these repls where it will know which dependencies to use. You'll just have to use all of them in one repl or the other if you want to work on one codebase

Dallas Surewood10:10:00

I thought when it switched to clj mode it might use the repl that has the deps.edn stuff by default

Dallas Surewood10:10:46

I could've sworn I had that workflow before

pez10:10:20

There is only one REPL started if you use this workflow.

Dallas Surewood03:10:19

It doesn't seem like I can list multiple aliases using this method. If I list more than one in the vector, none of them work

Dallas Surewood03:10:26

So I'm not able to include the other dependencies

pez06:10:09

That is very strange ... What do you get if you define it like so:

:deps {:aliases [:this :that]}
You should see this in the Jack-in window (here I am using my example project)
npx shadow-cljs -d cider/cider-nrepl:0.28.5 watch :app
shadow-cljs - config: /Users/pez/Projects/tests/shadow-w-backend/shadow-cljs.edn
shadow-cljs - starting via "clojure"
WARNING: Specified aliases are undeclared and are not being used: [:this :that]
And if, from the terminal, I do
clj -A:this:that
WARNING: Specified aliases are undeclared and are not being used: [:this :that]
Clojure 1.11.1
user=> 
Which tells us that that message comes from clojure.

pez09:10:11

This is a common culprit. If it is two projects you will have to use two VS Code windows, as a Calva instance only connects to one project at a time. https://calva.io/workspace-layouts/#one-folder-two-windows in the Calva docs for some pointers on how to set this up. I think it sucks a bit, so maybe this is what you are doing today? The deps.edn + shadow-cljs sequence works. Though, since what it does is to start clojure, and clojure will not read shadow-cljs dependencies, you will not have those in your REPL. You could possibly use add-lib together with a custom Calva connect sequence to get this to work, but I say that without having tried it. For the smoothest Calva experience with this, you should let shadow-cljs use deps.edn for its dependencies. Then you can use the either the deps.edn + shadow-cljs, or the shadow+cljs project type. I recommend the latter. I've written an article about this here: https://blog.agical.se/en/posts/shadow-cljs-clojure-cljurescript-calva-nrepl-basics/ and there is also a video on @danielamber2’s channel about it: https://www.youtube.com/watch?v=islMjv55cN8 Check out @sakalli’s comment there which beautifully summarizes what I try to say with all those words.

👍 1
Kari Marttila13:10:09

I listened to Cognicast Episode 167: Peter Strömberg and Calva. It was pretty interesting.

calva 1
Kari Marttila13:10:24

If I manage to configure my VSCode+Calva setup as much the same look-and-feel and developer experience as my IntelliJ+Cursive and Emacs+Cider setup, I will write a blog post about Calva, a bit like: https://www.karimarttila.fi/clojure/2021/01/27/clojure-emacs-vs-cursive.html

pez13:10:52

Ah, so it is you who have written that article. I've been using it for inspiration. 😃

Kari Marttila14:10:12

Heh, nice to hear. 🙂

pez14:10:05

Yes, that one too. 😃

Kari Marttila19:10:02

Really good Clojure programming experience with VSCode/Calva. I think I start using it with my 4Clojure exercises to have more experience.

pez19:10:55

I'm happy you like it. Especially as you can make the comparisons. It was a long time since I used CIDER and I've only tried Cursive occasionally to figure out how something works there that I should consider for Calva.

pez19:10:14

You might want to try Rich 4CLojure: https://github.com/PEZ/rich4clojure

👍 1
pez19:10:33

I don't know if you have tried Calva's Getting Started REPL? (It's a command in VS Code/Calva.) I'm curious what you think about it.

pez19:10:23

Very nice article by the way. Good with some quality posts out there mentioning the Calva alternative.

seancorfield20:10:06

@U76D9RZRR One thing I'd change: when you specify cider/cider-nrepl you don't need to also specify nrepl/nrepl as the former depends on the latter, so you ensure you get the appropriate version of the CIDER middleware.

👍 1
seancorfield20:10:09

@U0ETXRFEW I guess that's a note for you too, since Calva's jack-in specifies both (and does not need to).

👀 1
💡 1
pez20:10:42

Thanks! I'll have a think around that.

bringe23:10:37

What if there’s a new version of nrepl which we want Calva to use, but cider-nrepl doesn’t yet include that newer version? Maybe that situation would not occur or would rarely occur since I would imagine cider-nrepl would be updated to include the latest nrepl, although maybe there’s a gap sometimes. Also, maybe Calva would never have that need, and if it did, we could just add the nrepl dep back to the jack-in command.

bringe23:10:41

Issue created to at least track it, whether we make that change or not.

seancorfield00:10:26

FYI: the cider-nrepl docs specifically show it used without nrepl/nrepl so that's kinda where I was going with that: https://docs.cider.mx/cider-nrepl/usage.html#via-clj

seancorfield00:10:03

I guess Bug can give us the definitive answer (I won't @ him since it's 3 am over there right now)

Kari Marttila19:10:40

https://clojurians.slack.com/archives/CBE668G4R/p1665257954265159?thread_ts=1665257172.454249&amp;cid=CBE668G4R => Thanks for the hint @U0ETXRFEW ! I cloned the repo and decided to do the exercises using VSCode/Calva to get familiarized with my new setup. 🙂

metal 1
calva 1