Fork me on GitHub
#clj-kondo
<
2021-08-23
>
Noah Bogart15:08:46

this is foolish of me but i’ve forgotten and can’t seem to make it work: how do i disable the :refer :all lint for clojure.test and then stop marking deftest and is as unresolved symbols?

Noah Bogart15:08:07

if it matters, i’m using the #lsp clj-kondo integration instead of relying on clj-kondo directly

Noah Bogart15:08:05

clj-kondo --lint "$(clojure -Spath)" --dependencies --parallel --copy-configs doesn’t make them go away

borkdude15:08:24

@nbtheduke This should work:

(ns foo
  {:clj-kondo/config '{:linters {:refer-all {:exclude [clojure.test]}}}}
  (:require [clojure.test :refer :all]))

(deftest foobar
  (is (= 1 2)))

borkdude15:08:38

There should be no unresolved symbols at all, it works out of the box

borkdude15:08:59

At least with clj-kondo + flycheck, no idea about lsp

Noah Bogart15:08:07

i’m not sure what I’m doing wrong, then, thanks

borkdude15:08:30

Are you using any other namespaces with :refer :all?

Noah Bogart15:08:42

i’ll keep poking at it

borkdude15:08:50

yeah, that should "just work"

borkdude15:08:29

Can you post this code? I'll try it locally

Noah Bogart15:08:17

this is a completely fresh, untouched library template from #deps-new, created with clojure -Tnew lib :name io.github.noahtheduke/datalog

Noah Bogart15:08:01

i can open a new github repo with this but i’ve not actually written any code yet lol

borkdude15:08:14

can you tell me how to install that tool

Noah Bogart15:08:48

clojure -Ttools install com.github.seancorfield/deps-new '{:git/tag "v0.1.0" :git/sha "089d868"}' :as new

borkdude15:08:49

@nbtheduke From a clean slate:

borkdude@MBP2019 /tmp/datalog $ clj-kondo --lint "$(clojure -Spath)"  --dependencies --parallel --copy-configs
borkdude@MBP2019 /tmp/datalog $ clj-kondo --lint test
test/noahtheduke/datalog_test.clj:2:34: warning: use alias or :refer [deftest is testing]
test/noahtheduke/datalog_test.clj:3:41: warning: use alias or :refer

borkdude15:08:04

Going to try lsp now

borkdude15:08:15

Looks normal to me:

borkdude15:08:27

(well, I'm using the linting from clj-kondo itself, not lsp)

Noah Bogart15:08:45

Hmmmmm I don’t know what I broke but I must have broken something. Thanks for verifying.

borkdude15:08:24

Perhaps @ericdallo knows more

borkdude15:08:24

ah yes, I can reproduce when I'm using the lsp linting instead of directly clj-kondo

👍 2
ericdallo15:08:12

Some users already complained about this, and I never manage to reproduce successfully, not sure if it's something with clj-kondo cache or a source-path wrongly configured 😕

ericdallo15:08:17

is there a simple repro?

borkdude15:08:19

it started working for me when I: 1) created a .lsp folder in the root of the project 2) removed the /tmp/ folder from the workspace (apparently it added that instead of the proper root) 3) deleted .clj-kondo/.cache 4) restarted the workspace 5) imported it from the proper root

ericdallo15:08:08

1. clojure-lsp always create a .lsp folder after a success analyze, no need to create it

borkdude15:08:27

well, there wasn't one here

borkdude15:08:45

maybe because there was one in a higher dir?

ericdallo15:08:50

so the project was not analyzed properly by clojure-lsp, the logs or the log to client should say that

ericdallo15:08:03

it depends on what was the project root

ericdallo15:08:12

sent by lsp-mode (configured by user)

borkdude15:08:22

yes, anyway fixing that fixed the problem for me

ericdallo15:08:37

could you confirm your project root is configured properly @nbtheduke?

ericdallo15:08:25

if clojure-lsp doesn't scan the project properly, it will both log to clojure-lsp log and send a message to client which will print something like Classpath lookup failed....

Noah Bogart16:08:11

"workspaceFolders": [
        {
            "uri": "file:///Users/noah/Personal/datalog/test/noahtheduke",
            "name": "/Users/noah/Personal/datalog/test"
        },
        {
            "uri": "file:///Users/noah/Personal/datalog/src/noahtheduke",
            "name": "/Users/noah/Personal/datalog/src"
        },
        {
            "uri": "file:///Users/noah/Personal/datalog",
            "name": "/Users/noah/Personal"
        },
        {
            "uri": "file:///Users/noah/.vim",
            "name": "/Users/noah"
        }
    ],

Noah Bogart16:08:56

that’s what vim sent to clojure-lsp

Noah Bogart16:08:24

hmm, lsp log:

2021-08-23T16:03:49.865Z UnknownHost INFO [clojure-lsp.source-paths:134] - Automatically resolved source-paths from deps.edn: #{"src" "resources" "test"}
2021-08-23T16:03:50.339Z UnknownHost INFO [clojure-lsp.crawler:133] - Analyzing source paths for project root /Users/noah/Personal/datalog
2021-08-23T16:03:50.346Z UnknownHost INFO [clojure-lsp.crawler:77] - Paths analyzed, took 0.006113346 secs. Caching for next startups...
2021-08-23T16:03:50.346Z UnknownHost DEBUG [clojure-lsp.server:?] - :initialize 500ms
2021-08-23T16:03:50.347Z UnknownHost INFO [clojure-lsp.kondo:64] - Linting whole project files took 1ms
2021-08-23T16:03:50.356Z UnknownHost INFO [clojure-lsp.server:350] - Initialized!
2021-08-23T16:03:50.356Z UnknownHost DEBUG [clojure-lsp.server:?] - :initialized 0ms
2021-08-23T16:03:50.361Z UnknownHost DEBUG [clojure-lsp.server:?] - :didOpen 4ms
2021-08-23T16:03:52.362Z UnknownHost DEBUG [clojure-lsp.server:?] - :semanticTokensFull 1ms
2021-08-23T16:03:55.146Z UnknownHost ERROR [clojure-lsp.server:?] -
com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine      PosixJavaThreads.java:  192
            com.oracle.svm.core.thread.JavaThreads.threadStartRoutine           JavaThreads.java:  553
                        java.util.concurrent.ForkJoinWorkerThread.run  ForkJoinWorkerThread.java:  183
                          java.util.concurrent.ForkJoinPool.runWorker          ForkJoinPool.java: 1594
                               java.util.concurrent.ForkJoinPool.scan          ForkJoinPool.java: 1656
             java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec          ForkJoinPool.java: 1020
                             java.util.concurrent.ForkJoinTask.doExec          ForkJoinTask.java:  290
              java.util.concurrent.CompletableFuture$AsyncSupply.exec     CompletableFuture.java: 1692
               java.util.concurrent.CompletableFuture$AsyncSupply.run     CompletableFuture.java: 1700
                  clojure-lsp.server.LSPTextDocumentService/reify/get                 server.clj:  139
                                       clojure-lsp.handlers/did-close               handlers.clj:   69
                        clojure-lsp.feature.file-management/did-close        file_management.clj:  180
                                     clojure-lsp.shared/uri->filename                 shared.clj:  123
                                          clojure.string/starts-with?                 string.clj:  364
java.lang.NullPointerException:

2021-08-23T16:03:55.148Z UnknownHost DEBUG [clojure-lsp.server:?] - :didClose 1ms
2021-08-23T16:03:55.216Z UnknownHost DEBUG [clojure-lsp.server:?] - :didOpen 2ms
2021-08-23T16:03:57.220Z UnknownHost DEBUG [clojure-lsp.server:?] - :semanticTokensFull 0ms

ericdallo16:08:06

sounds like a bug on recent introduced didClose

ericdallo16:08:17

even so, not related with your issue

👍 2
Noah Bogart16:08:24

is there another way to determine the project root for lsp?

ericdallo16:08:47

yes, the serverInfo command should return a project-root-uri

ericdallo16:08:49

Calva and emacs already have handful commands to get that using that custom method

Noah Bogart16:08:52

:project-root-uri "file:///Users/noah/Personal/datalog"

ericdallo16:08:02

is that the correct project root ?

Noah Bogart16:08:22

that’s where the deps.edn is, yeah.

ericdallo16:08:39

could you try removing both .lsp/sqlite.db and .clj-kondo/.cache?

ericdallo16:08:22

it'd be even better if you try one after the other

ericdallo16:08:30

try first clj-kodno/.cache

Noah Bogart16:08:57

oops, did both and it seems to have resolved itself

ericdallo16:08:31

np, is it working properly now?

ericdallo16:08:59

what I think it's the issue:

ericdallo16:08:33

clojure-lsp call clj-kondo 3 (independent from errors) times: 1. during init, after get the project classpath, to get external analysis (jars), calling clj-kondo passing the whole classpath (excluding project source-paths) 2. during init, after 1., to analyze only project source-paths 3. after any file change, running for a single file, but not important for this isue What I suspect is that, 1. doesn't run properly, but 2. runs fine, persisting a .clj-kondo/cache with only cache for project, not containing external deps

borkdude16:08:53

well, if you have only 2, then the above issue shouldn't have happened, since clj-kondo already has a built-in cache for clojure.test

borkdude16:08:30

but if 1 lints clojure.test not correctly then there will be some invalid cache analysis fo clojure.test, which is more likely to cause the issue

ericdallo16:08:20

yeah, I think it's related with old cache or something like that if you manage to repro again, let us know @nbtheduke

☝️ 2
borkdude16:08:12

it would have been interesting indeed to inspect the contents of .clj-kondo/.cache after this happened

☝️ 2
Noah Bogart17:08:14

I’ll keep an eye out and if I see it again, I’ll post it!

ericdallo17:08:15

Thanks, it's something that happens from time to time, the first report I saw of this was on Calva back on Feb/2020! So it'd be really nice if we manage to fix it somehow