Fork me on GitHub
#cider
<
2023-08-28
>
daveliepmann09:08:47

Why were symbols and keywords with multiple / slashes added in https://github.com/clojure-emacs/clojure-mode/pull/475? I don't believe any of these are valid. (Context: I'm looking at https://github.com/clojure-emacs/clojure-mode/issues/653)

vemv20:08:24

I don't like it myself, but seg.mnt/ve/yCom|pLex.stu-ff (per https://github.com/clojure-emacs/clojure-mode/pull/475/files) appears to be a valid name, in the same way that clojure.core has (defn / []) for division

daveliepmann20:08:25

keywords as well, or only symbols?

vemv20:08:55

$ clj
Clojure 1.11.1
user=> :a/a/a
:a/a/a
not that I like it, but I can see why someone would want it supported

πŸ‘ 2
daveliepmann20:08:46

fair point, should've tried that myself

bg13:08:46

When using clojure-ts-mode C-c C-z doesn’t work in the REPL anymore because the fn cider-repl-type-for-buffer checks for buffers with clojure-mode enabled. I patched the function like this and now it works fine -

(defun cider-repl-type-for-buffer (&optional buffer)
    "Return the matching connection type (clj or cljs) for BUFFER.
BUFFER defaults to the `current-buffer'.  In cljc buffers return
multi.  This function infers connection type based on the major mode.
For the REPL type use the function `cider-repl-type'."
    (with-current-buffer (or buffer (current-buffer))
      (cond
       ((seq-some #'derived-mode-p '(clojurescript-ts-mode clojurescript-mode)) 'cljs)
       ((seq-some #'derived-mode-p '(clojurec-ts-mode clojurec-mode)) cider-clojurec-eval-destination)
       ((seq-some #'derived-mode-p '(clojure-ts-mode clojure-mode)) 'clj)
       (cider-repl-type))))
Is this the best way to fix the issue?

bg14:08:26

There are a few other issues, all of them are because of certain assumptions that cider makes about clojure-mode being enabled/available. Is there any recommendation on how to use clojure-ts-mode with cider at the moment?

vemv20:08:39

A GH issue would be most welcome The only input we have so far is https://github.com/clojure-emacs/cider/issues/3356#issuecomment-1601174777

lispers-anonymous15:08:41

Cider builds a lot of functionality on top of clojure-mode at the moment and as you've discovered isn't aware of clojure-ts-mode's existence. I suspect some time in the future we will start building awareness of clojure-ts-mode into cider, or perhaps write some sort of compatability layer on top of clojure-ts-mode that acts like clojure-mode. Right now I don't have an "official" suggestion other than to do what you are doing right now and patching things up to make them work as you encounter them. Maybe some of the solutions you find could be submitted to cider? It may not be what we land on but would get the conversation started for how to start integrating clojure-ts-mode and other packages.

πŸ’― 2
lispers-anonymous15:08:44

Yeah, that's what I'm thinking of in term of a compatibility layer. You are spot on there.

lispers-anonymous16:08:32

I wonder how it would work if clojure-ts-mode just defined functions with the exact same name in clojure-mode, like clojure-find-ns for instance, and then at the end of the file called (provide 'clojure-mode) . As long as clojure-ts-mode is loaded before cider this would work. Whatever the solution, it shouldn't be noticed by users IMO

lispers-anonymous16:08:52

(defvar clojure-ts--find-ns-query
  (treesit-query-compile
   'clojure
   '(((source (list_lit
               :anchor (sym_lit name: (sym_name) @ns)
               :anchor (sym_lit name: (sym_name) @ns-name)))
      (:equal @ns "ns")))))

(defun clojure-ts-find-ns ()
  "Return the name of the current namespace."
  (let ((nodes (treesit-query-capture 'clojure clojure-ts--find-ns-query)))
    (treesit-node-text (cdr (assoc 'ns-name nodes)))))
This is the total implementation of find-ns in clojure-ts-mode. https://github.com/clojure-emacs/clojure-ts-mode/blob/d630cd63af8022d5a1fee0e7aa05450b6e0fd75e/clojure-ts-mode.el#L673-L684

πŸ‘€ 2
vemv19:08:59

> I wonder how it would work if clojure-ts-mode just defined functions with the exact same name in clojure-mode Not sure if I would be a fan myself, since older packages would still depend on clojure-mode. So order would be determined by the package dependency tree? Wouldn't sound fun to troubleshoot / support πŸ™ƒ

lispers-anonymous20:08:24

Haha, fair enough. Just a fleeting thought.

bozhidar11:08:49

I'd prefer to make the compatibility more explicit myself - like the checks proposed above for CIDER to just wrap whatever functionality it needs from clojure-mode in functions that try both clojure-mode and clojure-ts-mode. (or something along those lines) Perhaps there can be even a config option in CIDER for which major mode to prefer.

πŸ‘ 4
bozhidar11:08:41

Shouldn't be very hard to do - I guess the only tricky part would be some REPL-powered font-locking and indentation when you're using clojure-ts-mode, but we can simply disable this in the beginning.

lispers-anonymous12:08:02

> I guess the only tricky part would be some REPL-powered font-locking and indentation when you're using clojure-ts-mode, but we can simply disable this in the beginning That is going to be tricky

bozhidar12:08:48

It's not essential, so I assume most people will be able live without it for a while. I'm not sure we'll be able to update the TS grammar's on the fly the way we've been doing it for clojure-mode.

lispers-anonymous12:08:53

The grammar we cannot update on the fly since it is statically compiled

lispers-anonymous12:08:06

But some of the rules we may be able to, although many of the tree-sitter facilities are setup such that they are captured when the mode is initialized.

bozhidar13:08:18

We'll figure something out. As I said that's not an essential feature, so I don't see it as some roadblock.

vemv19:08:39

ℹ️ Starting from today's snapshot (`<tel:202308281813|20230828.1813>` , or simply master if Git is your jam), CIDER has a revamped enrich-classpath integration. Over the last couple months (and after a long pause) I've reworked that lib, and its integration into cider.el. enrich-classpath allows you to interact with Java sources in autocompletions, navigation, documentation and stacktraces. It makes available both third-party Java sources, and the sources from the JDK itself. What's new? β€’ Categorically more robust β€’ Integrates with Lein and now Clojure CLI β€’ If you use Lein, your repl will use just one JVM backed by a clean java command, instead of Lein's usual two-JVM approach https://docs.cider.mx/cider/config/basic_config.html#use-enrich-classpath and other http://docs.cider.mx pages are its documentation for now. (enrich's https://github.com/clojure-emacs/enrich-classpath on github is outdated atm) tldr: opt in to (setq cider-enrich-classpath t) , and enjoy it when jacking in to JVM projects. (No cider-connect usage is documented for now) Bear in mind the first run will be a touch slow for a given project. Feedback would be extremely useful before releasing CIDER 1.8.0. 🍎🍏

πŸ‘€ 10
9
πŸŽ‰ 10
πŸ™€ 4
hifumi12321:08:56

Is it intended that cider-jack-in-clj simply freezes emacs while it loads? I am using Emacs 28.2 and just ran M-x straight-pull-package-and-deps and M-x straight-rebuild-package to try out the latest CIDER

hifumi12321:08:27

the previous behavior I would see the leiningen command invoked in my message buffer and wait β€” it was async

hifumi12321:08:05

these changes also seem to have broken a few leiningen options (e.g. repl options like :init-ns doesnt work anymore)

vemv21:08:08

It can appear to freeze since it's doing stuff. Can take a good minute on a large project

vemv21:08:58

> these changes also seem to have broken a few leiningen options (e.g. repl options like :init-ns doesnt work anymore) Interesting. I honor :init but hadn't thought of :init-ns

hifumi12321:08:08

:global-vars doesnt work either

hifumi12321:08:40

in short I have a project with the following set

:repl-options {:init-ns foo.bar}
:global-vars {*warn-on-reflection* true}
and I start in the user namespace with *warn-on-reflection* set to false

vemv21:08:51

I'll see what I can do about that one. Maybe it's easy. Note that Clojure CLI doesn't offer that, so it's in a grey zone

vemv21:08:40

> Is it intended that cider-jack-in-clj simply freezes emacs while it loads? I infer from your other feedback that the command eventually succeeded?

hifumi12322:08:00

Yes, it succeeded. It just froze all of Emacs until the REPL appeared. The previous behavior in CIDER was spawning lein and I was able to do other things while waiting

vemv22:08:17

Thanks. I'll consider it. It's certainly a nuisance. With Enrich's caching (which is partly shared across projects - much like ~/.m2), as you use it more, load times will decrease. With a bit of luck I can simply use whatever async facility made this work for traditional jack-in.

πŸ‘ 2
hifumi12322:08:19

Is it possible to downgrade CIDER in the meantime? I assume this would depend on the package manager on uses in Emacs

vemv22:08:47

cider-enrich-classpath defaults to nil - you got it changed at some point

hifumi12322:08:11

yeah, I have it set to t by default since I find the functionality useful, though the current workflow is disrupting a few of my lein projects

hifumi12322:08:44

in particular, im noticing the dev profile is not being applied (though this is set by myself in a custom lein command in cider)

vemv22:08:21

Does it really take more than a few seconds after the first time though? Profiles should be applied, I've used that myself every day let's debug it

hifumi12322:08:33

i.e. I have cider-lein-parameters set to "with-profile +dev repl :headless :host localhost", but one of my larger projects is no longer applying some stuff in the dev profile. itll be tough to make a repro but I can try soon

hifumi12322:08:00

I havent tested startup time when restarting cider, but I can try that right now

vemv22:08:09

my cider-lein-parameters are:

"with-profile \"+async-checking,+test,+dev,+emacs-backend,+emacs-backend-init,+yourkit,+g1gc,+parallel-reload,+cider-nrepl-latest\" repl :headless :host localhost"
And all of them are applied

hifumi12322:08:08

I see. I just attempted restarting CIDER, though the REPL only clears itself. However, if I quit the REPL then run M-x cider-jack-in-clj, Emacs freezes for about 10 seconds, but this is way faster than the first startup πŸ™‚

vemv22:08:21

Please paste the output of M-: (cider--extract-lein-profiles cider-lein-parameters) ? The other thing to keep in mind is, as mentioned, :init-ns and :global-vars are disregarded. Which is not a profiles bug, it's something else

hifumi12322:08:27

("with-profile +dev " "repl :headless :host localhost")

πŸ‘ 2
hifumi12322:08:01

It looks like the profiles do work. I just did a search in the java invocation and indeed I see the extra source paths provided by dev. Sorry for the distraction

πŸ‘ 2
vemv22:08:23

No issue! > Emacs freezes for about 10 seconds, but this is way faster than the first startup Pretty good news! > I just attempted restarting CIDER, though the REPL only clears itself. Ah, I'm not a sesman-restart user myself so it escaped my mind. It's an important thing to support. Thanks for the round of feedback! I've gotten awesome value from it.

gratitude 2
vemv22:08:39

To you and anyone else reading - I have to take a pause from CIDER hacking till Friday, then I will happily push the next iteration.