hi π I'm seeing some LSP crashes in a Clojure project where i'm pulling dependencies from alternative Maven repos:
:mvn/repos {"bintray" {:url ""}}
https://github.com/teodorlu/lab/blob/502cb8e84ec79677c9835cdd4935c4b91bb7baff/deps.edn#L20. Putting more details in thread π$ clojure-lsp --version
clojure-lsp 2023.02.27-13.12.12
clj-kondo 2023.02.17please let me know if there's more relevant information I can add!
AFAIK bintray was shutdown recently, and that is expected, clojure-lsp runs bb print-deps --format classpath under the hood, does that works if you run in your terminal?
that' s weird, could you try /home/teodorlu/.local/bin/bb print-deps --format classpath exactly?
Note -- the library in question has moved to maven central, so I should probably remove the bintray stuff anyway:
last comment (deleted) was from ~ . I suspect that's not what you wanted. Here's from project directory.
oh yeah, that should run from project root, and then we can see a Could not find artifact , to confirm you can echo $? after running that command to check if the status code was really 0, if not 0, clojure-lsp will fail indeed
$ pwd
/home/teodorlu/dev/teodorlu/lab
$ /home/teodorlu/.local/bin/bb print-deps --format classpath
[...]
$ echo $?
0Weird, I don't see Exception in thread "main" java.io.FileNotFoundException: /home/teodorlu/.clojure/.cpcache/3713B5C5B574229AE20967508893587F.cp (No such file or directory) when you run in the terminal, I think it's related with the clojure your editor has in PATH, @borkdude may know more about it, bb delegates to clojure IIRC
Can you just run bb print-deps --format classpath manually, did you try that?
@borkdude i believe I did that here: https://clojurians.slack.com/archives/CPABC1H61/p1678456335620479?thread_ts=1678453765.804219&cid=CPABC1H61
I've installed bb in ~/.local/bin :
$ which bb
/home/teodorlu/.local/bin/bbI don't feel like reading this thread right now as I'm busy, but if you can summarize your problem in a digestible way, I'd maybe be able to help
I am no longer able to reproduce the clojure-lsp error in the original post. It might have been me messing up something all along, or hitting something path dependent / something related to caching.
π
Let's leave this as "probably teodor messing something up" for now, then I can try to reproduce properly next time. Sorry, guys!
no problem :)
Greetings everyone!
I'm hoping someone can provide me with some guidance on how to approach this
bug: here's the link to the GitHub issue:
https://github.com/emacs-lsp/lsp-mode/issues/2698
The bug is that when the clojure-toplevel-inside-comment-form feature is
enabled, Emacs will freeze if your cursor is on the word "comment".
I'm curious about the root cause of this behavior. While it has been mentioned
in the lisp-mode repository that this is not an issue with lsp-mode itself, I'm
wondering if anyone knows where it's coming from.
Thank you βΊοΈ!
I'm using emacs 28. Now, I was trying to find a reproducible case, and I deleted and re-created my .emacs.d directory. I can't reproduce it either right now, I'll keep an eye out, though, I think I'll see it soon again and at that point I will report back
I've been using Emacs 28 when experiencing this issue and only used Emacs 28 built with native compilation enabled. I'll build Emacs 29 from source with native compilation and see if I get the same issue.
I have the same issue when using Emacs 29 built with --native-compilation=aot although the issue seems to occur a little less often.
It can take a few seconds of moving the cursor around before freezing. It most often freezes when moving the cursor over the opening paren of the comment expression and when I see Beginning of line in the mini-buffer.
Tomorrow, I'll try building emacs without native-compilation to see if it makes any difference
(Note: I am finding Emacs 29 native compilation a little faster with very long files than 28, which was already greatly much faster with native compilation. So I'd choose native compliation over the comment feature in cider)
I was just able to confirm that I don't have to have a repl active for this bug to happen @ericdallo. I'm able to reproduce it this way now: I hold my cursor at column 0 and start going down the rows till I land on the beginning of a (comment block (the initial parentheses. I leave the cursor there for 2-3 seconds and then the bug is triggered
yeah, I can't understand why lsp is relevant for the issue, maybe since you have a repro you could toggle-debug-on-quit and repro the issue, when emacs freeze, type C-g and emacs should present a stacktrace of what was doing at that time so we can analyze, timing is important here.
Debugger entered--Lisp error: (quit)
comment-normalize-vars()
clojure--looking-at-non-logical-sexp()
clojure-forward-logical-sexp(1)
clojure-sexp-starts-until-position(9)
clojure-beginning-of-defun-function(1)
beginning-of-defun-raw(nil)
beginning-of-defun()
clojure-font-lock-def-at-point(1)
clojure-font-lock-extend-region-def()
font-lock-default-fontify-region(1 10 nil)
apply(font-lock-default-fontify-region 1 10 nil)
#f(compiled-function (beg end &rest rest) #<bytecode -0x1baf75981233e6ab>)(1 10 nil)
apply(#f(compiled-function (beg end &rest rest) #<bytecode -0x1baf75981233e6ab>) 1 10 nil)
#f(compiled-function (beg end &rest rest) #<bytecode 0xfdbbc7d97634f8>)(1 10 nil)
font-lock-fontify-region(1 10)
#f(compiled-function (beg end) #<bytecode -0x177bfa55fe4edd87>)(1 10)
font-lock-ensure()
markdown-fontify-code-block-natively("clojure" 12 20)
markdown-fontify-code-blocks-generic(markdown-match-gfm-code-blocks 192)
markdown-fontify-gfm-code-blocks(192)
font-lock-fontify-keywords-region(1 192 nil)
font-lock-default-fontify-region(1 192 nil)
font-lock-fontify-region(1 192)
#f(compiled-function (beg end) #<bytecode -0x177bfa55fe4edd87>)(1 192)
font-lock-ensure()
lsp--fontlock-with-mode("clojure\ncomment\n\n\n----\n\n*[/home/carlo/code/c..." lsp--render-markdown)
lsp--render-string("clojure\ncomment\n\n\n----\n\n*[/home/carlo/code/c..." "markdown")
lsp--render-element(#<hash-table equal 2/2 0x10dad7f>)
#f(compiled-function (contents server-id) #<bytecode 0x7a94c7b9780490a>)(#<hash-table equal 2/2 0x10dad7f> clojure-lsp)
apply(#f(compiled-function (contents server-id) #<bytecode 0x7a94c7b9780490a>) #<hash-table equal 2/2 0x10dad7f> clojure-lsp nil)
lsp-clients-extract-signature-on-hover(#<hash-table equal 2/2 0x10dad7f> clojure-lsp)
lsp--handle-rendered-for-echo-area(#<hash-table equal 2/2 0x10dad7f>)
lsp--render-on-hover-content(#<hash-table equal 2/2 0x10dad7f> nil)
#f(compiled-function (input0) #<bytecode -0x176a9661cb6bf4c1>)(#<hash-table equal 2/2 0x10dac9f>)
apply(#f(compiled-function (input0) #<bytecode -0x176a9661cb6bf4c1>) #<hash-table equal 2/2 0x10dac9f>)
#f(compiled-function (&rest args) #<bytecode 0x8d56a12af6d91cb>)(#<hash-table equal 2/2 0x10dac9f>)
#f(compiled-function (result) #<bytecode -0x40cba87288b75a>)(#<hash-table equal 2/2 0x10dac9f>)
#f(compiled-function (result) #<bytecode -0x7e364647324b868>)(#<hash-table equal 2/2 0x10dac9f>)
lsp--parser-on-message(#<hash-table equal 3/3 0xd269203> #s(lsp--workspace :ewoc nil :server-capabilities #<hash-table equal 22/22 0xd1d9c7f> :registered-server-capabilities (#s(lsp--registered-capability :id "id" :method "workspace/didChangeWatchedFiles" :options #<hash-table equal 1/1 0xc2f323>)) :root "/home/carlo/code/clojure/couperin" :client #s(lsp--client :language-id nil :add-on? nil :new-connection (:connect #f(compiled-function (filter sentinel name environment-fn workspace) #<bytecode 0x12b24e3f73d7da1>) :test\? lsp-clojure--build-command) :ignore-regexps nil :ignore-messages nil :notification-handlers #<hash-table equal 1/65 0x129d3aed> :request-handlers #<hash-table equal 0/65 0xd99cef> :response-handlers #<hash-table eql 1/65 0xd99d0f> :prefix-function nil :uri-handlers #<hash-table equal 1/65 0xcbb4a1> :action-handlers #<hash-table equal 1/65 0x15e97bb> :major-modes (clojure-mode clojurec-mode clojurescript-mode) :activation-fn nil :priority 0 :server-id clojure-lsp :multi-root nil :initialization-options (:dependency-scheme "jar" :show-docs-arity-on-same-line\? t) :semantic-tokens-faces-overrides (:types (("macro" . font-lock-keyword-face) ("keyword" . clojure-keyword-face) ("event" . default))) :custom-capabilities ((experimental (testTree . t))) :library-folders-fn #f(compiled-function (workspace) #<bytecode -0x47e81772d0877b8>) :before-file-open-fn nil :initialized-fn nil :remote? nil :completion-in-comments? nil :path->uri-fn nil :uri->path-fn nil :environment-fn nil :after-open-fn nil :async-request-handlers #<hash-table equal 0/65 0xd99d2f> :download-server-fn #f(compiled-function (client callback error-callback update\?) #<bytecode 0x1730d7770fbcd0a3>) :download-in-progress? nil :buffers nil :synchronize-sections nil) :host-root nil :proc #<process clojure-lsp> :cmd-proc #<process clojure-lsp> :buffers (#<buffer velocity_profiles.clj> #<buffer generate_training.clj>) :semantic-tokens-faces nil :semantic-tokens-modifier-faces nil :extra-client-capabilities nil :status initialized :metadata #<hash-table equal 0/65 0x7b439fd> :watches #<hash-table equal 0/65 0x7b43b23> :workspace-folders nil :last-id 0 :status-string nil :shutdown-action nil :diagnostics #<hash-table equal 1/65 0x7b43f07> :work-done-tokens #<hash-table equal 0/65 0x7b43f27>))
#f(compiled-function (msg) #<bytecode -0x1e31a16976ddd1b1>)(#<hash-table equal 3/3 0xd269203>)
mapc(#f(compiled-function (msg) #<bytecode -0x1e31a16976ddd1b1>) (#<hash-table equal 3/3 0xd269203> #<hash-table equal 3/3 0x10dadcf>))
#f(compiled-function (proc input) #<bytecode 0x175efea64fc54320>)(#<process clojure-lsp> "Content-Length: 354\15\n\15\n{\"jsonrpc\":\"2.0\",\"id\":269,\"...")But I don't see the timing @ericdallo
Oh I think I see why this happens with lsp
lsp-mode has a a feature called https://clojure-lsp.io/features/#document-highlight-on-hover-showing-symbol-usages that is used for 3 "features" in emacs:
β’ show the highlight of the hovered symbol as the gif
β’ show the info about the sym in the minibuffer (for clojure the signature/documentaiton)
β’ show detailed info retrieved from hover if user lsp-describe-thing-at-point (`K` for doom users)
So, for some functions, the docstring may contain markdown showing a code snippet like
`` `clojure-mode
some code here
`` `
so when lsp-mode finds that, it calls the clojure-mdode to color that presenting beautifully in the editor (print 2).
That's why lsp-mode is calling clojure-mode.
Even so, seems to be a performance issue or something in clojure-mode, you could disable that feature on lsp, but IMO is a really good feature for a Clojure IDE, so disabling that variable from clojure-mode is probably the best workaround, but the best would be fix the performance issue in clojure-modeI see, what's the variable that could be disabled on clojure-mode? I might try doing that
Also, which function/macro would be containing docstrings formatted in a certain way @ericdallo? comment itself doesn't have a complex docstring. Interestingly, if I try to invoke lsp-describe-thing-at-point (`K` for me) I get the freeze!
clojure-toplevel-in-comment-form more details https://clojurians.slack.com/archives/CPABC1H61/p1678475201269779?thread_ts=1678470309.301829&cid=CPABC1H61
no, but I would prefer to not disable that, as I said before, I though you were mentioning an alternative, my bad
@meditans most of clojure.core/cljs.core stuff, since we get detailed docs from clojuredocs Check the second print
you could disable clojuredocs integration, but I also find it quite useful, even so you may face in some other vars that contains code snippets
Here's the thing though: when I do lsp-describe-thing-at-point I don't get the clojuredocs stuff, to get that I have to do cider-doc. I don't get any documentation on hover in fact
(or cider-clojuredoc ). The point being, I always call that manually if I need it, I would be fine with disabling it if it can be the cause of this. What would be the relevant variable?
hum, you can debug why clojuredocs is not showing in server logs after server startup it should request clojuredocs and cache. But, from your stacktrace we can see it's rendering a simple clojure markdown only for the function signature which clojure-lsp does for almost every var
lsp--fontlock-with-mode("clojure\ncomment\n\n\n----\n\n*[/home/carlo/code/c..." lsp--render-markdown)it doesn't look related to cider and even disabling clojuredocs won't be enough
yeah, I think there is no way to fix it only on lsp side besides disabling hover feature entirely (`lsp-eldoc-enable-hover`)
I would be fine with disabling hover, but I'm not using eldoc, so, maybe lsp-ui-doc? I can try disabling a couple of lsp options
yes, that's used by lsp-ui-doc
Oh, ok, my bad, I did (after! clojure-mode (setq lsp-eldoc-enable-hover nil)) and the problem seems solved! I will do a couple more tests
Nice catch, I'll also try with lsp-eldoc-enable-hover nil as I find the hover distracting. I had disabled lsp-ui-doc but it seems that was not the full story. I also never get anything useful in lsp-describe-thing at-point, so prefer to switch off LSP features that I don't or can't use I would prefer to trigger the doc by key binding, so have enabled LSP peek instead, so will check if peek is okay with lsp-enable-eldoc-hover set to nil
I've seen that been mentioned in some channels but I couldn't repro though, IIRC was something related with clj-refactor and clojure-mode, so my suggestion would be to first isolate the package that causes the issue first
Maybe @elken could know something
I also remember someone asking about this
I'm not near a computer for a while but I'll try and have a look when I can if I can repro
If it can be useful, I'm using doom emacs, and my clojure configuration is the default (apart from that option and some unrelated stuff)
@meditans maybe you can help isolate the problem like: does it happens with a REPL connected? does the buffer size affects that?
Sure, let me check!
I mentioned this issue 5 days ago (two posts ago)
https://clojurians.slack.com/archives/CPABC1H61/p1678052829442559?thread_ts=1678052829.442559&cid=CPABC1H61
For a quick fix, just disable the variable in question
If looking to diagnose and resolve the issue then I suggest a fix for this clojure-mode feature is most appropriate. I don't think it's specific to just LSP (although that may help trigger the issue)
There are two different tockets raised on the clojure-mode repository regarding this issue. The most recent ticket suggests its triggered by LSP or native-compilation (or both). The older ticket probably caused by something else due to its age
comment forms are treated differently in Clojure when clojure-toplevel-in-comment-form is enabled
It seems this different behaviour can lead to 100% CPU from several possible triggers.
Do you set that variable @meditans AFAIK the default value of it for doom is nil already
I do set that variable myself @ericdallo, comment blocks are a lot less ergonomic without the option, which is why I'm trying to keep it on. @jr0cket do you have it disabled? How do you evaluate inside comments?
Ah, I see you posted your workaround in the other thread, nevermind
Yes, I have only recently disabled this clojure-mode feature. I had been noticing something toward the end of last year (around the time I switched to Emacs 28 with native-compilation I believe - so that could be a cause). I had used this feature for years before that very successfully and without lockup. I use vim-style editing, so I use cider-eval-last-sexp command (, e e key binding in my Spacemacs & Doom Emacs configs). I place the cursor on the line after the expression as vim-style cursor doesnt go beyond the last closing parens of an expression on the same line. It was a convienient feature of clojure-mode, although its easy to work around it. The next time I build Emacs from source I'll create a build without native-compilation to see if I can rule that out. I am farily sure I have been using LSP far longer than native compilation, so it seems to my limited testing to be the most likely candidate. I dont thing the code in clojure-mode has been changed in a while. It could be clojure-lsp or lsp-mode or lsp-ui, but that seems less likely.
So I just tried to repro this and can't. Have I missed something?
REPL output. Maybe it's fixed on 29
Hi everyone:slightly_smiling_face:
Can anyone help me to get lsp to pick up the correct classpath in a monorepo?
I have a react-native project in project-root/rn that is compiled with shadow-cljs that relies on project-root/rn/deps.edn for dependency resolution (via :deps true)
I have created a project-root/deps.edn with
{:paths []
:aliases {:dev {:extra-paths ["rn/src"
"backend/src"]
:extra-deps {clojure-lsp/lib {:local/root "rn"}
clojure-lsp/cli {:local/root "backend"}}}}}
and a project-root/shadow-cljs.edn with:
{:source-paths ["rn"]}
yet when I do cd project-root && npx shadow-cljs classpath from the root it doesnβt pick up the (at least some) dependencies (like reitit for example) while they are included in:
cd project-root/rn && npx shadow-cljs classpath
As lsp seems to execute that same command to determine the classpath I am guessing it is the reason why I canβt navigate into these librariesThe extra-deps clojure-lsp/lib looks familiar π π
hum, that's a interesting case
oh yeah, I totally borrowed that from a snippet of yours:innocent:
The main issue is: you have two dependency manager tools that relies on different project-roots if shadow supports something like clojure to point to sub folders that would probably work, but I don't know if that option exists
but, for a complex case like that, we have a more generic setting called :project-specs which you can define what command will be executed for which file
and for shadow you can probably have a custom script that cd to the rn dir and run that command
pretty tricky, but I know projects that did that and worked
example:
project-root/.lsp/config.edn
{:project-specs [{:project-path "deps.edn"
:classpath-cmd "clojure -A:dev:test -Spath"}
{:project-path "shadown-cljs.edn"
:classpath-cmd "cd project-root/rn && npx shadow-cljs classpath"}]} ;; or a custom shell scriptthank you! I will experiment with it, it looks like what I need.
In the :classpath-cmd is it necessary to append the project-root/ to cd?
I would have assumed I could do cd rn && npx shadow-cljs classpath from the root.
Unfortunately I canβt seem to get it to work with either variant.
not necessary, I wrote that manually without even checking if the parens match π
they did:grin:
yeah, I had a feeling the && wouldn't work, but I think it works if you move it to a custom shell script
in project-root/.lsp ?
or in the root?
whatever you prefer
hm I have:
{:project-specs [{:project-path "deps.edn"
:classpath-cmd "clojure -A:dev:test -Spath"}
{:project-path "shadown-cljs.edn"
:classpath-cmd ["sh ./full-classpath.sh"]}]}
with full-classpath as
#!/usr/bin/env sh
cd rn && npx shadow-cljs classpath
still canβt navigate into libraries after restarting the lsp server unfortunately.
Is there some sort of caching involved?I might have to play with it some more
is it possible to examine the classpath from within emacs?
okay well:
LSP :: Classpath lookup failed in clojure-lsp. Some features may not work correctly.
this might be the culprit^^yes lsp-clojure-server-info
but that only works after server started correctly
check the https://clojure-lsp.io/troubleshooting/#server-log, it will tell what is going wrong
Yes.
Thank you!!π
I had to wrap the :classpath-cmd value for the deps.edn project-path into a vector and split the string.
even though only the first project-spec was throwing an error uncommenting it didnβt work (though it did got rid of the error message)
But fixing that everything else fell into place.
thanks a ton for your help!
as reference for others that might stumble across this:
{:log-path "/tmp/clojure-lsp.log"
:project-specs [{:project-path "deps.edn"
:classpath-cmd ["clj" "-A:dev" "-Spath"]}
{:project-path "shadown-cljs.edn"
:classpath-cmd ["sh ./full-classpath.sh"]}]}
is my .lsp/config.ednAwesome, I may add a guide for that soon in clojure-lsp, thanks for helping testing that kind of project
sure thing! looking forward to it!