lsp

:clojure-lsp: Clojure implementation of the Language Server Protocol: https://clojure-lsp.io/
adambros 2020-08-27T01:21:14.006200Z

Is there a way to disable or configure the addition of ns forms to files? It currently tries to write (ns main.foo.bar) where main comes from src/main/foo/bar.clj , and sometimes it seems to write the ns form multiple times. I'm using

clojure-lsp --version
clojure-lsp release-20200819T134828
and Plug 'autozimu/LanguageClient-neovim', {'branch': 'next', 'do': 'bash install.sh'}

ericdallo 2020-08-27T13:01:33.010300Z

It's a new option @adambros, I added it yesterday 😆

ericdallo 2020-08-27T01:24:03.006600Z

Yeah, I already faced that issue, clojure-lsp tries to add a ns when creating a new file but I think clojure-mode also add this making a duplicated addition

ericdallo 2020-08-27T01:24:17.006800Z

I'll try to address a PR to make that optional 🙂

ericdallo 2020-08-27T01:32:16.007Z

Actually, for emacs it's clj-refactor that adds a namespace already: https://github.com/clojure-emacs/clj-refactor.el/blob/master/clj-refactor.el#L53

dpsutton 2020-08-27T02:29:45.007900Z

i think he was using neovim in this case

👍 1
ericdallo 2020-08-27T03:17:27.008100Z

Yes, but this new setting may work too 🙂

ericdallo 2020-08-27T03:17:42.008400Z

@snoe :reviewplease: https://github.com/snoe/clojure-lsp/pull/175

🆗 1
dpsutton 2020-08-27T03:20:45.008600Z

ah missed that part 🙂

😄 1
adambros 2020-08-27T03:32:37.008800Z

Thanks for the help! I for some reason had glanced straight over that option in the readme 😅

rafaeldelboni 2020-08-27T15:22:04.012300Z

Hey I just updated to the new versions with clj-kondo and my lsp is just hanging my pc (fans just going to full speed) and the starting lsp server never finishes. Do I need to add any special config anywhere, looks like it's trying to lint all depencies of my project.

snoe 2020-08-27T15:24:33.013400Z

@rafaeldelboni yeah I've run into that with large classpaths, working with kondo to fix it but for now you might have to use an old release https://github.com/snoe/clojure-lsp/releases/tag/release-20200805T150718

rafaeldelboni 2020-08-27T15:25:01.013700Z

Thanks I will rollback

borkdude 2020-08-27T15:25:09.014Z

@snoe what more do you need from clj-kondo to fix this?

snoe 2020-08-27T15:26:43.014300Z

I think if it's affecting others it'll be a kondo release, but even after the vec changes I managed to run into a stackoverflow yesterday. Still investigating from my end but I think it'll be a change like you said to use transducers or recur in the recursion

borkdude 2020-08-27T15:28:32.014600Z

One other option is to not use any return values from the linted libraries. I think most things are written to some local atoms anyway

borkdude 2020-08-27T15:28:57.014800Z

I'll make an issue for it

borkdude 2020-08-27T15:31:21.015Z

https://github.com/borkdude/clj-kondo/issues/972

borkdude 2020-08-27T15:32:11.015400Z

I also want to look into parallel linting, that would maybe make it easier as well

borkdude 2020-08-27T15:32:50.015600Z

One workaround in clojure-lsp might be to not lint the entire classpath at once, but maybe in groups of 10 libs or so in a doseq

snoe 2020-08-27T15:34:20.015900Z

ah good idea:bulb:

ericdallo 2020-08-27T15:34:49.016100Z

Yeah, we could try to do that, as we are not using the kondo analysis data, we could only lint the current file/text

ericdallo 2020-08-27T15:34:54.016300Z

WDYT @snoe?

borkdude 2020-08-27T15:35:25.016500Z

You can also make linting the entire classpath optional and then do it in groups of 10

snoe 2020-08-27T15:35:26.016700Z

The cache gives us signature diagnostics

borkdude 2020-08-27T15:35:32.016900Z

ah ok

snoe 2020-08-27T15:35:52.017100Z

(and I want to add the cross-ns unresolved symbol lint)

borkdude 2020-08-27T15:36:03.017300Z

:thumbsup:

ericdallo 2020-08-27T15:36:37.017500Z

> (and I want to add the cross-ns unresolved symbol lint) Yeah, with that we can only use kondo for almost every analysis

borkdude 2020-08-27T15:37:03.017700Z

Shouldn't be too hard to get in

ericdallo 2020-08-27T15:37:27.017900Z

Yes, I started a branch doing that, but is not that easy haha

ericdallo 2020-08-27T15:38:05.018100Z

https://github.com/snoe/clojure-lsp/pull/176

ericdallo 2020-08-27T15:38:28.018400Z

Feel free to help with that @snoe 😉

borkdude 2020-08-27T15:38:53.018600Z

Oh :) I think it can be done entirely in impl/linters.clj in clj-kondo, as an optional linter. Already discussed with @snoe in #clj-kondo I think

👏 1
borkdude 2020-08-27T15:39:28.018900Z

Right now it only warns about unresolved symbols from the current namespace. It's only a small step to extend that to other namespaces probably

snoe 2020-08-27T15:39:37.019100Z

oh wow @ericdallo nice start

ericdallo 2020-08-27T15:42:55.019300Z

Thanks! Yes @borkdude, It would be really cool to left all analysis to kondo

borkdude 2020-08-27T15:48:09.019500Z

It would be nice to have some repro of the out of memory or stackoverflow issue

borkdude 2020-08-27T15:48:22.019700Z

E.g. post the classpath in the issue

snoe 2020-08-27T15:55:10.019900Z

@borkdude mind if i dm it to you? not quite comfortable sharing publicly

borkdude 2020-08-27T15:57:16.020100Z

sure!

borkdude 2020-08-27T15:57:47.020300Z

It might be one specific jar file. Since I can't reproduce it by concatenating one directory 10k times:

$ clj-kondo --lint $(bb -e "(println (str/join \":\" (repeat 10000 \"src\")))")
linting took 3670ms, errors: 0, warnings: 0

1
snoe 2020-08-27T16:18:08.020600Z

looking a bit I think running in a go block in lsp probably contributed to the stack size

1
borkdude 2020-08-27T16:34:31.020900Z

Linted twice successfully with the released clj-kondo and the cp snoe gave me: > linting took 43652ms, errors: 2176, warnings: 3996

ericdallo 2020-08-27T16:41:48.021100Z

@snoe do you think it's really clj-kondo that is causing that slowness? My guess is that the jars crawler that are causing these issues

snoe 2020-08-27T16:51:13.021300Z

so the jar crawler only happens once and hashes your project file. kondo always runs in the released version of lsp. But yeah i've isolated it to kondo locally and like I said it's inconsistent when the overflow happens but I'm also manipulating how lsp calls it so I suspect we're just on a threesshold.

ericdallo 2020-08-27T16:53:54.021500Z

Hum, I see

snoe 2020-08-27T17:06:44.022Z

@borkdude if I could get a release of kondo with https://github.com/borkdude/clj-kondo/pull/964 I could push an lsp release that at least is much more consistent for people and I'll just keep an eye on the new issue and try to recreate.

☝️ 1
borkdude 2020-08-27T17:12:01.022500Z

@snoe What about dependending on "2020.07.30-20200826.174236-11". It is a SNAPSHOT, but it won't change from under you

borkdude 2020-08-27T17:14:05.022700Z

I'd rather revert the change really and fix it with a proper repro, so we know what we are doing

borkdude 2020-08-27T17:14:49.022900Z

I haven't seen this issue with anyone using clj-kondo in its 1.5 year lifetime and it's used a lot

snoe 2020-08-27T17:18:03.023100Z

is that in maven? then that works for me

snoe 2020-08-27T17:20:17.023300Z

yup that works! thanks

borkdude 2020-08-27T17:31:00.023500Z

yes, every SNAPSHOT has a "real" version that is based on the date that it was pushed

borkdude 2020-08-27T17:49:00.023700Z

I did some analysis on the calls to process-file in clj-kondo.impl.core and the stack depth isn't any deeper than 1 really, so I don't see how vec helps there

borkdude 2020-08-27T17:49:33.023900Z

it only recurses for jars and dirs, but it's only one level

☝️ 1
borkdude 2020-08-27T17:52:10.024200Z

However in analyzer.clj we do a deep recursion for nested forms, so if there's a very deep call, it may cause the issue. I'll try to repro that

👀 1
borkdude 2020-08-27T17:56:25.024500Z

No problem with 300 nested calls. And I've never seen an expression that big in any real code

borkdude 2020-08-27T17:57:17.024700Z

😳 2
😂 1
snoe 2020-08-27T17:59:23.025500Z

@rafaeldelboni can you try the new release? https://github.com/snoe/clojure-lsp/releases/tag/release-20200827T175529

snoe 2020-08-27T18:01:14.026100Z

First run I get:

INFO  clojure-lsp.crawler: clj-kondo scanned project classpath in 69024ms
DEBUG clojure-lsp.main: :initialize 105825 ()
Subsequent runs I get:
INFO  clojure-lsp.crawler: skipping classpath scan due to project hash match
DEBUG clojure-lsp.main: :initialize 9707 ()

ericdallo 2020-08-27T18:02:01.026700Z

@rafaeldelboni you can get the logs from /tmp/lsp.out

borkdude 2020-08-27T18:05:50.027100Z

Do you have any stacktraces / dumps of when the error happened?

snoe 2020-08-27T18:06:37.027300Z

unfortunately no. just got the error message, i was throwing away the trace

borkdude 2020-08-27T18:08:04.027500Z

can you try to reproduce with the change reverted?

👍 1
ericdallo 2020-08-27T18:15:33.027700Z

On a big project... first run I get:

INFO  clojure-lsp.crawler: clj-kondo scanned project classpath in 46185ms
DEBUG clojure-lsp.main: :initialize 101477 ()
Subsequent runs i get:
INFO  clojure-lsp.crawler: skipping classpath scan due to project hash match                                                                                                                  
DEBUG clojure-lsp.main: :initialize 14369 ()   

borkdude 2020-08-27T18:32:58.028Z

Meanwhile I'll work on a change where no return values are needed anymore. I'm only using it for a small thing which can be refactored

borkdude 2020-08-27T18:33:08.028200Z

so we can just use run!

snoe 2020-08-27T18:49:49.028400Z

So before the lazy-fix there actually wasn't a stack trace:

(catch Throwable e
  (log/info "pre kaboom ")(.printStackTrace e)                        (log/error e "kaboom"))

snoe 2020-08-27T18:49:59.028700Z

INFO  clojure-lsp.crawler: pre kaboom
ERROR clojure-lsp.crawler: kaboom
java.lang.OutOfMemoryError: GC overhead limit exceeded

borkdude 2020-08-27T18:50:58.028900Z

Hmm, GC overhead. In clj-kondo.core there is a doall around all of this mapcat stuff, so it would get realized anyway. Not sure how vec would have fixed that?

snoe 2020-08-27T18:53:51.029100Z

I think it's cause concat/mapcat are creating nested linked-lists that can are building more objects than you want

snoe 2020-08-27T18:54:05.029300Z

I think i linked to the blog post in the pr that explains it better than i can

borkdude 2020-08-27T18:55:02.029500Z

ok

snoe 2020-08-27T18:57:18.029700Z

And whatever graal does must be better at cutting down on number of objects or something like that

borkdude 2020-08-27T18:57:57.029900Z

hmm

snoe 2020-08-27T18:58:49.030100Z

my hope is that if we switch to kondo for analysis we can then work on moving lsp to graal too

borkdude 2020-08-27T19:00:33.030300Z

I'm using the JVM for clj-kondo.lsp which is used in Visual Studio Code

borkdude 2020-08-27T19:00:41.030500Z

but it can also be used with emacs probably

borkdude 2020-08-27T19:00:54.030700Z

it was a great alternative for Windows when GraalVM didn't work there

borkdude 2020-08-27T19:01:09.030900Z

and people don't have to install anything as long as they already have java

borkdude 2020-08-27T19:01:28.031100Z

just download the VSCode plugin, done

snoe 2020-08-27T19:01:32.031300Z

ah, good to know

ericdallo 2020-08-27T19:02:18.031500Z

Really good idea indeed

rafaeldelboni 2020-08-27T21:13:27.032700Z

Looking good now First Run:

INFO  clojure-lsp.crawler: clj-kondo scanned project classpath in 38472ms
DEBUG clojure-lsp.main: :initialize 86873 ()
Second Run:
INFO  clojure-lsp.crawler: skipping classpath scan due to project hash match
DEBUG clojure-lsp.main: :initialize 6413 ()

2
borkdude 2020-08-27T21:59:24.032900Z

@snoe Version "2020.07.30-20200827.215744-12" should be even better. I now avoided all map(v) and mapcats when processing files, there's only run! over files now

borkdude 2020-08-27T21:59:33.033100Z

Less garbage

borkdude 2020-08-27T22:00:57.033300Z

This is the version that corresponds to master @ 157cc964a180432c27c447cb32d45bac7f391c0f

snoe 2020-08-27T22:04:05.033500Z

thanks!