Fork me on GitHub
Dmytro Bunin10:08:31

Hey there. At my company we are using jest test runner for cljs tests. Which means we don’t use clojure.test and instead use our own macros that gets translated to js/describe and js/it etc. My question is is it possible to somehow let lsp know about our macros to make this work for our setup?


Could you share a test example?

Dmytro Bunin11:08:02

(require '[cljest.core :refer [describe it]])

(describe "foo"
  (it "returns bar"
    (m/=? "bar" (foo))))


Maybe try teaching clj-kondo to lint that describe as a var


{:lint-as cljest.core/describe clojure.test/deftest}


In your . clj-kondo/config.edn

Dmytro Bunin11:08:40

still treats it as a reference

Dmytro Bunin12:08:07

(defn test-reference? [source-path {:keys [filename]}]
  (and source-path
       (not (string/starts-with? filename source-path))
       (string/includes? filename "_test.")))

Dmytro Bunin12:08:51

I think this is used to split them up. We use _spec prefix. I guess that’s why they don’t show up.


yep, you are right


is _spec prefix a standard for cljest?

Dmytro Bunin12:08:56

it doesn’t need to be

Dmytro Bunin12:08:05

and we haven’t open sourced it yet

Dmytro Bunin12:08:17

we are just using it cos we have karma tests with _test prefix 😄


yeah, we could make it configurable I think with a default value of ["_test"]

Dmytro Bunin12:08:21

renaming to *_test, doesn’t help so I think it’s also something to do with classpath


hum, that function is only testing if: • the current var you are seeing references lens, is not in the test source-path of the usage (e.g. we only show that a var has test references if the var is on src and the test in another source-path like test) • the test reference filename has a _test in its filename • source-paths are properly configured (check lsp-clojure-server-info)

Dmytro Bunin12:08:57

so we have spec files next to the normal files

Dmytro Bunin12:08:13

eg src/a.cljs, and src/a_spec.cljs


yeah, that's a blocker ATM


if we can think on some kind of config generic that would work for most users and you we can create a issue


I noticed a regression last week, but I’m not sure if it’s in lsp-mode, or clojure-lsp. When using lsp-mode for xref-find-references on foo in (defn foo ..., previously, the results wouldn’t include the defn line, and if there was only one reference, it would navigate straight to it (without needing to select the single result in the minibuffer). Now it does include it, which means it never thinks there’s a single reference.


This is something on the LSP spec, the client can ask for a references to include it's definition, there is a lsp-mode var for that IIRC


from lsp-mode code:

(cl-defun lsp-find-references (&optional include-declaration &key display-action)
  "Find references of the symbol under point."
  (interactive "P")
  (lsp-find-locations "textDocument/references"
                      (list :context `(:includeDeclaration ,(lsp-json-bool include-declaration)))
                      :display-action display-action
                      :references? t))


could you try lsp-find-references instead?


lsp-find-references behaves in the same way


what's your clojure-lsp version?


❯ clojure-lsp --version
clojure-lsp 2022.07.24-18.25.43
clj-kondo 2022.06.23-SNAPSHOT


Hum, we didn't change anything on clojure-lsp recently related to that and it's working properly to me, so I guess it's something on lsp-mode/your config, not sure what though


Strange. I’m pretty sure it was working for me until very recently, and I don’t think I’ve changed anything related either.


Oh, it’s in the CHANGELOG for 8.0.1: lsp-find-references to include declaration by default


Oh, I was not aware of that :)


I suggest you ask on Emacs-lsp discord why the change and how to change to the previous one


Okay, will do. It doesn’t look configurable, so I guess I need to make a wrapper to pass in the parameter


yeah, a variable for that would make total sense, you could open a PR if you have the time :)