Fork me on GitHub
#lsp
<
2021-08-06
>
dharrigan12:08:45

You know what might be a neato idea, but no idea if possible

dharrigan12:08:59

You know on the codeLens, where it tells you something like this:

dharrigan13:08:55

Let's say that this defn is only ever referenced by that namespace, thus I could choose to mark it as private, would it be possible to highlight that for me? LIke 1 reference, private only? If that function is used in another namespace, then it could show something like 1 reference external, 1 reference local

dharrigan13:08:33

Not sure if I'm explaining myself clearly, I guess what I'm looking for is a way to easily see if functions could be made private quickly and easily.

dharrigan13:08:46

so that my public api is clear.

ericdallo13:08:58

it's a valid idea, it could be done

ericdallo13:08:09

but would affect a little performance

dharrigan13:08:09

clj-kondo already knows if a function is private

ericdallo13:08:28

it knows when a function is private when it's marked as private

ericdallo13:08:35

for other features we would to check the references

ericdallo13:08:44

we already do that to lens

ericdallo13:08:53

but we would need to take care with performance

ericdallo13:08:01

but looks a valid flag/option

dharrigan13:08:08

Sure. Let me raise it as an issue for consideration on github

ericdallo13:08:22

yes, please open a feature request with those details 🙂

borkdude13:08:10

this would be possible for a clj-kondo analysis perspective

borkdude13:08:27

could also make a custom linter from this

ericdallo13:08:08

yes, that's the idea, is just that custom lint is probably the heavier code of clojure-lsp which checks each var definition and count the references in the project

ericdallo13:08:18

we need to change it carefully

borkdude13:08:52

@U11EL3P9U You could also just write a custom linter for yourself using clj-kondo, while not seeing it in the editor but periodically writing out an HTML report for yourself to view

borkdude13:08:26

Vars that are not private but only used in current ns-report.html

dharrigan13:08:43

Sure, could do, would rather prefer if it was in the editor and done dynamicaly for me as I change the code about and jump from namespace to namespace.

borkdude13:08:53

yeah makes sense

lassemaatta14:08:40

I'm sure this is explained somewhere, but are those code lens things supposed to be interactive (in emacs)? The "N references" text looks clickable and the mouse cursor changes on hover, but nothing seems to occur.

ericdallo14:08:19

they are suppose to be interactive, but it doesn't work for reference lens 😕

ericdallo14:08:32

explanation:

ericdallo14:08:07

LSP lens only allows trigger commands when clicking in a code lens, for example a code lens of Run or Debug should trigger a run or debug command for your app

ericdallo14:08:22

references is something that needs a return, is not a command, so it's tricky, we just show it with a command that doesn't actually exists/works

lassemaatta14:08:07

ah, I see. thank you for the explanation

ericdallo14:08:15

It could be implemented on lsp-mode/vim etc to support that somehow, but it'd not follow the spec and it'd need to be done on each lsp client

lassemaatta14:08:45

it would be awfully nice if it could open something like lsp-treemacs-call-hierarchy when clicked, for example

ericdallo14:08:45

IMO this is something that could be improved in LSP spec

ericdallo14:08:28

yeah, maybe we could hack only lsp-mode to advice that somehow, but it would need custom code just for clojure

lassemaatta14:08:30

perhaps it's better to be patient and wait for the spec to improve

ericdallo14:08:18

yeah, I probably should save a time to open an issue there 😅

Noah Bogart14:08:50

if you figure out how to make it work in lsp-mode, i’ll make it work in coc-nvim

🔥 3
neovim 3
anonimitoraf00:08:24

In vscode (JS/TS), clicking a lens shows references. Does that mean vscode doesn't follow the spec? Also, what sort of lsp-mode advice are you thinking @UKFSJSM38?

ericdallo00:08:17

Probably VSCode is not following/not using LSP for the lens you tested

3
ericdallo00:08:16

I know VSCode has its own Js/ts implementation not using lsp

ericdallo00:08:24

But you can still use LSP with it

ericdallo00:08:32

But the lens are probably not from lsp

anonimitoraf00:08:42

Ah, right. I assumed they are

anonimitoraf00:08:49

So, what sort of things make sense to get triggered on Lens click (LSP)? Perhaps we can wrap any of those actions with an advice?

ericdallo00:08:49

Debug/run lens, like java or Dart have

Noah Bogart00:08:43

The typescript lsp and server are tightly bound and have a lot of non standard functionality

😞 3
anonimitoraf00:08:53

Ah 😞 sounds like it'll be a big hack to utilize those for showing call heirarchy/references

ericdallo00:08:58

The advice is something completely custom done in client, don't know it worth the work

ericdallo00:08:36

Call hierarchy is already possible with clojure-lsp

ericdallo00:08:42

Not just via lens click

Noah Bogart00:08:45

Technically because of how the message protocol works, clojure-lsp could do the same but then we'd have to implement that behavior in each client

☝️ 3
anonimitoraf00:08:57

I mean, with lens click as @U0178V2SLAY said

anonimitoraf00:08:25

Yea, nvm. Actually I don't know why I'm invested in this 😛 I rarely use my mouse

ericdallo00:08:47

I think custom methods are good for features specific for each lang/server like clojure which has a custom one to "resolve a macro as..." Which automatically change your clj-kondo config

3
☝️ 3
Noah Bogart00:08:28

Agreed. A non-standard feature I do want to get into clojure-lsp at some point is “import X from namespace Y” in the completion menu, but I need to do more research on how tsserver does it first to get an understanding of what that entails

anonimitoraf00:08:05

clojure-lsp does that already, to some extent as far as I know

Noah Bogart00:08:56

oh? when typing an unknown var, the completion will say “import X from namespace Y” and then if you highlight it and press “enter” (or whatever), it completes the symbol while also adding it to the namespace declaration?

anonimitoraf00:08:45

Weird, just tried it. Doesn't work anymore. I remember (once or twice in the past): • Typing some-func • Executing code actions • Selecting: import some-func from some-ns @UKFSJSM38 Was this supported at one point?

Noah Bogart00:08:09

oh, as a code action i think that works

Noah Bogart00:08:17

just not as a combined part of completion

anonimitoraf00:08:55

Right, yea. I sometimes use emacs for TS/JS and the completion is via code action. In vscode it's part of completion, yea

ericdallo01:08:16

The code action works, and we have support for add when completed as well, not sure if there is a bug

Noah Bogart01:08:07

Oh really? I can’t get the “add when completed” to work

Noah Bogart01:08:14

Maybe I'm doing it wrong

ericdallo01:08:15

we used to have that, let me check if it's working

ericdallo01:08:36

yep, working

ericdallo01:08:05

it works when completing an alias

anonimitoraf01:08:50

Hmm, I expect go-loop to be suggested here (from core.async)

ericdallo01:08:47

there are rules to require, for both completion or code action, clojure-lsp will be able to require a ns if: • it's a known common alias, like string , io , set async etc • the alias was already required before in a ns of the project, otherwise there is no way for clojure-lsp know.

ericdallo01:08:26

your case is not an alias, is a refer, we could improve clojure-lsp to understand some common refers like go-loop , actually, it already knows deftest testing is

Noah Bogart01:08:03

Does kondo know about every public var in all classpath namespaces? Does clsp?

ericdallo01:08:18

we just need to be careful with what we add to completions without anything typed yet, because clojure-lsp already return 800+ items, if we'd add all public vars of all classpath that would probably blow up

Noah Bogart01:08:19

Oh wow, interesting. Guess I don’t know how the completion works. I thought it was as you typed, not before

ericdallo01:08:23

the completion can be triggered at any time, with something typed or even with nothing typed yet

ericdallo02:08:37

FYI: I added clojure.async.core common macro/functions to suggested require code actions: https://github.com/clojure-lsp/clojure-lsp/commit/934e41cf7373d12d4fa8bf073cdcb78c44a33a55

🎉 3