Fork me on GitHub
#lsp
<
2022-04-08
>
skuro07:04:42

is there any way to access / navigate the sideline code actions without using the mouse?

skuro07:04:27

I'm looking around the lsp-ui docs but cannot find anything on the subject

skuro07:04:59

oh, maybe lsp-execute-code-action 🙂

skuro07:04:08

not exactly what I expected but works

mpenet08:04:41

lsp-execute-code-action + something like vertico/consult makes it quite nice

ericdallo12:04:36

yep, I abandoned lsp-ui at all, the modeline from lsp-mode is quite enough and lsp-execute-code-action shows the actions quickly, you can filter with vertico/consult easily

andrewzhurov10:04:38

how far does clojure-lsp goes into derivation of semantics of a Clojure program?

andrewzhurov10:04:09

i.e., what semantics does it derive?

andrewzhurov10:04:19

I'm asking because I'm trying to get semantic representation of a Clojure program (deps included). I.e., read(program-folder) => program-as-data

ericdallo12:04:40

@U0ZQT0K2N not sure you are aware, but I want to implement a tool for that soon on clojure-lsp, check this https://github.com/clojure-lsp/clojure-lsp/issues/744 I think it's related to what you want?

❤️ 1
ericdallo12:04:02

but basically clojure-lsp relies entirely on clj-kondo analysis, so everything there should be available from clojure-lsp

andrewzhurov13:04:48

that tool would be handy for communicating knowledge

ericdallo13:04:44

yeah, I can see lots of new things growing from that

andrewzhurov13:04:53

I am wondering what knowledge clojure-lsp has to offer. it relies and builds on top clj-kondo, as you mention. that 'on top' includes integration with LSP, but perhaps clojure-lsp derives some more knowledge as well?

andrewzhurov13:04:03

other source of knowledge for clojure-lsp seems to be rewrite-clj, as clojure-lsp is being mentioned on rewrite-clj's page as adopters. but I'm not sure I've seen so far any knowledge from rewrite-clj being used in clojure-lsp, is there?

ericdallo13:04:33

we use rewrite-clj a lot by all code refactors

ericdallo13:04:50

but for this feature specifically we don't need rewrite-clj at all

andrewzhurov13:04:26

ah, so it's being used to manage the source of clojure-lsp, but is not used by it internally, right?

ericdallo13:04:08

clojure-lsp uses rewrite-clj for the refactors feature

ericdallo13:04:19

so when one call move to let on clojure-lsp, we use rewrite-clj

ericdallo13:04:34

there are few places we use it too, but not relevant for this dump feature

andrewzhurov13:04:47

ah, I see. thank you for explaining.

andrewzhurov13:04:48

btw, what's the difference between stuff under features and feature?

andrewzhurov13:04:22

I went through features , feature stuff is on the list

ericdallo13:04:55

it should be the same 😅

ericdallo13:04:08

probably some misrename, we should use singular or plural

ericdallo13:04:44

AFAICS, features are on test and feature are on src

ericdallo13:04:51

so just rename one of those folders

andrewzhurov13:04:32

ah, ok. yeah, that happens sometimes, names are tricky.:)

😅 1
Teemu Kaukoranta14:04:05

Hello! Should there be any difference in performance, comparing clojure-lsp format to cljfmt ? I'm assuming they should be about the same.

Teemu Kaukoranta14:04:28

I'm testing it out though, and cljfmt is much faster on my machine. I'm hoping lsp is just checking more files, so it's a configuration issue. Figured it's just easier to ask though 🙂

ericdallo14:04:25

yeah, cljfmt is a little bit faster because it just scan the folders you pass, clojure-lsp finds that automatically via classpath and have a more robust mechanism for format configuration (available on classpath jars too)

ericdallo14:04:49

so if you want to use only format, you can choose cljfmt, but if you want to use more clojure-lsp features like clean-ns and diagnostics

ericdallo14:04:55

probably using format from clojure-lsp is better

ericdallo14:04:24

for example, at nubank we have a common codestyle project with all lint and format configs, so all projects just use that jar and have everything in a standard

ericdallo14:04:34

that's not possible with cljfmt, it just reads a single file from the project

Teemu Kaukoranta14:04:54

Thanks for the quick reply. We already used cljfmt, but we also want to use clean-ns, so I figured it would also be nice to use the format command. The configuration of clojure-lsp is nice. I put a test together really quickly, and the result was that clojure-lsp was 4x slower. I think it was just a poor test 😄

Teemu Kaukoranta14:04:02

Since I have your attention, what is the difference between diagnostics and just calling clj-kondo? clj-kondo was much faster for us, probably because of its --parallel option.

ericdallo14:04:11

diagnostics will bring kondo analysis + clojure-lsp/unused-public-var clojure-lsp usually is slower the first time when it caches the external analysis, the next times it scan project only to know all analysis + namespaces

Teemu Kaukoranta14:04:13

ah, never mind. Found it from the documentation. clojure-lsp has custom linters, which by default include clojure-lsp/unused-public-var

ericdallo14:04:24

we are also improving performance of it each release

ericdallo14:04:07

if you use lein-clojure-lsp, it will analysze one time only, so you can format clean-ns diagnostic

ericdallo14:04:24

checking project analysis once

Teemu Kaukoranta14:04:37

That's nice, but we don't use lein 🙂

ericdallo14:04:51

yeah, I intend to add support for that on deps.edn too

ericdallo14:04:38

we replaced all cljfmt/clj-kondo/nsorg etc at nubank by clojure-lsp because even if it's a little bit slower, it has consistency, config standards for hundreds of projects, and it's a single tool for everything

Teemu Kaukoranta14:04:53

Sorry for barraging you with questions, but is it possible to tell format with paths to format? Would be nice to only format files that have changed (e.g. a pre-commit hook).

ericdallo14:04:19

LMK if you see room for improvement on the API

Teemu Kaukoranta14:04:05

cool, thank you so much for the help 🙂

👍 1
andrewzhurov09:04:45

@UKFSJSM38 I wonder what kind of style config you end up having (mentioned codestyle), should be of a high grade. Is it open-sourced somewhere?

ericdallo14:04:02

nope it's a nubank internal project as it contains macros and functions from other projects, but I can share its core idea: Basically, it's a lein project with no clojure code, witch exports only a resources folder like this: resources/clojure-lsp.exports/nubank/codestyle/config.edn

{:clean {:ns-inner-blocks-indentation :same-line}
 :classpath-config-paths ["nubank/lib-a"
                          "nubank/lib-b"]
 :use-metadata-for-privacy? true
 :auto-add-ns-to-new-files? true
 :cljfmt {:indents {assoc-if                [[:block 1]]
                    assoc-in-if             [[:block 1]]
                    assoc-some              [[:block 1]]
                    assoc-in-some           [[:block 1]]
                    constraint-fn           [[:block 2]]
                    consume!                [[:block 0]]
                    data-fn                 [[:block 1]]
                    defhandler              [[:block 2]]
                    defint                  [[:block 0]]
                    defuf                   [[:block 1]]
                    ,,,}}}
resources/clj-kondo.exports/nubank/codestyle/config.edn
{:skip-comments true
 :config-paths ["../common-a"
                "../state-flow"
                "../common-b"
                "../common-c"
                "../../marick/midje"]
 :hooks        {:analyze-call {foo/a foo/b}}
 :lint-as       {clojure.test.check.clojure-test/defspec clj-kondo.lint-as/def-catch-all
                 clojure.test.check.properties/for-all   clojure.core/let
                 schema.test/deftest                     clojure.test/deftest}
 :linters       {:deprecated-var {:level :info}
                 :refer-all {:exclude [midje.sweet
                                       matcher-combinators.test
                                       clojure.test.check.clojure-test
                                       clojure.test]}
                 :clojure-lsp/unused-public-var {:exclude-regex [".+\\.server/run-dev"
                                                                 ".+\\.server/servlet-init"
                                                                 ".+\\.server/servlet-destroy"
                                                                 ".+\\.server/servlet-service"
                                                                 ".+\\.components/start-sachem-system!"
                                                                 ".+\\.components/ensure-system-up!"]}}}

ericdallo14:04:17

This makes clojure-lsp and clj-kondo find those configs of any project using this jar, having the need of only this config on each project: .clj-kondo/config.edn

{:config-paths ["nubank/codestyle"]}
.lsp/config.edn
{:classpath-config-paths ["nubank/codestyle"]} 

ericdallo14:04:01

BTW, @U04V15CAJ may be interested on knowing we do that, this is shared across hundreds of services :)

🎉 1
andrewzhurov08:04:37

That's cool! Thanks for sharing. ❤️ 🙂

pyr14:04:39

Hi, I am hitting something similar to what @pesterhazy was reporting: I have trouble getting clojure-lsp to work with emacs beyond 2022.01-22-01.31.09. Later releases do not report linting failures at all (so it's more widespread than what @pesterhazy was mentioning, I just don't get any kondo warnings notices)

ericdallo14:04:48

what's your lsp-clojure-server-info reports?

borkdude14:04:22

I also saw this when doing a video with @U02KYBC5WJY in Calva. I advised him to install the clj-kondo extension separately, since we could not figure it out with lsp only. As a workaround you can use flycheck-clj-kondo and disable the linter in clojure-lsp.

ericdallo14:04:53

Keep in mind, flycheck-clj-kondo will offer only clj-kondo features, not refactors, lens and clojure-lsp features

borkdude14:04:11

yes, but you can use them together (like I always do)

ericdallo14:04:47

I don't see why one would like to use kondo separated if not using a edge kondo or something @U04V15CAJ

borkdude14:04:23

@UKFSJSM38 I agree, but as I said, we could not figure it out. There were no .lsp config files anywhere. So we went with a workaround.

ericdallo14:04:44

So probably Calva didn't even start clojure-lsp

ericdallo14:04:58

@pyr check your project root with lsp-workspace-folders-remove and then lsp

pyr14:04:03

so indeed my home dir was picked up

pyr14:04:37

it might be related to the fact that to debug all this I removed all other packages (and thus have no projectile anymore)

borkdude14:04:41

@UKFSJSM38 well, in Daniel's case, navigation worked, so I think lsp was doing something

ericdallo14:04:01

Calva uses nrepl navigation as fallback @U04V15CAJ

borkdude14:04:09

there was no REPL yet in that project

pyr14:04:11

bear in mind this is the working config (I get clj-kondo hints with this older version)

ericdallo14:04:55

I saw this behavior that kondo lint configs were not working on recent versions if you have wrong project-root

ericdallo14:04:13

probably a regression we introduced that just a side effect of a wrong project config

pyr14:04:43

@U04V15CAJ I just moved my .clj-kondo config

👍 1
borkdude14:04:21

.config/clj-kondo/config.edn
note: not, .config/.clj-kondo just making sure :)

pyr14:04:56

@UKFSJSM38 the remove-folders trick worked to set the project root properly, thanks

👍 1
pyr14:04:10

I'll try again with a more recent clojure-lsp to see if I get back the kondo linting

ericdallo14:04:57

yeah, that regression probably make you the need to fix the root, is not ideal, but you would probably have lots of other issues if not fixing the project root, including performance issues

pyr14:04:42

OK, with the root fixed, I get linting through clojure-lsp. Thanks for the help with debugging!

👍 1
ericdallo15:04:28

we could make lsp-mode double confirm when root is /home /home/your-user /Users/your-user

ericdallo15:04:46

sounds like a good feature suggestion

snoe16:04:44

@UKFSJSM38 you mentioned graal doesn't have JAVA_HOME is it all env vars? if not, HOME might be all that's needed to check.

ericdallo16:04:36

yeah, I was thinking about checking HOME indeed as JAVA_HOME is not present and even if it s present points to the Java installation dir, not the user home, right?

snoe16:04:36

oh, sorry, I was wondering if graal has access to any env vars, if it does HOME would be nice

ericdallo16:04:04

yes, it has the same access to env vars normally, what is doesn't have is the jvm properties, like (System/getProperty "java.home")

👍 1
borkdude17:04:14

It does have "user.home" System property

👍 1
pyr14:04:03

Another corollary behavior is that clojure-lsp hangs buffers when they are being opened, which seems to be related to it wanting to consider my home directory as any project's root

borkdude14:04:36

@pyr do you have a .clj-kondo folder in your home folder?

borkdude14:04:55

you shouldn't do that: use .config/clj-kondo/config.edn

ericdallo14:04:04

Please, keep the discussion in the thread if possible

dpsutton15:04:41

Wondering if this is a known issue or not: Working with schema and want to validate a schema in the repl. I type s/val and ask for autocompletions. The first is s/valid? which sounds right and I select it, but that is from spec and brings in spec :as s when I already have schema :as s and only want those completions. Has this behavior been noted before?

ericdallo16:04:58

Probably not, also we changed recently some logic regarding that so it could be a regression too

🙏 1
ericdallo16:04:55

When you have a alias already required, we should not suggest other ns requires for that alias

dpsutton16:04:13

would you appreciate an issue?

snoe16:04:27

I've also noticed in completions, that if I have :as log already required, log/spy completion is still coming in with additional-text-edits

👍 1
snoe16:04:07

So I'm guessing the completion speed changes?

dpsutton16:04:09

yeah i’ve had log from clojure.tools.logging in a ns and using completions (even for log/warn from c.t.logging will bring in some util logging ns we have

ericdallo16:04:26

Found the issue @U11BV7MTK probably a old one, will try to do a quick fix

🙏 1
ericdallo17:04:19

@U11BV7MTK it should be fixed on master, could you try a #clojure-lsp-builds in a couple of minutes?