Fork me on GitHub
#lsp
<
2021-07-14
>
ribelo09:07:29

@ericdallo heh, no problem mate. I had the opportunity to learn how to create/upgrade packages in NixOS, which I've been using for a while now. How awesome is that! What is the situation with PR in NixOS? If I update nixpkgs with the latest version of clojure-lsp can I push it to GH, or will it get lost in the clutter of hundreds of other PRs and you won't even notice it?

ericdallo11:07:56

It was mergers yesterday :)

ericdallo11:07:30

Usually there is no PR conflicts with the same package, but it's a good idea search for the PR before you open it

ericdallo11:07:49

You can install it from unstable channel/master now

nbardiuk12:07:40

I've recently learned about tool to track which channel contains specific PR https://nixpk.gs/pr-tracker.html?pr=130038

Yuner Bekir09:07:44

Hello guys, I am using calva in VS Code and I am trying to get all references of a function, inside our project. The problem is that it seems that not all projects are evaluated, my reasoning behind it is that when I use the shortcut shift + f12 I don't get all of the calls of the function. When I evaluate a different project then I get a list of the function references. The project I am working on is like a pomegranate, its a project with multiple smaller projects inside. ( I haven't worked on any other projects, so I don't know if this is the classical project)

ericdallo11:07:58

I never heard of pomegranate but I suppose it's a kind of monorepo project right? Similar to polylith and lein-monolilth?

ericdallo11:07:37

You should probably import the mono-repo root as the project root, which means open the project root with Calva/VSCode instead of the subprojects

ericdallo11:07:19

Also, if you could do a mini-repro I could test to check if clojure-lsp works nice with that pomegranate

Yuner Bekir14:07:17

The whole project is a collection of subprojects so a mono repo is partly correct. Each subproject is small enough that it doesn't need a separate repo. I attempted to do what you told me. It solved some of my problems, but it seems that some namespaces are not included, which is interesting, but still thanks the non included namespaces are not that important

ericdallo14:07:37

I minimal repro would help a lot understand the project structure and the deps between them, but in general: If a subproject depends on another subproject/you want to go from one to another you probably want to open the project that contain the subprojects as root, but you would need a deps.edn or project.clj with all the subproject deps

ericdallo14:07:05

otherwise, opening each subproject as a single project would work as well, but you would not be able to go from one prject to another using LSP features

dharrigan12:07:21

What sorcery is this!?!?! 😄

❤️ 4
ericdallo12:07:39

It was introduced some months ago actually :)

ericdallo12:07:50

The deprecated tag on diagnostics

dharrigan12:07:16

Yes, just that it's awesome 🙂

ericdallo12:07:31

I like it too 😄

ericdallo12:07:47

there is another tag as well, the unused one

ericdallo12:07:04

it should color the var as dimmed grey (at least on emacs/vscode)

dharrigan12:07:42

Does lsp have the ability to insert a clj-kondo ignore for the line?

dharrigan12:07:16

i.e., something like this #_{:clj-kondo/ignore [:invalid-arity]}?

dharrigan12:07:31

or am I talking cross purposes, one is a clj-kondo thing, another is an lsp thing?

ericdallo12:07:41

no, but we could add a code-action for that indeed

ericdallo12:07:01

prompting for user what linter they want to add

dharrigan12:07:13

for example, in a lot of dev namespaces, there are functions that aren't referenced at all

dharrigan12:07:18

you still want it linted, checked etc.

ericdallo12:07:20

actually, getting from the current diagnostic

dharrigan12:07:39

but you don't care if the function is used or not, but you would like to exclude them on a case-by-case basis

ericdallo12:07:49

yeah, but the unused-public-var is from clojure-lsp not clj-kondo haha

borkdude12:07:03

carve supports that as a config

borkdude12:07:18

but has its own way of unused var

ericdallo12:07:20

clojure-lsp support exclude that as well on config, but not via code comment

dharrigan12:07:45

perhaps supporting/honouring/variant of the same ignore thing that clj-kondo does, but for clojure-lsp would be neato?

dharrigan12:07:00

and instead of it being in a config.edn file, it can be done when editing the code and inserting an ignore

ericdallo12:07:06

yeah, would work, not sure how hard it is

dharrigan12:07:26

it's very similar to how intellij works with java/kotlin in allowing you to ignore certain lines in the file, whilst in the file - no external config.

dharrigan12:07:36

just a thought 🙂

ericdallo12:07:43

yeah, makes sense

borkdude12:07:05

or perhaps the linter could be moved to clj-kondo and you can just use the clj-kondo comment

dharrigan12:07:38

that would work 🙂 then there is only one place where the linting goes on and thus only one way of ignoring things 🙂

ericdallo12:07:01

move that to kondo would be really good for clojure-lsp 😅

borkdude12:07:29

the lsp linter is based on data from clj-kondo anyway. the only problem is that clj-kondo hasn't got an idea of "project", the scanning of the project is done by lsp by invoking clj-kondo, so it behaves like a lower level tool

borkdude12:07:50

and to be able to say "unused var" you have to have seen the entire project

ericdallo12:07:55

it's true, not sure how that would be done on kondo

borkdude12:07:16

perhaps we can move this project scanning stuff to kondo as well, as the first step

ericdallo12:07:21

maybe one more flag to kondo like --project-root 😆

borkdude12:07:50

yeah or it can be configured in .clj-kondo/config.edn

👍 2
borkdude12:07:53

if you lint with --dependencies clj-kondo could be fairly sure it's seen the entire project after that

borkdude12:07:48

it's a bit complicated :)

borkdude12:07:03

alternatively clj-kondo could expose the locations where the ignores are applied to

ericdallo12:07:45

yeah, seems complicated indeed

ericdallo12:07:14

is it hard to add comment maps like the kondo one to clojure-lsp? I suppose it just uses rewrite-clj?

borkdude12:07:37

perhaps some metadata like ^:export to mark vars as always used could also work :thinking_face:

ericdallo12:07:53

hum.. seems good as well

borkdude12:07:14

does lsp still parse the code as well using rewrite-clj?

ericdallo12:07:50

for some features not related with kondo, yes

ericdallo12:07:54

like refactorings

borkdude12:07:21

ok right. we could perhaps agree on a general comment form, like #_:linter/ignore

borkdude12:07:28

which clj-kondo also respects

ericdallo12:07:49

hum, yes, a standard for that would be perfect

borkdude12:07:42

clj-kondo also has a more fine grained one #_{:clj-kondo/ignore [:unused-binding]} but I think most people use the "global" one

borkdude12:07:58

so that would be a good start

borkdude12:07:06

note that these comments apply to the next form, not to lines

dharrigan12:07:39

A good start indeed 🙂 I would like, at some point, in a future iteration to support a vector of unused things, for perhaps there are things I do want to ignore, but not others. A future iteration for sure! 🙂

borkdude12:07:05

the vector indicates the linter rules to ignore, not specific values

ericdallo12:07:06

yes, so user can use the global one to suppress the unused public var, but if there is some unused arity lint, it'll keep returning the diagnostic

borkdude12:07:41

e.g. (let [#_{:clj-kondo/ignore [:unused-binding]} x 1])

borkdude12:07:59

for most people this is too verbose I think so they use only the global one

ericdallo12:07:01

the global one seems a good start, I'll open an issue on clojure-lsp to support the #_:linter/ignore one, does that pattern makes sense for clj-kondo as well @U04V15CAJ?

practicalli-johnny12:07:47

I have a user namespace in dev/user.clj and I've changed the signatures of 2 functions from zero args to 1 arg. lsp / clj-kondo is reporting invalid-arity warnings. My assumption is that some kind of cached version of these functions are being referenced. If so, how do I update lsp / clj-kondo ?

ericdallo12:07:36

ATM if you make a change on the file the new diagnostics would update

ericdallo12:07:59

there is a flag to enable update the diagnostics on the references of a changed function, but it's not enabled by default for performance issues

practicalli-johnny12:07:59

Would this issue be because I dont have dev/ directory in the class path?

ericdallo12:07:22

hum, it could be

ericdallo12:07:33

:notify-references-on-file-change the setting I mentioned, but not sure is that your problem

practicalli-johnny13:07:42

Nope.. adding dev/ directory didn't resolve the issue (but I needed to do that anyway for other things).

practicalli-johnny13:07:09

How do I clean the cache ? Happy to do this destructively 🙂

practicalli-johnny13:07:47

Well rm -rf .lsp I guess 🙂

practicalli-johnny13:07:26

My code isnt quite bad enough yet to delete it all :rolling_on_the_floor_laughing:

ericdallo13:07:27

I think .lsp/sqlite.db would be enough

practicalli-johnny13:07:39

Ah, I had old definitions of those functions in a (comment ,,,) block at the bottom of the file that were being picked up.

practicalli-johnny13:07:29

I assume there is some key to instruct lsp / clj-kondo to ignore the contents of a comment block - obviously not the :redefined-var key I was using

ericdallo13:07:37

clojure-lsp consider the latest definition of a var like clojure, but it doesn't consider if the var is inside a comment block, it'd not be that easy to implement that

practicalli-johnny13:07:51

😭 Oh, I use a lot of comment blocks, so I will keep this in mind. Thanks for your help

borkdude13:07:30

you can configure clj-kondo to skip comment blocks as if they don't exist

ericdallo13:07:45

yeah, that'd be the best choice IMO ☝️

practicalli-johnny13:07:04

I see there is a :skip-comments false configuration, I'll try that in my global clj-kondo config (assuming I have one)