Fork me on GitHub
#calva
<
2023-03-04
>
jeaye02:03:50

Hi folks. I'm trying to use Calva's debugger to teach someone who's learning Clojure the order of execution of code, which means I'd like to step through as much as possible. How can I instrument every fn and keep them instrumented? Is there any way to instrument Clojure core fns, too (I see the docs say it's not doable, but I want to check if it's just cumbersome or not doable)? Or perhaps does someone have a better recommendation for a Clojure debugger or tracer?

pez11:03:01

I don't quite understand why we can't instrument clojure core functions, so can't comment on how doable it is. I think that would be quite awesome to be able to do.

pez11:03:35

As for alternatives. The Cursive debugger is the best traditional debugger for Clojure that I know of. For your purposes though, maybe a tracer like @U02EMBDU2JU’s omni-trace would be a good fit? https://github.com/Cyrik/omni-trace Lukas demoed it at ClojureD 2022: https://www.youtube.com/watch?v=JitNGtiuNOA

Lukas Domagala13:03:11

I've mostly switched to using https://github.com/jpmonettas/flow-storm-debugger since I don't have the time to work on omni-trace right now

jeaye18:03:42

Thanks, guys!

jeaye18:03:28

I suppose the core fns don't work because of direct linking. All of core is compiled with that, which means no var indirection, which means no instrumentation. Should be able to get a core lib with that disabled though.

jeaye19:03:24

Just tried out flow-storm-debugger. It's a nice tool. The key difference between it and Calva's debugger is that flow-storm-debugger shows what happened after the fact. It doesn't allow you to step through code yourself; it shows you what code was stepped through when you ran it previously.

jeaye19:03:17

I never realized that Clojure was so lacking in the debugging world, since we all just use our REPLs and generally understand the flow of execution. But for someone learning Clojure as a first language, that really doesn't cut it. Makes me realize that jank can bring big wins here with some out of the box DAP tooling.

bringe21:03:41

To me it seems like showing a beginner the flow using flow-storm after execution is just as good, if not better, than showing it during execution, since you can step backwards in time too. I think showing a beginner how to use inline defs to be able to execute any part of the code in question at will is also probably pretty important. I added much of the debugger functionality to Calva when I was still fairly new to Clojure, but I don’t even use it (or any debugger). I do think it might be a good idea for me to try using something like flow-storm more in some situations, but so far I don’t really feel a need for something like that. It could be the case that I just don’t know what I’m missing, though.

Lukas Domagala21:03:58

I've just gotten used to having it in my dev deps and staring it with a hot key if I'm doing something that could use it.

bringe21:03:31

Ah I should put it within easy reach like that.

Thierry11:03:16

I have a question about using Calva (in VSCode) with a deps.edn project. Untill now all projects I worked on were based on leiningen, easy to use but much overhead. I migrated one of my projects to deps.edn and I can run it and it works with clj -M -m myapp.core . But when I Jack-In with Calva to start a repl, the app and its dependencies are not on the classpath. First I have to do a (require 'myapp.core) before anything works, is that normal? Second, I added a new dependency and now I get a message that this dep is not located anywhere on the classpath. What might I be doing wrong?

pez11:03:05

Hard to tell without knowing more about the project structure. Can you describe it a bit?

Thierry11:03:25

Sure, I can share it with you even if you want

Thierry11:03:29

its not a private thing

Thierry11:03:33

not on gh just yet tho

pez11:03:34

It's not normal. To answer your question. sounds like something is wrong.

pez11:03:44

Push it to GH and I'll have a look.

Thierry11:03:03

sure, just need to remove some stuff first

Thierry11:03:58

Here's a quick repo, will delete it when youre done https://github.com/LouDnl/yls-pez

Thierry11:03:53

I must be doing something wrong somewhere wit hconfig

Thierry11:03:53

with configuring*

pez12:03:03

I can't easily test this because postgres and possibly other things. There is nothing that strikes me as wrong at a glance. (I would remove the nrepl dependencies from the project unless they are needed for something else than editor tooling.) Can you describe the steps you take to start, and what you expect should happen?

Thierry12:03:40

The nrepl deps are needed for the repl namespace. Steps: Open VSCode project Jack-In choosing the project root Select dev and calva aliases Wait for repl clj:user:> (require 'youless.core) Try to start statemanagement:

; Execution error (ClassNotFoundException) at java.net.URLClassLoader/findClass (URLClassLoader.java:476).
; mount.lite
or require:
(require 'youless.core)
; Execution error (FileNotFoundException) at youless.config/eval7237$loading (config.clj:1).
; Could not locate taoensso/timbre__init.class, taoensso/timbre.clj or taoensso/timbre.cljc on classpath.

Thierry12:03:00

When I dont select aliases the (require 'youless.core) works - disregard this

Thierry12:03:18

But I dont know why and I dont know why I have to require first

Thierry12:03:46

@U0ETXRFEW you can test it without postgres, I cant even get a namespace after jackin without starting the project using mount.lite

Thierry12:03:30

I had an error in the :dev alias that overrided the main deps, so thats solved. I used :deps instead of :extra-deps. But that still doesnt explain why I need to do (require 'youless.core) first?

pez12:03:26

What does ”Try to start statemanagement” mean?

Thierry12:03:12

Ah, you can ignore that but its (mount.lite/start)

Thierry12:03:50

If I do a require first everything works fine.

Thierry12:03:06

But that shouldnt be necessary am I right?

pez12:03:06

Calva does not require anything for you, so if your project needs a special order of requires, it could be that you need to require some namespace before some other for things to work. In this case it seems like it is unintended so I would go from the error messages you get and see what might be missing in your ns forms.

pez12:03:19

Also have a look at the leiningen project to see if it had some init-fn configured our something. Might give some clues to what you need to do with the deps project to make it work.

Thierry12:03:40

Okay, thanks for the tips

Thierry12:03:51

Will let you know what the outcome is

Thierry12:03:19

I think what I am missing are the deps.edn equivalents of project.clj's :

:main youless.core
:aot [youless.core]

Thierry12:03:23

@U0ETXRFEW I think I solved it by using "afterCLJReplJackInCode": "(require 'youless.core)", in my custom calva.replConnectSequences

pez14:03:19

I was about to suggest that. It could be the right solution even.

👍 2
pez16:03:16

You don't need any :calva alias if you are using jack-in, btw. Jack-in will override those (as well as the global nrepl dependencies you have there.)

Thierry07:03:01

Thanks for the tip, removed it from my project and indeed works as you describe

mathpunk21:03:10

anyone have a fave community for vscode power users? i have non-calva problems

pez21:03:27

I most often ask here. 😀

think_beret 2
bringe21:03:20

IIRC there’s a Slack for vscode

bringe21:03:07

It’s dev-related, but might be helpful for you.

bringe21:03:03

https://code.visualstudio.com/blogs/2022/10/04/vscode-community-discussions There’s a link on this page near the bottom, and there’s also a link to the VS Code community GH discussions.

mathpunk21:03:10

thanks!

👍 2