Fork me on GitHub
#lsp
<
2022-08-03
>
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?

ericdallo11:08:30

Could you share a test example?

Dmytro Bunin11:08:02

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

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

ericdallo11:08:03

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

ericdallo11:08:46

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

ericdallo11:08:57

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.

ericdallo12:08:47

yep, you are right

ericdallo12:08:45

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 😄

ericdallo12:08:05

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

ericdallo12:08:24

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

ericdallo12:08:27

yeah, that's a blocker ATM

ericdallo12:08:20

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

djm12:08:31

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.

ericdallo12:08:01

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

ericdallo12:08:02

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))

ericdallo12:08:22

could you try lsp-find-references instead?

djm12:08:10

lsp-find-references behaves in the same way

ericdallo12:08:56

what's your clojure-lsp version?

djm12:08:18

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

ericdallo12:08:37

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

djm12:08:15

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

djm12:08:59

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

ericdallo12:08:56

Oh, I was not aware of that :)

ericdallo12:08:15

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

djm12:08:44

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

ericdallo12:08:22

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

djm12:08:37

:thumbsup: