Fork me on GitHub
#lsp
<
2021-03-21
>
Carlo12:03:55

Hey @ericdallo, I have a question on tooling: I open the clojure-lsp project in emacs, then open the file clojure-lsp/test/clojure_lsp/features/call_hierarchy_test.clj (at which point my lsp server auto-starts), then I do cider-jack-in-clj (with clojure-cli). Then I try to evaluate the clojure-lsp.features.call-hierarchy-test namespace I'm in with M-x cider-eval-buffer , and I get:

2. Unhandled clojure.lang.Compiler$CompilerException
   Error compiling test/clojure_lsp/features/call_hierarchy_test.clj at (1:1)
   #:clojure.error{:phase :compile-syntax-check,
                   :line 1,
                   :column 1,
                   :source
                   "/home/carlo/code/clojure/clojure-lsp/test/clojure_lsp/features/call_hierarchy_test.clj"}
             Compiler.java: 7652  clojure.lang.Compiler/load
                      REPL:    1  user/eval22442
                      REPL:    1  user/eval22442
             Compiler.java: 7181  clojure.lang.Compiler/eval
             Compiler.java: 7136  clojure.lang.Compiler/eval
                  core.clj: 3202  clojure.core/eval
                  core.clj: 3198  clojure.core/eval
    interruptible_eval.clj:   87  nrepl.middleware.interruptible-eval/evaluate/fn/fn
                  AFn.java:  152  clojure.lang.AFn/applyToHelper
                  AFn.java:  144  clojure.lang.AFn/applyTo
                  core.clj:  667  clojure.core/apply
                  core.clj: 1977  clojure.core/with-bindings*
                  core.clj: 1977  clojure.core/with-bindings*
               RestFn.java:  425  clojure.lang.RestFn/invoke
    interruptible_eval.clj:   87  nrepl.middleware.interruptible-eval/evaluate/fn
                  main.clj:  437  clojure.main/repl/read-eval-print/fn
                  main.clj:  437  clojure.main/repl/read-eval-print
                  main.clj:  458  clojure.main/repl/fn
                  main.clj:  458  clojure.main/repl
                  main.clj:  368  clojure.main/repl
               RestFn.java:  137  clojure.lang.RestFn/applyTo
                  core.clj:  667  clojure.core/apply
                  core.clj:  662  clojure.core/apply
                regrow.clj:   20  refactor-nrepl.ns.slam.hound.regrow/wrap-clojure-repl/fn
               RestFn.java: 1523  clojure.lang.RestFn/invoke
    interruptible_eval.clj:   84  nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:   56  nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:  152  nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn
                  AFn.java:   22  clojure.lang.AFn/run
               session.clj:  202  nrepl.middleware.session/session-exec/main-loop/fn
               session.clj:  201  nrepl.middleware.session/session-exec/main-loop
                  AFn.java:   22  clojure.lang.AFn/run
               Thread.java:  834  java.lang.Thread/run

1. Caused by java.io.FileNotFoundException
   Could not locate clojure_lsp/test_helper__init.class,
   clojure_lsp/test_helper.clj or clojure_lsp/test_helper.cljc on classpath.
   Please check that namespaces with dashes use underscores in the Clojure file
   name.
Am I doing something wrong?

ericdallo12:03:02

Could you try jack in as a lein project?

Carlo12:03:58

thanks @ericdallo, jack-in as lein works. Could you explain me why that's the case? Isn't the presence of a deps.edn file enough for clojure-clj?

ericdallo13:03:02

the clojure-lsp is actually a lein project that read the dependencies from deps.edn file, we need to migrate to full dep.edn 😅

🙌 3
dpsutton13:03:33

If you try using the clojure cli again does it work? It’s been a bit but I think there’s some Java that lein compiles that clj obviously doesn’t know about

ericdallo13:03:51

yes, @U11BV7MTK is correct, that branch I refered fix that, but we need to fix other things to that work as well

Carlo14:03:21

Another question: in my emacs setup I have (setq lsp-clojure-custom-server-command '("bash" "-c" "cd /home/carlo/code/clojure/clojure-lsp && lein run")). I open emacs, visit the file clojure-lsp/src/clojure_lsp/feature/call_hierarchy.clj , jack-in using lein, use cider-eval-defun-at-point with an universal argument to toggle the debugging on the function incoming, then I call M-x lsp-treemacs-call-hierarchy on element-by-uri->incoming-usage-by-uri , expecting the call to be intercepted and debugged via cider (it has to pass via the incoming function). But that doesn't happen. What am I missing?

ericdallo14:03:25

I never used that as (setq lsp-clojure-custom-server-command '("bash" "-c" "cd /home/carlo/code/clojure/clojure-lsp && lein run"))`` not sure why you need that. these are the steps I do to work:

ericdallo14:03:11

1. I generate a local release to test with lein with-profile :debug bin 2. I point emacs to use that release: (setq lsp-clojure-custom-server-command '("bash" "-c" "~/dev/clojure-lsp/target/clojure-lsp")) 3. I open the https://github.com/ericdallo/clojure-sample, (could be any clojure project) and and wait until LSP starts. 4. I get the port of the running clojure-lsp on the project with lsp-clojure-server-info , it should print a :port xyz 5. I go to clojure-lsp and use cider-connect-clj and pass the port xyz 6. Now every function I eval on clojure-lsp project, it will affect the running session of clojure-lsp on my sample project

Carlo14:03:46

let me try this again then. I seem to remember that the problem with this approach is that if you use cider-connect-clj you won't have cider-nrepl middleware automatically injected, and so you won't be able to flag functions for debugging in cider. Is there a workaround for that? @U11BV7MTK mentioned connecting to the repl the way clojure-clj does it (which, as I understand, injects the appropriate middlewares) which is what brought me to the previous question

Carlo14:03:10

so, in your method, does universal-argument M-x cider-eval-defun-at-point work?

ericdallo14:03:38

Good question, never tried that, but you could add the middleware manually I think via some cider variable?

Carlo14:03:22

that's the thing, from my admittedly little experience, I think a middleware has to be injected in the nrepl initialization, and I didn't find a way to do it only from the emacs side

ericdallo14:03:07

or cider-jack-in-nrepl-middlewares

Carlo15:03:15

the documentation for lein you linked suggests to add something like

{:repl {:plugins [[cider/cider-nrepl "0.25.2"]]}}
to the project.clj . I modified the :debug section (since it seems to be the one I'm invoking:
:debug ^:leaky {:dependencies [[nrepl/nrepl "0.8.3"]
                                            [cider/cider-nrepl "0.25.9"]]}

ericdallo15:03:48

that worked?

Carlo15:03:56

but I'm not sure on the invocation:

$ lein with-profile :debug bin
OpenJDK 64-Bit Server VM warning: Options -Xverify:none and -noverify were deprecated in JDK 13 and will likely be removed in a future release.
Performing task 'bin' with profile(s): ''
Warning: profile : not found.
WARNING: seqable? already refers to: #'clojure.core/seqable? in namespace: clojure.core.incubator, being replaced by: #'clojure.core.incubator/seqable?
WARNING: seqable? already refers to: #'clojure.core/seqable? in namespace: clostache.parser, being replaced by: #'clojure.core.incubator/seqable?
Warning: profile : not found.
Warning: profile : not found.
Warning: profile : not found.

ericdallo15:03:16

try with: lein with-profiles +debug bin

Carlo15:03:59

ok that eliminates the warning, why does +debug work instead of :debug which is what's written in project-clj?

ericdallo15:03:18

when you +profile , lein add that profile to the existing instead of using only the one you provided

ericdallo15:03:32

I don't know why that removes the warning though

ericdallo23:03:14

clojure-lsp Released https://github.com/clojure-lsp/clojure-lsp/releases/tag/2021.03.21-23.29.19 version: • Bump a lot of libs: rewrite-clj (v1), lsp4j, guava, data.json • Add new code action: Resolve macro as... 🎉 : The Resolve macro as feature asks to user how clj-kondo should lint that macro from common used macros only (for now), and on what clj-kondo config file it should save the :lint-as map. Thanks to @borkdude and @lee for the help to make that happen. This feature was something that since I started programming Clojure I missed on other editors than Cursive and now that is possible starting from Emacs editor (make sure to update lsp-mode package) 😄

🎉 39
clojure-lsp 18
clj-kondo 12
ericdallo23:03:37

@U9A1RLFNV LMK if need any help setting up that new action on Calva, it will need to code something for that work

👍 3
snoe01:03:25

how does it work, code actions should be editor agnostic right?

nmkip01:03:29

Will it be available in AUR?

ericdallo02:03:54

@U0BUV7XSA this action uses a lsp-mode feature called action-handler, it's used on lsp-java, rust and other LSP, it's useful to when you need user input before applying the action, But yeah, the editor needs to handle that as well

ericdallo02:03:35

@UJCC6CE9E yes, probably @U11EL3P9U will release it tomorrow

dharrigan04:03:10

It's there now 🙂

nmkip22:03:07

Thanks! Just updated 🙂

🚀 6