Fork me on GitHub
#clj-kondo
<
2023-03-08
>
Akiz10:03:18

Hi, I have updated Malli to the latest version and clj-kondo now reports “insufficient input” (that map in image for example). This is the schema: [:map {:closed true} [:name string?] [:description string?] [:created-by {:optional true} [:maybe string?]] [:id {:optional true} int?]]

Akiz10:03:50

This is kondo’s config

borkdude10:03:49

Can you make a clj-kondo only repro that I can clone locally so I don’t have to copy or type code from screenshots? Then I’ll have a look later today

👍 2
Akiz11:03:43

I don’t get this error in a new project, so I won’t even upload it. The definition in malli-types-clj/config.edn is same for both projects. I tried to delete clj-kondo .cache and also .lsp from the original project, no luck. Unfortunately I can’t share the original project and it is really complex, so there are a lot of variables. Do you have any idea where I could look?

borkdude12:03:54

If you can't make a repro, I can't help you fix it, unfortunately, but maybe you can downgrade malli and ask in #CLDK6MFMK - seems like a downstream problem

👍 2
Akiz12:03:51

Interesting, the downgrade didn’t help. So I thought to delete .clj-kondo/metosin and it worked (with old and new version as well).

Noah Bogart15:03:47

Hook question: I have a macro that acts like def but takes a namespaced symbol and strips the namespace from it and then uses def to make a var: (defrule style/some-var ...) macroexpands to (simplified): (def some-var ...). i wrote a simple hook for this, and for some reason, clj-kondo/clojure-lsp seem to treat the whole block now as a single unit instead of parsing/analyzing each sub expression:

(ns hooks.noahtheduke.splint.rules
  (:require
    [clj-kondo.hooks-api :as api]))

(defn defrule-hook
  [{:keys [node]}]
  (let [[rule-name & body] (next (:children node))
        node (api/list-node (list* (api/token-node 'def)
                                   (api/token-node (symbol (name (api/sexpr rule-name))))
                                   body))]
    {:node node}))

2
Noah Bogart15:03:10

that's a demonstration of "show docs" called on ->violation displaying the docs for this whole top-level form

Noah Bogart15:03:32

is there a better way to do this?

Noah Bogart15:03:39

if I switch the hook to (api/token-node 'defrule) instead of 'def , then go to definition and show docs work but the whole form has an "unresolved symbol: sorted-rules-require" error

borkdude15:03:53

Why write such a macro in the first place? Maybe ^:dev name could also work?

😂 2
borkdude15:03:49

regardless of that, let's take a look at your hook code

Noah Bogart15:03:15

🤷 it's the api i've decided on, it's shortest and simplest and communicates the intentions

borkdude15:03:28

This is wrong:

(list* (api/token-node 'def)
                                   (api/token-node (symbol (name (api/sexpr rule-name))))

borkdude15:03:38

list* expects the last thing to be a collection of nodes

Noah Bogart15:03:03

I have "body" at the end, doesn't that expand properly?

borkdude15:03:23

I recommend using (println node) before you return it, and then execute this on the command line

borkdude15:03:32

then you will see what I mean probably

borkdude15:03:51

oh yes, body, I missed that

borkdude15:03:32

I think you can fix stuff by preserving more original locations via the metadata

👍 2
borkdude15:03:41

with with-meta or vary-meta

Noah Bogart15:03:02

(defn defrule-hook
  [{:keys [node]}]
  (let [[defrule rule-name & body] (:children node)
        new-node (api/list-node
                   (list* (with-meta (api/token-node 'def) (meta defrule))
                          (with-meta (api/token-node (symbol (name (api/sexpr rule-name))))
                                     (meta rule-name))
                          body))]
    {:node (with-meta new-node (meta node))}))

Noah Bogart15:03:05

there we go, that works

👍 2
Noah Bogart15:03:31

thank you for the help

Patrick Brown21:03:42

I’ve got a clj-kondo/clojure-lsp issue with emacs. It stopped working. I did something, what I do not know. All components work in isolation, just not together. Deleting and reinstalling did not help. How do I go about troubleshooting this? I’m a little lost in where to start digging. Any advice is appreciated.

borkdude21:03:57

Is it possible to create a repro repository?

borkdude21:03:21

Are you running clojure-lsp or do you also run clj-kondo separately somehow?

Patrick Brown21:03:47

I could make a repro repo, but I think the issue is much deeper. I’ve gone into the repro repo I sent you when I had issues with defn-spec. It doesn’t work. I’ve messed something up at the global/emacs config level or something else deeper in the well than the project. That’s why I’m a little lost as to how I should continue

borkdude21:03:53

the first thing I usually recommend people to try it clj-kondo on the command line

borkdude21:03:02

are you able to run this:

clj-kondo --lint src

borkdude21:03:29

and maybe clojure-lsp as a command line tool:

clojure-lsp diagnostics

Patrick Brown21:03:43

It gives me an output similar to linting filled with how not perfect my code is

borkdude21:03:26

in your emacs config folder, can you maybe do this: mv elpa elpa.bak

borkdude21:03:30

and then restart your emacs

Patrick Brown21:03:30

I’m assuming that’s the same as moving my straight repos folder.?

borkdude21:03:52

I guess so. This reminds me. #CPABC1H61 has a minimal emacs config to debug things

borkdude21:03:00

you could try that one. @UKFSJSM38 knows where it is probably

ericdallo21:03:36

Yes, and if it's a problem with not even starting clojure-lsp check this https://emacs-lsp.github.io/lsp-mode/page/troubleshooting/

Patrick Brown21:03:23

Lsp starts, the server info gives me a clojure-lsp version of 2.27, and lsp of 2.17, the classpath settings is nil.

Patrick Brown21:03:38

scratch that, clj-kondo of 2.17

ericdallo22:03:13

I think both versions are wrong, they should be dates

Patrick Brown22:03:30

Yes, I was referring to the dates, feb 17th and 27th

👍 2
Patrick Brown22:03:56

I can’t copy the server info, because I’m not sure how to open it in a proper buffer.

borkdude22:03:14

go to *Messages*

ericdallo22:03:24

You can just click the mini buffer or do what borkdude said

Patrick Brown22:03:53

Duh, not a proud moment

:client-settings
 {:dependency-scheme "jar",
  :show-docs-arity-on-same-line? true,
  :text-document-sync-kind nil,
  :source-paths nil,
  :source-aliases nil,
  :cljfmt-config-path ".cljfmt.edn",
  :document-formatting? true,
  :document-range-formatting? true},
 :project-root-uri "file:///home/pat/m",
 :port "NREPL only available on :debug profile (`bb debug-cli`)",
 :project-settings {},
 :server-version "2023.02.27-13.12.12",
 :clj-kondo-version "2023.02.17",
 :log-path "/tmp/clojure-lsp.3157811663365747466.out",
 :classpath-settings nil}
 :client-settings
 {:dependency-scheme "jar",
  :show-docs-arity-on-same-line? true,
  :text-document-sync-kind nil,
  :source-paths nil,
  :source-aliases nil,
  :cljfmt-config-path ".cljfmt.edn",
  :document-formatting? true,
  :document-range-formatting? true},
 :project-root-uri "file:///home/pat/m",
 :port "NREPL only available on :debug profile (`bb debug-cli`)",
 :project-settings {},
 :server-version "2023.02.27-13.12.12",
 :clj-kondo-version "2023.02.17",
 :log-path "/tmp/clojure-lsp.3157811663365747466.out",
 :classpath-settings nil}

ericdallo22:03:59

Everything looks good, check if project-root-uri really matches your project root

Patrick Brown22:03:23

It does. I’m doing a proper full on reinstall of my emacs deps as borkdude outlined. It feels like I must have messed something up with my emacs config, but for the life of my I don’t remember touching it.

borkdude22:03:07

@U036UJBDM5G I don't want to sound patronizing, but do you save your emacs config in version control? I even save my entire elpa directory in version control since 2013 haha

Patrick Brown22:03:34

I have all my configs, but I git ignore my autodownloaded deps.

borkdude22:03:43

I've had too many weird issues before that and decided to do it the blunt way

Patrick Brown22:03:05

If that turns out to be my problem, I may jump on that ship.

borkdude22:03:30

I'm not using straight.el etc, it may have better version management

Patrick Brown22:03:06

It supposed to immutable like nix, but all I know is I just add :straight t to my use-package and it works.

👍 2
borkdude22:03:50

I've had issues with .elc files before, when I removed those, emacs re-compiled the .el files and suddenly a problem was fixed

Patrick Brown22:03:42

The same has happened with straight many times. This time I deleted andything with clojure in the name and it didn’t help, but it costs nothing to go further.

borkdude22:03:24

@UKFSJSM38 what was the minimal emacs project to install clojure-lsp / lsp-mode again? it helped me find the weird delay problem at the time

borkdude22:03:53

ah yes, @U036UJBDM5G you could try that file instead of init.el and see if you can get things working

Patrick Brown22:03:05

Well, no dice on the rebuilding emacs with fresh packages, and no dice on the minimal config.

borkdude22:03:16

is clojure-lsp on your path, can emacs find it?

borkdude22:03:34

else lsp-mode will download it anyway right

Patrick Brown22:03:50

I appreciate you both for coming out. HMU if you think of anything. I’m a frustrated dog, so maybe my dog and I should go outside for a walk with the beautiful weather we’re having. When I come back, I’m installing clojure-lsp and clj-kondo from source again, and launching with a custom command. That worked in the past. clojure lsp is there it just doesn’t seem to link with emacs, emacs knows it’s there, it knows my classpath. The problem lies somewhere in the middle.

👍 4
ericdallo22:03:07

A simple project usually helps a lot debug such issues, I recommend testing with my http://github.com/ericdallo/clojure-sample project

Patrick Brown23:03:00

@U04V15CAJ @UKFSJSM38 Thanks for all the help. After no luck with building from source. I went nuclear rm -rfed the f out of everything I could find, then I reinstalled things just like the readme brought my custom config back in piece by piece. I wish I had something smart to say… I’m just happy I can use my tooling again. Side note, I’ve grown way to reliant on tooling to be comfortable. Keep up the good work. I appreciate the quality things you make.

2
ericdallo23:03:03

Thanks! Glad it works now :)