Fork me on GitHub
#lsp
<
2021-09-01
>
andrea.crotti09:09:14

I always saw in various screenshots the references just next to a function (and now the tests as well which is very cool), but I never managed to find what's the magic lsp setting to enable that

andrea.crotti09:09:24

any idea how to get that to show?

borkdude09:09:52

it's code lens

borkdude09:09:01

lsp-lens-enable t

andrea.crotti09:09:05

ahh yes amazing

andrea.crotti09:09:39

if I click on it though nothiing happens even if it looks clickable

borkdude09:09:07

I never tried to click it. I don't use the mouse a lot except for scrolling in emacs

andrea.crotti09:09:58

yeah me neither but since it was clickable I assumed it would allow you to see the references somehow

andrea.crotti09:09:07

but anyway already nice to see

borkdude09:09:10

makes sense yeah, don't know

lassemaatta09:09:58

I asked about the same recently, can’t remember what was the reason it’s not supported

borkdude09:09:50

perhaps because it's ambiguous to what it should navigate to

andrea.crotti09:09:03

well I guess it would have just to show the list of links

djm10:09:03

I like that! I turned it off, when it used to be displayed above the function, but now that it shows the test references (and is less obtrusive), I’ve turned it back on

djm10:09:40

It’s interesting that there’s an lsp-avy-lens function, which claims to “Click lsp lens using ‘avy’ package” (it just gives me an error if I try to use it)

andrea.crotti10:09:45

one thing I'd always loved to have is the ability to actually jump easily to tests that (even without referencing them directly) test that particular function. That is beyond what LSP can do probably, and I did partially get it working with coverlay.el and cloverage reports, but it just tells you if a line was tested, still can't trace back to where.

djm10:09:28

Projectile has a function for that (`projectile-toggle-between-implementation-and-test` - C-c p t by default)

andrea.crotti10:09:11

well it just jumps to the test namespace, which could be empty, or you could be calling that function from other test namespaces

andrea.crotti10:09:23

so yeah it's not something you can do without detailed output from test coverage reports

djm10:09:15

Oh, yes - it’s for the namespace, not the specific function

andrea.crotti10:09:17

but I think it would be nice in general to have smarter tools to analyse how your code actually gets really tested, with maybe a mix of things like portal/reveal, tracing and test coverage reports

djm10:09:10

For functions, I use consult-xref to filter/select them, so easy to see just the test usages. Doesn’t help with the coverage part though.

practicalli-johnny11:09:32

The reference and test information is just information, it is not supported to do anything at the moment. There are LSP functions and key binding to go to and list references

andrea.crotti11:09:47

and as unrelated thing, what do you do to jump to any var definition in a given project? sometimes I know exactly the var name I want to go and could jump there without passing from the file

practicalli-johnny11:09:14

@andrea.crotti If on the name of the var, i.e. the name used in a call to that function, then its clj-find-var which is , g g or xref-find-definitions (`, g d` in spacemacs) Otherwise I would use helm-lsp-workspace-symbol (`, g s` in spacemacs) and type the name of the var I wanted to visit

practicalli-johnny11:09:34

I mostly just use find-definitions

practicalli-johnny11:09:28

although I do like the helm-lsp-workspace-symbol approach now I have taken another look. I assume there is something similar for ivy

andrea.crotti12:09:03

mm xref-find-definitions requires a TAGS file (I guess I have to set up something else) and I don't use helm anymore. In theory lsp-find-definition would be fine, it it could take a string as input, while now it just looks at what's currently under the cursor

ericdallo13:09:25

@andrea.crotti the lens are clickable but the LSP protocol doesn't allow to anything than call commands (calls that only do side effects), in the case of the references lens, we 'd need to show to user the references and navigate to the selected one, which is not possible with the actual LSP spec :/

andrea.crotti13:09:20

ah ok cool thanks

nwjsmith19:09:18

Just noticed that the "Extract function" code action isn't available from within deftests. I think it's because it isn't https://github.com/clojure-lsp/clojure-lsp/blob/cfde7c905cf1c743ae2dbbd8b5ff5c771b6a92e8/src/clojure_lsp/refactor/edit.clj#L33. Would it make sense to add deftest to that set?

ericdallo19:09:10

Feel free to open an PR more tests!

nwjsmith19:09:59

Will do, thanks!