lsp

:clojure-lsp: Clojure implementation of the Language Server Protocol: https://clojure-lsp.io/
Steiner 2021-01-23T02:09:51.050400Z

hey, guys. I have a question when using clojure-lsp as language server. when typing code like (f x), I found the company-mode wouldn't work, but if I type f, company-mode would work. what the hell ???

Alex 2021-01-26T08:14:38.103400Z

@steiner3044 are you familiar with tools/plugins that will automatically close your parents/brackets for you? That might help keep your code parsable for completion suggestions

Steiner 2021-01-26T08:21:29.103600Z

nope, the configure are all on the image I uploaded

Alex 2021-01-26T17:51:14.107400Z

@steiner3044 check out https://thoughtbot.com/blog/writing-clojure-in-vim which includes some helpful context around editing lisp/clojure code. One useful tool is to install Paredit (or a similar tool) which will help you keep balanced parentheses while adding, editing and deleting code

ericdallo 2021-01-23T02:26:06.050900Z

Hi @steiner3044 we ATM have a issue that we can't complete the code if it's not parseable (a valid clojure code), I'm trying to fix that and I opened this issue recently: https://github.com/clj-commons/rewrite-clj/issues/87

1💯
Steiner 2021-01-23T02:28:24.051300Z

wow, thank you for your work, I will watch this:slightly_smiling_face:

ericdallo 2021-01-23T02:29:14.051500Z

Thanks 😄

bringe 2021-01-23T02:36:56.051800Z

So I guess this explains an issue I had in my notes with clojure-lsp completions, (that the first time I type something like foo/ I don't see suggestions, but if I backspace the slash and type it again I do)

bringe 2021-01-23T02:37:17.052Z

Something like that at least

ericdallo 2021-01-23T02:38:13.052200Z

yep, that's something I'd love to fix 😅

Jakub Zika 2021-01-23T08:02:43.052400Z

What conflicts do you mean? I moved to Spacemacs with Cider + lsp-mode month ago and I did not experience any issue yet. Edit: did i just find one @lvh? Namespace is not filled automatically when creating a new file in a project.

ericdallo 2021-01-23T14:51:57.053Z

I just made a simple test compiling with native-image a simple sample project using the same sqlite db we use with clojure-lsp and it worked like a charm 🙂 I'll try to check why @thiagokokada branch is not working

borkdude 2021-01-23T14:53:48.053200Z

huh... sqlite worked with graalvm?

borkdude 2021-01-23T14:54:04.053400Z

I want to see the sample project :)

ericdallo 2021-01-23T14:54:30.053600Z

I'll push it and give you the link, one sec

ericdallo 2021-01-23T14:54:42.053800Z

I hope I did everything correct 😅

ericdallo 2021-01-23T15:04:55.054Z

It's really working, but it gives some exceptions during the build: (but the exceptions shows up even if a simple println clojure project :man-shrugging:)

ericdallo 2021-01-23T15:05:49.054400Z

this is the sample: https://github.com/ericdallo/clojure-sample

borkdude 2021-01-23T15:06:01.054700Z

Ah, this explains it. It's a fallback image. This is not really a native binary, but just a kind of uberjar.

borkdude 2021-01-23T15:06:12.054900Z

Compile with --no-fallback

ericdallo 2021-01-23T15:06:24.055100Z

oh... that's sad 😕

ericdallo 2021-01-23T15:06:47.055300Z

I see, probably it'll not work so

ericdallo 2021-01-23T15:07:05.055500Z

yeah, just saw the warning log right now :man-facepalming:

borkdude 2021-01-23T15:07:38.055700Z

Here are some standard args I always use:

args=("-H:+ReportExceptionStackTraces"
       "-H:ReflectionConfigurationFiles=reflection.json"
       "--initialize-at-build-time"
       "-H:Log=registerResource:"
       "-H:EnableURLProtocols=http,https,jar"
       "--enable-all-security-services"
       "-H:+JNI"
       "--verbose"
       "--no-fallback"
       "--no-server"
       "--report-unsupported-elements-at-runtime"
       "--native-image-info"
       "--verbose")

ericdallo 2021-01-23T15:08:24.055900Z

Ok, it gave me a lot of exceptions indeed (probably related to the reflection.json I'm not using like clj-kondo uses)

ericdallo 2021-01-23T15:08:40.056100Z

I'll step back and try to make it work without sqlite then try to add it

ericdallo 2021-01-23T15:08:50.056300Z

sorry for the false alarm @borkdude and thanks for the help

borkdude 2021-01-23T15:08:56.056500Z

:thumbsup:

borkdude 2021-01-23T15:09:37.056700Z

For babashka we made this: https://github.com/babashka/pod-babashka-sqlite3 It is a component which runs sqlite in a go binary. Small and fast. And it communicates using JSON back and forth, a bit like a webservice

borkdude 2021-01-23T15:09:54.057100Z

transit actually

borkdude 2021-01-23T15:10:18.057300Z

You could use this to workaround your issues, using the JVM pod library which also works in a GraalVM binary

borkdude 2021-01-23T15:10:37.057500Z

but it's a bit of a workaround ;)

ericdallo 2021-01-23T15:11:04.057700Z

yeah, I see, do you think it'd work well with clojure-lsp ?

borkdude 2021-01-23T15:11:13.057900Z

I think it would.

borkdude 2021-01-23T15:11:22.058100Z

It supports even sending over binary blobs

borkdude 2021-01-23T15:12:44.058300Z

I wouldn't just go and distribute this native approach to production very soon, first run some tests with power users

ericdallo 2021-01-23T15:13:00.058500Z

really nice work on that project haha 👏 I'll try to debug graalvm a little more with some more tests and follow the above post from snoe and if does not work I'll try to use pod-babashka-sqlite3

borkdude 2021-01-23T15:13:07.058700Z

as you might run into issues with macOS users and permissions

ericdallo 2021-01-23T15:13:26.058900Z

yes, this needs to be done carefully indeed

ericdallo 2021-01-23T15:14:19.059100Z

if it works, I could test with coworkers that use MacOS on huge Nubank projects

borkdude 2021-01-23T15:16:56.059300Z

yeah

borkdude 2021-01-23T15:17:39.059500Z

You will need to use this lib as a JVM lib: https://github.com/babashka/pods And then do (load-pod ...) as in the README of the sqlite3 pod

borkdude 2021-01-23T15:18:12.060Z

I guess you aren't using deps.edn right?

ericdallo 2021-01-23T15:18:13.060200Z

@borkdude one more question 😅 those deps:https://github.com/clj-kondo/clj-kondo/blob/master/project.clj#L21-L22 they are for something clj-kondo does specific? do you think we'd need to make graalvm work on clojure-lsp too?

borkdude 2021-01-23T15:19:23.060500Z

I am working on a PR for babashka which uses GraalVM 21 and it doesn't seem to be needed anymore.

borkdude 2021-01-23T15:19:45.060700Z

You will need it with 20.3.0

borkdude 2021-01-23T15:19:50.060900Z

but go with 21 I'd say

ericdallo 2021-01-23T15:19:58.061100Z

nice (I'ḿ using 20.3.0 ATM)

ericdallo 2021-01-23T15:20:56.061300Z

BTW, we are using deps.edn , not sure if it's the correct way to use though, we kind of import it from project.clj

borkdude 2021-01-23T15:21:40.061500Z

oh then it's all fine, I was wondering if I should make a clojars release for the pods lib, but you can use it as a git lib then

ericdallo 2021-01-23T15:22:04.061700Z

Oh got it 👍

snoe 2021-01-23T16:31:12.061900Z

Eh I'd say it's a lein project more than deps.edn. Not sure where equivalents to lein bin and test-refresh are these days.

ericdallo 2021-01-23T21:53:17.062400Z

Well, I managed to make it work with org.xerial/sqlite-jdbc , persisting and selecting from sql from a java Class in clojure

ericdallo 2021-01-23T21:53:34.062600Z

But I'm having issues with graalvm work with next.jdbc

borkdude 2021-01-23T21:55:17.062800Z

@ericdallo I have several working examples of next.jdbc and GraalVM, this was never the issue for me.

borkdude 2021-01-23T21:56:01.063Z

The driver was usually the problem

borkdude 2021-01-23T21:56:13.063200Z

so what error are you getting?

ericdallo 2021-01-23T21:56:59.063400Z

Yeah, I saw that issue where you give some examples 😛 This is the stack: https://pastebin.com/Jsw45Rjr

ericdallo 2021-01-23T21:57:31.063600Z

oh, sorry wrong paste

1
ericdallo 2021-01-23T22:15:00.063900Z

https://pastebin.com/Jn3vj7LE

borkdude 2021-01-23T22:19:15.064100Z

Can you also paste ./scripts/native-compile.sh ?

ericdallo 2021-01-23T22:19:31.064300Z

yes, I'm pushing the code right now 🙂

borkdude 2021-01-23T22:21:01.064500Z

@ericdallo you need to use at least clojure 1.10.2+ (rc3 now)

borkdude 2021-01-23T22:21:10.064700Z

to avoid the infamous locking error

borkdude 2021-01-23T22:21:46.064900Z

CLJ-1472

borkdude 2021-01-23T22:22:00.065100Z

(https://clojure.atlassian.net/browse/CLJ-1472)

ericdallo 2021-01-23T22:24:18.065300Z

Oh, good to know

ericdallo 2021-01-23T22:26:53.065800Z

Basically it uses this class which works: https://github.com/ericdallo/clojure-sample/blob/master/src-java/clojure_sample/SampleDb.java

ericdallo 2021-01-23T22:29:15.066100Z

This does works to me, what means that sql is working, right? So if next.jdbc works, basically our problems are gone, right?

ericdallo 2021-01-23T22:30:05.066300Z

Sorry for the code @borkdude it's a mess, I'm doing a lot of tests

ericdallo 2021-01-23T22:33:33.066500Z

I'm checking your examples with next.jdbc, does https://github.com/babashka/babashka-sql-pods/blob/5d04e7fce699741e1b5e8488cf0a8f70843a3e2e/script/compile#L54 works with graalvm 20.3.0?

borkdude 2021-01-23T22:34:00.066800Z

it does yes

ericdallo 2021-01-23T22:34:48.067Z

Ok, probably your example is using some flag that I missing, I'll try to find what is

borkdude 2021-01-23T22:38:19.067200Z

@ericdallo What error do you get after using 1.10.2-rc3 though?

borkdude 2021-01-23T22:38:25.067400Z

That should be done first

borkdude 2021-01-23T22:38:41.067600Z

After that, there should basically be no problems, when your reflection config has all the things needed

ericdallo 2021-01-23T22:38:48.067800Z

I'm compiling right now with that version 😆

ericdallo 2021-01-23T22:38:59.068Z

Oh my, I really hope 🤞

ericdallo 2021-01-23T22:39:16.068200Z

I spent all day compiling hahahah my notebook need some rest 😛

ericdallo 2021-01-23T22:42:09.068400Z

It worked!

ericdallo 2021-01-23T22:42:41.068600Z

I can't believe it 😄

borkdude 2021-01-23T22:42:59.068800Z

This is big news! Are you using 20.3.0?

ericdallo 2021-01-23T22:43:20.069Z

I'll clean the code and do other push, thank you for the help @borkdude with that it's proved that we can compile graalvm app using sqlite!

ericdallo 2021-01-23T22:44:03.069200Z

Actually I'm using 20.2.0 since it's the latest available for NixOS users

borkdude 2021-01-23T22:44:18.069400Z

Yeah, I think a PR to this repo is in order: https://github.com/babashka/babashka-sql-pods/ We already support postgres, hsqldb and now oracle

borkdude 2021-01-23T22:44:37.069600Z

But I can do that myself too using your config

ericdallo 2021-01-23T22:44:55.069800Z

So the trick was using latest clojure and the custom JNI class

borkdude 2021-01-23T22:45:04.070Z

custom JNI class?

ericdallo 2021-01-23T22:45:43.070200Z

Yeah, without this on classpath the sql wasn't working : https://github.com/ericdallo/clojure-sample/blob/master/src-java/clojure_sample/JNIReflectionClasses.java

ericdallo 2021-01-23T22:46:10.070500Z

I could create a fix jar like you did for clojure-reflector

ericdallo 2021-01-23T22:46:12.070700Z

WDYT?

borkdude 2021-01-23T22:46:54.070900Z

Ah, very interesting, I've never used this before. I wonder if it works on macOS as well. I don't think this class is actually needed once you use the generated reflection json

borkdude 2021-01-23T22:47:12.071100Z

could be wrong though

ericdallo 2021-01-23T22:47:45.071300Z

Hum, the json doesn't include org.sqlite custom reflection classes/methods

ericdallo 2021-01-23T22:47:51.071500Z

but I'll try right now

borkdude 2021-01-23T22:48:10.071700Z

ah it only adds it to the build, but doesn't spit it out to the reflection.json?

borkdude 2021-01-23T22:48:21.071900Z

but you are logging these classes

borkdude 2021-01-23T22:48:28.072100Z

so you could manually add those

ericdallo 2021-01-23T22:48:45.072300Z

Hum, yeah, true indeed

ericdallo 2021-01-23T22:49:25.072500Z

It's a lot of classes, don't you think a external jar with that fix would be better?

borkdude 2021-01-23T22:50:12.072700Z

how do I create the uberjar that your script/native-compile.sh needs?

borkdude 2021-01-23T22:50:41.072900Z

I'm getting:

$ lein with-profiles +native-image "do" clean, uberjar
OpenJDK 64-Bit Server VM warning: forcing TieredStopAtLevel to full optimization because JVMCI is enabled
Could not find artifact rewrite-clj:rewrite-clj:jar:0.6.3-SNAPSHOT in clojars (<https://repo.clojars.org/>)

ericdallo 2021-01-23T22:51:14.073100Z

Oh sorry, this was another test of mine hahaha of another issue, you can change it to use 0.6.1 on deps.edn

borkdude 2021-01-23T22:52:08.073300Z

you are using 1 repo for all your issues? great way to mix problems ;)

borkdude 2021-01-23T22:52:48.073500Z

Fatal error:com.oracle.svm.core.util.VMError$HostedError: Option name "TruffleMultiThreaded" has multiple definitions: com.oracle.svm.truffle.api.SubstrateTruffleOptions.TruffleMultiThreaded and com.oracle.svm.truffle.api.SubstateTruffleOptions.TruffleMultiThreaded

ericdallo 2021-01-23T22:53:22.073700Z

hahaha yeah, I usually don't do that, but today I got things messed 😅

ericdallo 2021-01-23T22:53:48.073900Z

Hum, I didn't have this error :thinking_face:

borkdude 2021-01-23T22:53:59.074100Z

this is probably a conflict between 20.2.0 stuff and 20.3.0 stuff

borkdude 2021-01-23T22:54:14.074300Z

in 21 we don't need all this stuff anymore I think

borkdude 2021-01-23T22:54:20.074500Z

but now it's running

ericdallo 2021-01-23T22:54:24.074700Z

got it

borkdude 2021-01-23T22:54:59.074900Z

so I think when you add all the > Declaring class: org.sqlite.core.NativeDB to the reflection config (with all the methods, etc), then it should also work

ericdallo 2021-01-23T22:55:26.075100Z

Yes!

ericdallo 2021-01-23T22:55:37.075300Z

I'm so glad this works now 😄

borkdude 2021-01-23T22:56:01.075500Z

so where are you now using sqlite, or is this only the java version?

ericdallo 2021-01-23T22:56:02.075700Z

I'll clean up this repo and externalize the JNI class to a fix jar

ericdallo 2021-01-23T22:56:14.075900Z

I'm using in the sqlite ns

ericdallo 2021-01-23T22:56:23.076100Z

clojure-sample.sqlite

borkdude 2021-01-23T22:56:30.076300Z

this is all commented out in my checkout

borkdude 2021-01-23T22:57:11.076500Z

Like I said: I don't think a library/jar is needed for this, you can probably add the classes to the reflection config

borkdude 2021-01-23T22:58:17.076700Z

org.sqlite.core.NativeDB
org.sqlite.Function
org.sqlite.Function.Aggregate
org.sqlite.ProgressHandler
org.sqlite.Function.Window
org.sqlite.core.DB.ProgressObserver

ericdallo 2021-01-23T22:59:41.076900Z

Ok, I'll try then

borkdude 2021-01-23T23:00:26.077100Z

Ah I see, you also need to have some JNI json file:

-H:JNIConfigurationFiles=/path/to/jniconfig
https://www.graalvm.org/reference-manual/native-image/JNI/ I think this was the missing part

borkdude 2021-01-23T23:01:02.077500Z

The difference between your class and a .json file is that your class registers these things at runtime, and a .json file is the declarative way of doing the same

ericdallo 2021-01-23T23:05:22.077700Z

you mean we need both the reflection json file with those classes and this H:JNIConfigurationFiles?

ericdallo 2021-01-23T23:05:36.077900Z

I didn't used this H:JNIConfigurationFiles , why do we need it?

borkdude 2021-01-23T23:06:22.078100Z

Like I said: the configuration file is the declarative way of doing the same you are doing with the Java class now

borkdude 2021-01-23T23:07:01.078400Z

both are probably fine, but that logic is often tied to a specific graalvm version whereas a .json file is not

ericdallo 2021-01-23T23:07:10.078600Z

I see but what is the difference between ReflectionConfigurationFiles and H:JNIConfigurationFiles ?

borkdude 2021-01-23T23:07:16.078800Z

so if you can get it working with .json files, that is much better for the future

ericdallo 2021-01-23T23:08:06.079Z

I'll try to use the json file, I just don't get it If I should add the classes to ReflectionConfigurationFiles or to the H:JNIConfigurationFiles

borkdude 2021-01-23T23:08:06.079200Z

> JNI supports looking up classes by their names, and looking up methods and fields by their names and signatures. This requires keeping the necessary metadata for these lookups around. The native image builder must know beforehand which items will be looked up in case they might not be reachable otherwise and therefore would not be included in the native image. Moreover, the native image builder must generate call wrapper code ahead-of-time for any method that can be called via JNI. Therefore, specifying a concise list of items that need to be accessible via JNI guarantees their availability and allows for a smaller footprint.

borkdude 2021-01-23T23:08:19.079400Z

I think all the methods that use JNI need to be also in the JNI .json file

ericdallo 2021-01-23T23:08:53.079900Z

I see, so I think I'll need to keep working to make it work with json files only 😄

ericdallo 2021-01-23T23:09:08.080100Z

thanks for the huge help explaining those things @borkdude

borkdude 2021-01-23T23:09:18.080300Z

I don't know if these classes need to be in both files, or if jni config implies reflection config, but maybe try both :)

1
borkdude 2021-01-23T23:09:22.080500Z

ok, I'm off now

borkdude 2021-01-23T23:09:24.080700Z

late

ericdallo 2021-01-23T23:09:31.080900Z

good night!

borkdude 2021-01-23T23:09:37.081100Z

thanks