Fork me on GitHub
#lsp
<
2022-10-25
>
jacob.maine01:10:29

Is there a recommended way to share .cljfmt.edn between Calva and clojure-lsp?

jacob.maine02:10:25

Specifically, I'm asking about :indents that use regular expressions, like :indents {#"^for-" [[:inner 0]]}. That format works for Calva because it uses tools.reader/read-string, which sees #"..." as a regular expression. But clojure-lsp reads with clojure.edn/read-string, which doesn't understand regular expressions. To get around this, clojure-lsp expects you to use a reader function: :indents {#re "^for-" [[:inner 0]]}. Unfortunately, tools.reader/read-string complains about that. So, depending on which format I choose, my .cljfmt.edn file works in Calva or with clojure-lsp, but not both.

jacob.maine02:10:48

To partially answer my own question, it appears that cljfmt is https://github.com/weavejester/cljfmt/pull/274 being able to read .cljfmt.edn itself. I've https://github.com/weavejester/cljfmt/pull/274#issuecomment-1289896356 that it also try .cljfmt.clj. If that change is incorporated, it looks like it will support the #"..." style in the .clj file. I've also requested that it support #re "..." in the .edn file. @U0ETXRFEW and @UKFSJSM38 I think it'd be nice if both Calva and clojure-lsp use cljfmt's own tools for reading those files, whenever they're ready. Do you think we could move in that direction? The one blocker will be that Calva currently parses .edn files as if they were .clj files—that is, it uses tools.reader/read-string. That means it currently happily consumes #"..." in an .edn file, though with the new toolset, it would start throwing errors. Perhaps when the cljfmt PR is finished, we can think about a migration path?

pez05:10:57

Interesting. I actually didn't know that regular expressions were not part of EDN. That explains a lot! 😃

😅 1
pez06:10:03

The recommended way to share cljfmt configs between Calva and clojure-lsp is to tell Calva to use clojure-lsp for reading the config https://calva.io/formatting/#configuration. But testing it now, I see that it still croaks on the `#re" reader tag.

ericdallo12:10:01

That'd be great @U07M2C8TT, both using the same upstream function

Thierry12:10:56

Clojure-lsp in my VSCode with Calva is very much in love with my memory.. Any way to feed it something else? 🙂

Thierry12:10:48

restarting the lsp in vscode helps, but is only a bandage

borkdude12:10:59

May be a memory leak

borkdude12:10:21

Can you share anything of your project, deps.edn, .clj-kondo/config, etc

borkdude12:10:27

and clojure-lsp version

Thierry12:10:12

sure, if in private is okay?'

borkdude12:10:53

We could make a private chat with @UKFSJSM38 @U07M2C8TT and @U0BUV7XSA

Thierry12:10:05

sure, it wasnt always like this. i feel its since a cpl of weeks. i'm in the middle of upgrading dependencies and moving to java 11 from java 8

borkdude12:10:11

I've seen a memory leak with clj-kondo once, which I could repro by linting the same file in a loop 100000x times but this could be anywhere of course.

Thierry12:10:14

so it could be anything

borkdude12:10:52

the memory leak was introduced by memoize which holds on to objects in memory forever. could be similar problem in lsp, but remains to be seen of course

borkdude12:10:24

could also be because of the lsp4clj change, but now I'm just guessing. It's best to share your setup / config etc with the people I just mentioned.

borkdude12:10:49

the smallest repro you can make is the best one

Thierry12:10:23

ill have to do this when my deadline is passed, too much on my plate atm --;

Thierry13:10:50

30 minutes later, back up to 3gb lol

Thierry14:10:13

lets create this private chat, this is getting out of hand

ericdallo14:10:31

A valid info: clojure-lsp usually to take more memory/cpu during startup, especially without cache (.lsp/.cache), but then it should not increase during the time, since it uses really low cpu and memory after that

Martynas Maciulevičius14:10:40

Is there a way to not run specific linters on some buffer types? I use NVIM with Conjure and when it prints the loaded namespaces into its log buffer it always highlights the namespaces as unused like this:

Martynas Maciulevičius14:10:20

Or maybe not run linter on a buffer type completely? But I would like the customization better. If we'd want to omit the buffer from linting then this question may be better suited for #vim

borkdude14:10:09

You can configure :config-in-ns with :filename-pattern

☝️ 1
borkdude14:10:33

Let me know if that worked ;)

borkdude14:10:45

@UKFSJSM38 It seems the docs weren't updated for that :filename-pattern

borkdude14:10:59

Do you have an example from your work?

ericdallo14:10:17

maybe

{:ns-groups [{:filename-pattern ".*integration.*" :name integration}]
              :config-in-ns {integration {:linters {:unused-private-var {:level :off}}}

Martynas Maciulevičius15:10:08

This is not a proper namespace, it doesn't have a declaration. I'll try the filename pattern.

borkdude15:10:33

you can just make up a fake name

nate15:10:40

I use ALE for linting with kondo in vim, and have this in my vimrc:

let g:ale_pattern_options = {'conjure-log.*.cljc': {'ale_enabled': 0}}

Martynas Maciulevičius16:10:04

I tried this file:

{:ns-groups [{:filename-pattern "conjure-log-.*\.cljc" :name conjure-log}]
 :config-in-ns {conjure-log {:linters {:unresolved-symbol {:level :off}}}
I added it to my .clj-kondo/config.edn in the project directory and into ~/.config/clojure-lsp/config.edn. I think it didn't work. Did I do something wrong? I also tried .* for the regex

borkdude16:10:01

clj-kondo version?

Martynas Maciulevičius16:10:19

> clj-kondo --version
clj-kondo v2022.10.14

borkdude16:10:41

you don't need to add it to clojure-lsp's config, that doesn't work

borkdude16:10:08

to what configuration directory did you add the config exactly

borkdude16:10:29

can you give the full path? after you mentioned the lsp config I have doubts if you intended to add the config to kondo's home config, which is not ~/.clj-kondo but ~/.config/clj-kondo

Martynas Maciulevičius16:10:26

I used this to find clojure-lsp config: https://github.com/clojure-lsp/clojure-lsp/blob/01500c34e00efa2b4affc627bdc80e89af18f55d/lib/src/clojure_lsp/config.clj#L32 It points into ~/.config/clojure-lsp/config.edn so I created that file and added the config map there. Also my XDG_CONFIG_HOME variable is not set.

Martynas Maciulevičius16:10:28

And for clj-kondo I used the project itself. I'll try the ~/.config/clj-kondo. I tried ~/.config/clj-kondo/config.edn (notice the tilda at the front) and it also doesn't silence the linter. Maybe my rules are bad, I don't know anymore.

ericdallo10:10:35

Your config paths look correct

Martynas Maciulevičius10:11:38

If I add a file in ~/.config/clj-kondo/config.edn then with this config I can silence the linter globally:

{:linters {:unresolved-symbol {:level :off}
           :unresolved-namespace {:level :off}}}
But this config doesn't pick up the file conjure-log-1151426.cljc (it has random integer in the name):
{:ns-groups [{:filename-pattern ".*conjure.*" :name conjure-log}]
 :config-in-ns {conjure-log {:linters {:unresolved-symbol {:level :off}
                                       :unresolved-namespace {:level :off}
                                       }}}}
Is there something that I'm doing wrong? What I expect is to silence these linters in that specific file pattern.

borkdude10:11:46

It's best to debug this from the command line and perhaps with a local checkout of clj-kondo with some debugging statements inserted

Martynas Maciulevičius10:11:32

First thing I found is that I can't put \. into the regex pattern. But it's not enough. I have this input file (don't mind the error texts here, it's system-out buffer):

; Sponsored by @___________ ❤
; --------------------------------------------------------------------------------
; localhost:34189 (connected): .nrepl-port
; --------------------------------------------------------------------------------
; Assumed session: Bullmastiff (Clojure)
; --------------------------------------------------------------------------------
; eval (buf): /home/martin/_____________________________________________.clj
nil
; (err) Syntax error compiling at (src/_______________.clj:25:1).
; (err) Unable to resolve symbol: a in this context
#'my.ns/hi
nil
#'my.ns/api-config
#'my.ns/start
nil
#'my.ns/-main

hi
Then I have this config:
{:ns-groups [{:filename-pattern "clj_file" :name conjure-log}]
 :config-in-ns {conjure-log {:linters {:unresolved-symbol {:level :off}
                                       :unresolved-namespace {:level :off}}}}}
Command:
cat clj_file | clj-kondo --filename clj_file --lint -
This is the output:
cat clj_file | clj-kondo --filename clj_file --lint -
clj_file:11:3: warning: Unresolved namespace my.ns. Are you missing a require?
clj_file:18:1: error: Unresolved symbol: hi
linting took 11ms, errors: 1, warnings: 1
Version: clj-kondo v2022.11.02 Is it correct?

borkdude10:11:01

You have to escape the backslash

Martynas Maciulevičius11:11:24

How can I evaluate it from command line without compiling?

borkdude11:11:53

clojure -M:clj-kondo/dev ...

borkdude11:11:19

I have this in my ~/.clojure/deps.edn:

:clj-kondo/dev {:paths []
                           :deps {clj-kondo/clj-kondo {:local/root "/Users/borkdude/dev/clj-kondo"}}
                           :main-opts ["-m" "clj-kondo.main"]}

Martynas Maciulevičius11:11:11

I tried to run it using lein repl but it hangs the REPL if I try to run the main function 😕 (not the -main which does system exit)

Martynas Maciulevičius11:11:48

> I have this in my ~/.clojure/deps.edn: Is it in the top-level?

borkdude11:11:22

can you specify how you exactly called the main function? it should not hang

borkdude11:11:48

yes, but it does not matter if an alias is global or local

Martynas Maciulevičius11:11:32

I tried this expression that I found in the bottom and I deleted one --lint clause to point to only my file:

;;;; Scratch

(comment

  (into #{}
        (comp
         (map :filename)
         (distinct))
        (:findings (read-string (with-out-str
                                  (main "--lint" "/home/martin/ttttttttttttttttttttttttt/clj_file"
                                        "--config" "{:output {:format :edn}}"
                                        "--config" "{:linters {:invalid-arity {:level :warning}}}"))))))
I used lein repl to connect to REPL and I have nREPL middleware too

borkdude11:11:03

it's better to use clj-kondo.core here

borkdude11:11:15

(clj-kondo.core/run! {:lint ["your-file.clj"] :config '{:linters {...})

Martynas Maciulevičius11:11:18

I added a print statement in config.clj , in function

(println {:str-filename (string? filename-pattern)
          :sym-name (symbol? name)
          :pattern-matches (and filename-pattern
                                (re-matches (re-pattern filename-pattern) filename))
          :filename-pattern filename-pattern
          :filename filename
          :matches (or (and (string? pattern) (symbol? name)
                            (re-matches (re-pattern pattern) (str ns-name)))
                       (and (string? filename-pattern) (symbol? name)
                            (re-matches (re-pattern filename-pattern) filename)))})
Outputs (first when file matches, second when it doesn't match):
$ cat clj_file | clojure -M:clj-kondo/dev --filename heeey --lint -
{:str-filename true, :sym-name true, :pattern-matches heeey, :filename-pattern heeey, :filename heeey, :matches heeey}
heeey:11:3: warning: Unresolved namespace my.ns. Are you missing a require?
heeey:18:1: error: Unresolved symbol: hi
linting took 70ms, errors: 1, warnings: 1

$ cat clj_file | clojure -M:clj-kondo/dev --filename heeeyAAAAA --lint -
{:str-filename true, :sym-name true, :pattern-matches nil, :filename-pattern heeey, :filename heeeyAAAAA, :matches nil}
{:str-filename false, :sym-name true, :pattern-matches nil, :filename-pattern nil, :filename heeeyAAAAA, :matches false}
heeeyAAAAA:11:3: warning: Unresolved namespace my.ns. Are you missing a require?
heeeyAAAAA:18:1: error: Unresolved symbol: hi
linting took 67ms, errors: 1, warnings: 1
It matched the linter's config but the output didn't change 🤷 Config:
{:ns-groups [{:filename-pattern "heeey" :name conjure-log}]
 :config-in-ns {conjure-log {:linters {:unresolved-symbol {:level :off}
                                       :unresolved-namespace {:level :off}}}}}

borkdude11:11:11

OK, I think the relevant bit might be in linters.clj where the unresolved symbols are processed. It might not take the ns-group into account

borkdude11:11:17

Feel free to post an issue with a repro

Martynas Maciulevičius10:11:38

If I add a file in ~/.config/clj-kondo/config.edn then with this config I can silence the linter globally:

{:linters {:unresolved-symbol {:level :off}
           :unresolved-namespace {:level :off}}}
But this config doesn't pick up the file conjure-log-1151426.cljc (it has random integer in the name):
{:ns-groups [{:filename-pattern ".*conjure.*" :name conjure-log}]
 :config-in-ns {conjure-log {:linters {:unresolved-symbol {:level :off}
                                       :unresolved-namespace {:level :off}
                                       }}}}
Is there something that I'm doing wrong? What I expect is to silence these linters in that specific file pattern.