Fork me on GitHub
#cider
<
2023-11-18
>
vlnn10:11:42

Is there some kind of integration between cloverage and cider? E.g. can cider mark the forms that are tested?

practicalli-johnny11:11:07

I don't recall anything in Cider, but Clojure LSP and LSP mode will annotate functions that have a unit test

👍 1
practicalli-johnny11:11:18

Seem like LSP also has a test tree view (I only just noticed this, so haven't tried it) https://clojure-lsp.io/features/#test-tree

Volodymyr Anokhin12:11:13

Thanks, I didn’t thought it may be on a different level of implementation. But I moved to lsp not that long ago, and still researching its features

vlnn13:11:47

Oh, it looks like the annotation (like 2 references | 1 test) are shown for the functions that are referenced from test namespace. Still, this will not help with deciding if all the branches of logic were covered with the tests (until everything is not refactored into functions that is — which not always a best solution). So the question is still valid — is there a possibility to visualize the code that is never tested?

vlnn14:11:25

I’ve kinda resolved the problem with using coverlay.el, but it’s a) not fully compatible with cloverage lcov output, and b) shows really rave colours in my doom emacs. So I’d like to find something prettier and production-ready.

vlnn14:11:55

Results: Useful but not pretty!

vemv17:11:46

I don't think there's such a package. Are you aware that Cloverage shows a similar-looking .html report? I found it pretty useful. https://github.com/flow-storm/clofidence was recently announced. It should make coverage on cljs possible.

vlnn17:11:15

OK, I’ve got second PoC up and running — after some configuration tinkering I’ve made projectile and coverlay to work together, so coverlay knows where the clojure project is and where to look for the coverage info, and all you need to run the cloverage manually (for smaller projects it could be hooked to run tests I guess…).

vlnn17:11:26

(after! projectile
  (use-package! coverlay
   :config
   (setq coverlay:tested-line-background-color "#C9F3D2")
   (setq coverlay:untested-line-background-color "#F8CED3")
   (setq coverlay:mark-tested-lines nil)
   (setq coverlay:base-path (expand-file-name (projectile-acquire-root)))
   (coverlay--do-watch-file (expand-file-name "target/coverage/lcov.info" (projectile-acquire-root)))
   (global-coverlay-mode)))
this is doom configuration of the link between two, clojure only for the moment

👏 2
Felix Dorner22:11:27

I’d like to autostart nrepl server for a project when I start emacs. I figured I’d just I run cider-jack-in with arguments :project-path and :jack-in-cmd , which starts the nrepl. But when I then open a file from that project, cider doesnt automatically connect, like it does when I jack in normally from a .clj buffer. How can I make it connect automatically?

vemv23:11:55

Show us your attempt 🙂

Felix Dorner13:11:12

Hmm, weird, it works now:

Felix Dorner13:11:53

(cider-jack-in '(:project-dir "/Users/felix/tmp/test-autojackin" :jack-in-cmd "/usr/local/bin/clojure -Sdeps '{:deps {nrepl/nrepl {:mvn/version \"1.0.0\"} cider/cider-nrepl {:mvn/version \"0.35.0\"}} :aliases {:cider/nrepl {:main-opts [\"-m\" \"nrepl.cmdline\" \"--middleware\" \"[cider.nrepl/cider-middleware]\"]}}} -M:cider/nrepl'"))

vemv13:11:08

I wouldn't use jack-in-cmd, let CIDER compute things for you the other interesting part is where you put that call, and how do you guard it's executed exactly once.

Felix Dorner13:11:11

I though to to run it in emacs-startup-hook, but maybe that’s totally wrong..?

vemv13:11:48

I cannot confidently say that, but it sounds pretty early, might add unpredictability I'd do it like this:

(defvar launched nil)

(add-hook 'clojure-mode-hook (lambda (&rest _)
                               (unless launched
                                 (when (equal (buffer-file-name)
                                              "/Users/vemv/foo/deps.edn")
                                   (setq launched t)
                                   (cider-jack-in ...)))))

;; trigger the hook:
(find-file "/Users/vemv/foo/deps.edn")
By doing this way, we ensure that enough code has been loaded You can add something like that to init.el directly. wrapping it in emacs-startup-hook also sounds ok, for good measure