Fork me on GitHub
#emacs
<
2022-11-08
>
Casey14:11:13

I have a buffer that is constantly hanging emacs. When I toggle-debug-on-quit and C-gduring the hang, I get this backtrace. I suspect the problem is related to the fact that I am using local vars named comment (shadowing clojure.core/comment). Based off this backtrace can anyone point me in the direction of which project I should report this to? (FWIW I'm using latest doom emacs)

dpsutton14:11:01

most likely clojure-mode.

dpsutton14:11:35

One thing is check if clojure-toplevel-inside-comment-form is t. Try setting it to nil and seeing if that helps

dpsutton14:11:00

I think this could be the “top of defun” feature is breaking with the overload of comment

Casey14:11:17

Oh it's definitely t I use that feature alot

Casey14:11:28

I'll try disabling it and see if the hangs stop.

dpsutton14:11:28

agree. I do as well

vemv14:11:38

it look like a good mixture of things 🌀 lsp, markdown, clojure-mode

Casey14:11:22

i'm not sure where the markdown is coming from 😕 aside from the fact that the doom markdown package is enabled. not sure why it's running in my clojure-mode though

vemv14:11:08

the root of your stacktrace says lsp-fontlock. you might want to disable it. CIDER already provides sweet font-locking which is not exclusive at all with clojure-lsp

Casey14:11:51

what is font locking exactly?

dpsutton15:11:47

I suspect this might be related to lsp ui? Maybe the doc popups? Perhaps it grabs the source and puts it inside of a markdown string and renders that?

1
ericdallo15:11:18

Not really, it's a lsp-mode core feature, that when hovering in a element, it shows the docs of the symbol, so we font-lock the clojure code

ericdallo15:11:43

but I do see clojure-mode on the exception, and my guess is there the issue

ericdallo15:11:08

lsp font-locking just called clojure-mode font locking

vemv15:11:47

but it's wrapped in markdown (as seen in the stacktrace), surely that makes it unparsable to clojure-mode

ericdallo15:11:22

hum, odd, I think it should not cause any issue as all other LSP langs do the same

ericdallo15:11:33

clojure-mode should at least ignore I think

vemv15:11:13

ignore what - arbitrary markdown syntax? seems an odd requirement :thinking_face: I'm hypothesizing about how this stuff works, just by judging the stacktrace, but if markdown is passed to clojure-mode, better to strip the markdown delimiters beforehand

ericdallo15:11:18

Explaining better the feature: • client requests information about the symbol, docs, clojure code example etc via lsp hover request • server response with custom markdown showing all the docs + clojure code as a string. • client(Emacs) just delegate to the major mode to apply font locking on what is inside the clojure markdown, but AFAIK it should not send markdown to clojure-mode

👍 1
vemv15:11:45

checking out the stacktrace again, the string starts with comment not (comment that's the issue - unbalanced parentheses (either on the buffer itself, or due to some bug in the responsible code)

ericdallo15:11:29

I think it's expected to have invalid code all the time while developing, shouldn' t clojure-mode handle that better?

vemv15:11:39

depends on the definition of invalid code you should have balanced parentheses 99% of the time which emacs makes really easy although it is to be confirmed that @U70QFSCG2’s buffer actually has unbalanced parentheses

ericdallo15:11:10

I think we should not expect user has a paren tool or something like that, at least o clojure-lsp, clj-kondo we always need to handle invalid code which is more common that we think

vemv15:11:42

let's keep it simple and determine first the actual issue :)

👍 1
Casey16:11:45

I use lispyville and lispy to prevent unbalanced parens.

Casey16:11:32

So no.. there aren't unbalanced parens in this case (though it can happen if you paste in text containing unbalanced parens, but that wasn't the case here)

Casey16:11:44

> One thing is check if clojure-toplevel-inside-comment-form is t. Try setting it to nil and seeing if that helps This definitely fixed it.. when nil I don't get any hanging

Casey16:11:58

here is a full stacktrace (the previous was cutoff)

dpsutton16:11:42

nice. if we can figure out a minimal case we can solve it. don’t think we can use runtime information to know that comment is not clojure.core/comment though

Casey16:11:07

(ns app.bug
  (:refer-clojure :exclude [comment]))


(def comment {:comment/body "I probably shouldn't be using comment"})

Casey16:11:18

I can trigger the bug with just this code

dpsutton16:11:16

ok. we can make it smarter by ignoring comment forms that don’t have a ( immediately preceding them

Casey16:11:32

I'm not sure how exactly to trigger it.. simply editing things in and round the def seems to trigger it sometimes. Even just using the mouse to place the point somewhere in that form will cause it

Casey16:11:57

That sound reasonable.. until we go and use a comment var as a function xD. But at least in this codebase I don't see myself doing that heh.

dpsutton16:11:32

yeah. but then if you do that its on you to not use the “comment acts as top level” then i guess

Casey16:11:45

that sounds fair to me

Casey16:11:44

Should I open a ticket on github?

vemv18:11:54

> don’t think we can use runtime information to know that comment is not clojure.core/comment though (ns-resolve 'comment)? and friends e.g. ns-interns (maybe you know this well and mean that clojure-mode can't do this without cider?)

dpsutton18:11:56

this is clojure-mode so we have no connection to a runtime

Apple16:11:05

when i connect to a shadow-cljs repl initially, cider thinks that i'm connected to a clj repl. all good. then if i does a switch like this

shadow.user> (shadow/repl :app)
To quit, type: :cljs/quit
[:selected :app]
cljs.user> 
then cider notices that i'm connected to a cljs repl while at the same time thinks i'm disconnected from a clj repl i can start a second clj repl to the same shadow-cljs and leave it in clj mode, but cider is not to be able to recognize that i'm connected to both clj and cljs repl. when i activate either the clj or cljs repl buffer, cider thinks i'm connected to the respective repl but disconnected from the other. how to make emacs cider support both repls at the same time?

ag16:11:43

I think you shouldn't start second REPL. You need to use cider-connect-sibling-cljs command

1
🎉 1
🙏 1
Apple16:11:42

THANK YOU SO MUCH!!!

ag19:11:06

matter of fact you should probably figure out the way to use cider-jack-in-clj&cljs that way it would automatically create two REPLs for you. And what's great about it that in .cljc files, if you set the major mode to clojure-mode - it will eval things in clj REPL, if you change it to clojurescript-mode - it will eval things in cljs-repl

👍 1
Valentin Mouret08:11:54

I am struggling to do this. I run cider-jack-in-clj&cljs and the Clojure REPL boots ok, but the ClojureScript one says: > error in process filter: ClojureScript is not available. See https://docs.cider.mx/cider/basics/clojurescript for details The docs are not very helpful there. Most likely my configuration is wrong, so I looked up full-stack projects on GitHub and mostly copied https://github.com/schnaq/cljs-re-frame-full-stack but the results are the same. Would you happen to have pointers to help me out here?

Apple14:11:41

here what i do with shadow-cljs: somewhere in your code just require these two lines

[shadow.cljs.devtools.api :as shadow]
   [shadow.cljs.devtools.server :as server]
then add
(server/start!)
(shadow/watch :app)
also in your deps add this
cider/cider-nrepl                    {:mvn/version "0.28.7"}
then you can get rid of all your other repl setup, just fire up the clojure, from within emacs do cider-connect then do cider-connect-sibling-cljs

Valentin Mouret15:11:26

Cheers! I will try that.