lsp

:clojure-lsp: Clojure implementation of the Language Server Protocol: https://clojure-lsp.io/
borkdude 2021-02-20T10:56:41.000800Z

Made a video about clojure-lsp (my initial experiences after using it for 1 week) https://youtu.be/WMnVv63ezFQ A little bit chaotic, apologies ;)

πŸ‘ 2
1
❀️ 2
πŸŽ‰ 1
borkdude 2021-02-20T11:12:02.000900Z

@ericdallo Unfortunately I had to remove a section about renaming since that didn't work at all :(

borkdude 2021-02-20T11:12:37.001100Z

And you can also see how I have some problems with auto-complete... but I explained this yesterday.

borkdude 2021-02-20T11:14:13.001300Z

But overall, good stuff ;)

ericdallo 2021-02-20T14:03:25.002600Z

Really good video @borkdude, thank you for that!

borkdude 2021-02-20T14:03:52.002800Z

:)

ericdallo 2021-02-20T14:04:02.003Z

Your completion issue is really odd indeed, I'll try to reproduce with a clean emacs later

borkdude 2021-02-20T14:18:34.003300Z

@ericdallo You can try my entire emacs setup here: https://github.com/borkdude/prelude It even contains all elpa packages ;)

πŸ‘ 1
2021-02-20T17:46:11.007Z

Hi folks, I often edit .cljc files with reader conditionals in the ns :require block:

(ns my-app.core
  (:require
    [my-app.foo :as foo]
    #?@(:cljs
      [[my-app.bar :as bar]])))

2021-02-20T17:48:30.008300Z

This seems to break the add-missing-libspec action. Should this work, or is it too much of a unique use-case to support?

ericdallo 2021-02-20T17:50:44.009700Z

It's indeed a bug @jkrasnay πŸ˜” Please, open an issue with that minimal repro, clojure-lsp should know how to handle that IMO

2021-02-21T13:34:47.042800Z

I’m trying to create a repro but add-missing-libspec has seemed to stop working for me at all, even for plain .clj files. I’ve tried clearing out .lsp/sqlite.db and restarting but it’s no help. Unfortunately I don’t see any logs under /tmp either. Any ideas?

ericdallo 2021-02-21T13:35:51.043Z

Are you running arr-missing-libspec via code actions or manually executing lsp-clojure-add-missing-libspec ?

ericdallo 2021-02-21T13:42:55.043200Z

you can try lsp-clojure-server-info and find the log-path where it will point to the clojure-lsp log path

2021-02-21T13:44:27.043400Z

I’m running Neovim with this mapping from @snoe’s vimrc: nnoremap <silent> cram :call CocRequest('clojure-lsp', 'workspace/executeCommand', {'command': 'add-missing-libspec', 'arguments': [Expand('%:p'), line('.') - 1, col('.') - 1]})<CR>

2021-02-21T13:44:58.043600Z

Other similarly mapped commands are working, e.g. introduce-let

2021-02-21T13:47:23.043800Z

Not sure how to run the equivalent of lsp-clojure-server-info in Neovim (that looks like an Emacs command to me). Let me try to figure that one out.

ericdallo 2021-02-21T13:47:29.044Z

I see, the issue with manually calling the commands is that you need to know if for that ns is supported, that's way I recommend calling code actions instead

ericdallo 2021-02-21T13:47:58.044200Z

it's the same of your mapping but change add-missing-libspec -> server-info

ericdallo 2021-02-21T13:48:27.044400Z

I'd suggest using code actions instead of manually calling refactor commands (that may not be available all the time, depending on your code)

ericdallo 2021-02-21T13:48:42.044600Z

@dharrigan knows how to call code actions in vim πŸ™‚

2021-02-21T13:50:15.044900Z

Got it. Yeah, @dharrigan was giving me some help on the #vim channel. add-missing-libspec wasn’t showing in my code actions either, but now I’ve found the log!

1
2021-02-21T13:53:29.045200Z

FYI I guess MacOS has some fancy ideas on where to put temp files. My log was in /var/folders/6k/qwsbhrf9291gjy8vs1nyyq7h0000gn/T/clojure-lsp.13565201280854705473.out

ericdallo 2021-02-21T13:54:31.045400Z

yeah, @snoe had the same issue, is like JVM save the log on createTempFile , not sure there is a better way to improve that without messing with user folders permissions

2021-02-21T13:57:55.045700Z

The problem was that I was trying to resolve str/lower-case. string/lower-case resolves fine. Obvious in retrospect 😊

ericdallo 2021-02-21T14:00:04.045900Z

yeah, that's why code actions are more reliable πŸ™‚ If there is any way to add that require/import, it'll return the code action, otherwise not

2021-02-21T14:03:41.046100Z

Thanks for your help!

ericdallo 2021-02-21T14:05:15.046300Z

you are welcome πŸ™‚

dharrigan 2021-02-21T16:18:33.061900Z

Out of curiosity, would it then be your advice not to use mappings such as "noremap <silent> cram :call CocRequest('clojure-lsp', 'workspace/executeCommand', {'command': 'add-missing-libspec', 'arguments': [Expand('%:p'), line('.') - 1, col('.') - 1]})<CR>" and only rely upon the codeaction (menu)?

ericdallo 2021-02-21T16:20:05.062100Z

The issue is that add-missing-libspec is a command that will only work if the namespace can be imported otherwise will do nothing. The add-missing-* code actions are already returned if it's confirmed that could be imported, so it's a better UI IMO

dharrigan 2021-02-21T16:24:29.063300Z

makes sense

dharrigan 2021-02-21T16:24:53.063700Z

I shall update my vimrc πŸ™‚

1
dharrigan 2021-02-21T16:25:52.064400Z

The only two I now have are clean-ns and cycle-privacy

ericdallo 2021-02-21T16:29:48.064600Z

cycle privacy is available via code action too, and not make sense call in a non function, but it's your choice, is not a huge difference

dharrigan 2021-02-21T16:30:41.065Z

true, I'm normally "in" a function when I do crcp to quickly toggle the privacy. Yes, using a code action would achieve the same πŸ™‚

dharrigan 2021-02-21T16:31:11.065200Z

As an aside, does clojure-lsp know if the thing on a doHover is a Java import?

dharrigan 2021-02-21T16:31:33.065400Z

I'm curious to know if it might be possible to show javadoc on a known Java interop method

dharrigan 2021-02-21T16:32:27.065600Z

i.e., if I press K (a well-known show me the source binding), then if I'm on a, say for example a .javaMethod it would pop up and show the javadoc for javaMethod

ericdallo 2021-02-21T16:52:36.066400Z

Yeah we know but clj-kondo analysis doesn't has that yet πŸ˜•

dharrigan 2021-02-21T16:52:51.066600Z

np πŸ™‚

2021-02-20T18:50:24.011800Z

Is there a way to configure the command to generate classpaths for each project?

ericdallo 2021-02-20T18:51:22.012700Z

What do you mean? What's your issue?

lispers-anonymous 2021-02-20T18:52:37.014100Z

I have a clojurescript project that outputs cljs files (for source maps I think) to a directory nested under the resources directory of my project. Is there a way to make clojure-lsp ignore this directory? Sometimes when I try to navigate to a var definition, it jumps me to a file under this directory when the preferred file exists under my source directory.

snoe 2021-02-21T14:55:22.047100Z

Hrm, that might be a bug, we should only save jar analysis in the db, no matter the flag. @ericdallo If you look at your classpath, there's basically three types of things in there. A) jar files, B) target directories (`output/:target/`) C) source directories (`src/)`. If you set that flag to true, LSP should only walk the jar files from the classpath (A), if the flag is false, then directories (B) would also be analyzed (but should not be stored) and then (as always) we analyze source-paths based on settings and independent from classpath source paths (C). I'm guessing we messed up what we store in the db when switching to kondo

ericdallo 2021-02-21T15:03:45.047400Z

So if set that flag to true it'll stop walking that jar files? is that make sence? I think we just need a flag to not check the target directories, right?

snoe 2021-02-22T02:36:59.095400Z

No, jars always get walked, if true the directories don't get walked

ericdallo 2021-02-22T03:23:02.095700Z

Alright, I see the point of the boolean now, I saw that the code ignore directories if true, but that won't ignore source paths that are directories too?

snoe 2021-02-22T04:20:55.096500Z

yeah, source-paths get added on after directories are stripped iirc

snoe 2021-02-22T04:21:46.096700Z

Honestly, true should be the default behaviour, I just wasn't comfortable changing it before.

lispers-anonymous 2021-02-20T18:53:52.014200Z

I tried setting ignore-classpath-directories to true but that didn't seem to solve my problem

2021-02-20T18:54:11.014400Z

I have a project that needs aliases to generate the correct dev classpath. As in clojure -A:dev -Spath

borkdude 2021-02-20T18:55:09.014600Z

@mynomoto This is what I have in .lsp/config.edn at work:

{:project-specs [{:project-path "deps.edn"
                  :classpath-cmd ["clojure" "-A:frontend:backend" "-Spath"]}]}

2021-02-20T18:55:10.014800Z

So what I would think that could work is a project specific project-specs.

ericdallo 2021-02-20T18:55:22.015Z

Got it, you can configure a custom project-specs for that

ericdallo 2021-02-20T18:55:29.015200Z

yes, like that ☝️

2021-02-20T18:56:19.015400Z

Oh, this is great! Thank you @borkdude and @ericdallo.

πŸ‘ 2
ericdallo 2021-02-20T19:02:58.015800Z

Yeah, the ignore-classpath-directories is exactly for that, but I don't know exactly how it works, it's odd to me that it's a boolean, if true it'll ignore what folders? @snoe should that be a set of files/folders? otherwise, how that does work?

lispers-anonymous 2021-02-20T19:06:35.016Z

I'm currently attempting force lsp to start with a fresh late by deleting the sqlite.db file. Maybe it held onto some stuff when I set that ignore-classpath-directories thing

πŸ‘ 1
2021-02-20T19:09:50.018900Z

I'm trying to explore the https://github.com/furkan3ayraktar/clojure-polylith-realworld-example-app using lsp to navigate between the files. But the navigation works in several cases only after entering manually on the destination file. Should it work without that?

ericdallo 2021-02-20T19:10:24.019100Z

Yes, with the classpath scan when starting the project

ericdallo 2021-02-20T19:10:37.019300Z

check /tmp/clojure-lsp.*.out log when initializing the server

ericdallo 2021-02-20T19:12:55.019600Z

@mynomoto since it's a project with not default folders src test , you should configure it

ericdallo 2021-02-20T19:13:25.019800Z

with source-paths : https://clojure-lsp.github.io/clojure-lsp/settings/

ericdallo 2021-02-20T19:14:25.020100Z

or import the specific project instead of the root, like clojure-polylith-realworld-example-app/rest-api on the first time you open the project (lsp-mode should prompt for you to chosse the root, then you should choose the subproject if you wanna try this way)

2021-02-20T19:15:06.020500Z

So, those are on the :dev alias under :extra-paths and they apear on the classpath generated using clojure -A:dev -Spath

2021-02-20T19:16:16.020700Z

I'm using coc, I think it doesn't work the same as lsp-mode.

ericdallo 2021-02-20T19:16:29.020900Z

but are they on source-paths?

2021-02-20T19:17:36.021100Z

No, they are not. Just to make it clear to me, it won't work with :extra-paths?

2021-02-20T19:19:11.021300Z

OK, will do

2021-02-20T19:19:54.021500Z

And it has to be on the top-level of deps.edn? I renamed the extra-paths to source-paths on the alias (as there is no top-level source-paths) and got the same result.

ericdallo 2021-02-20T19:20:21.021700Z

no, they are different things, extra-paths is something you tell clj what are the extra-paths for your classpath, but clojure-lsp doesn't know that (or is not smarter enough, not sure that would be possible or could be confusing), so you need to tell clojure-lsp what are the dirs that contains the clojrue code of your project, the default are src and test

ericdallo 2021-02-20T19:20:41.021900Z

the source-paths need to be specified on .lsp/config.edn not in any deps.edn πŸ˜…

ericdallo 2021-02-20T19:21:07.022200Z

thank you!

2021-02-20T19:21:10.022400Z

Oh, got it, thanks! Let me try that.

πŸ‘ 1
ericdallo 2021-02-20T19:21:54.022700Z

For most common clojure projects, the default is enough, since this project use a different folders arch, you need to specify that

2021-02-20T19:30:18.023100Z

Sorry for missing the file where :source-paths should go, now everything is working. Thank you! I wonder if the classpath information (that considers the :extra-path configuration on deps.edn) should not be enough for analysis since that is what clj-kondo uses. I'm sure there is a reason why this is necessary and I just don't know what it is. Thank you for your work on clojure-lsp, I think is an amazing project!

lispers-anonymous 2021-02-20T19:32:29.023300Z

I am unsure if I've fixed it. I deleted the sqlite.db file, I ran lein clean on my project (which cleaned up the extra cljs files in resources). I'm not jumping into that directory anymore. We will see if it holds.

1
ericdallo 2021-02-20T19:34:07.023500Z

Nice! Yeah, that something to improve probably, but we need to take care to not mess with already working source-paths, but I agree that should be cool feature to have, for leon projects too checking the project.el Feel free to open a feature request issue :)

πŸ‘ 1
zane 2021-02-20T22:12:45.028200Z

Has anyone had any luck using clojure-lsp with Instaparse? Instaparse appears to define may of its symbols via a macro: defclone. This appears to confuse clojure-lsp triggering unresolved-vars errors. I tried fixing this by adding instaparse.macros/defclone clojure.core/def under the :lint-as key in .clj-kondo/config.edn, but that didn’t work.

ericdallo 2021-02-20T22:13:47.028300Z

Hey, I don't know what is Instaparse, but I imagine it has a custom macro, right?

ericdallo 2021-02-20T22:14:16.028500Z

If so, the correct way to fix the macro lint error is to configure via clj-kondo indeed with :lint-as

borkdude 2021-02-20T22:14:21.028700Z

The config you mention should work

ericdallo 2021-02-20T22:14:42.028900Z

@zane past here the exact config

borkdude 2021-02-20T22:16:35.029100Z

You will probably need to re-crawl your sources after adding that config

zane 2021-02-20T22:17:02.029300Z

{:lint-as {clojure.test.check.clojure-test/defspec clojure.core/def
           clojure.test.check.properties/for-all clojure.core/let
           instaparse.macros/defclone clojure.core/def
           metaprob.generative-functions/gen clojure.core/fn}}

zane 2021-02-20T22:17:13.029500Z

I see. How do I trigger a re-crawl?

zane 2021-02-20T22:17:26.029700Z

I tried just making a small edit and saving.

borkdude 2021-02-20T22:17:28.029900Z

@zane rm -rf .lsp/sqlite* and then re-open the project

zane 2021-02-20T22:17:44.030100Z

Let me try that.

borkdude 2021-02-20T22:18:40.030300Z

@ericdallo Maybe the crawler should take into account a hash of the clj-kondo config for caching?

zane 2021-02-20T22:18:51.030500Z

@borkdude That fixed it. Cheers!

borkdude 2021-02-20T22:19:03.030700Z

:thumbsup:

ericdallo 2021-02-20T22:19:06.030900Z

I was thinking exactly that @borkdude, we could hash the clj-config used

zane 2021-02-20T22:19:35.031100Z

@borkdude By the way, I’m giving clojure-lsp another go because of your recent video, so thanks for that as well. πŸ‘:skin-tone-2: πŸ™‚

1
πŸŽ‰ 1
borkdude 2021-02-20T22:19:48.031300Z

πŸŽ‰ :)

ericdallo 2021-02-20T22:22:18.031700Z

Created this to improve that behavior πŸ™‚ https://github.com/clojure-lsp/clojure-lsp/issues/331

2
zane 2021-02-20T23:29:09.033300Z

I’m experiencing something a bit strange with completion. In one of the files in my project completion isn’t available before a certain line, but is available after it. The only significant thing about the line in question is that it has a .cljc reader conditional on it. :thinking_face:

ericdallo 2021-02-20T23:29:41.033400Z

could you show a little repro?

zane 2021-02-20T23:29:58.033600Z

Would it help to create a repro project?

zane 2021-02-20T23:30:04.033800Z

Or do you want the code around the line in question?

ericdallo 2021-02-20T23:33:15.034200Z

A repro project would be perfect, could you open an issue linking that project?

zane 2021-02-20T23:35:13.034400Z

Will do (if I’m successful at creating the repro project!).

πŸ‘ 1