Fork me on GitHub
#calva
<
2021-12-24
>
Chad kennedy00:12:36

Hi all. Using Calva in Windows 10, connected to WSL. I opened the Getting Started REPL. I see "Initializing Clojure language features via clojure-lsp" spinning forever in the status bar. In the Clojure Language Client window I see:

ericdallo01:12:59

hum, that's bad, sounds like clojure-lsp issue on wsl :thinking_face:

Chad kennedy01:12:20

Anything I can do to help diagnose? Post some logs or anything? Is anyone else experiencing a similar issue, or is running in my configuration fairly rare?

ericdallo01:12:45

It doesn't look like a common issue, let try get some logs

Chad kennedy00:12:50

Dec 23, 2021 6:42:01 PM org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer fireError
SEVERE: An error occurred while processing an incoming message.
java.lang.NullPointerException
    at org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.handleRequest(RemoteEndpoint.java:279)
    at org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.consume(RemoteEndpoint.java:190)
    at org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.handleMessage(StreamMessageProducer.java:194)
    at org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.listen(StreamMessageProducer.java:94)
    at org.eclipse.lsp4j.jsonrpc.json.ConcurrentMessageProcessor.run(ConcurrentMessageProcessor.java:113)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
    at java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.lang.Thread.run(Thread.java:829)
    at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:596)
    at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:192)

bringe01:12:35

Pasting the server logs would be more helpful. https://calva.io/clojure-lsp/#opening-the-server-log-file. To make it easier to find the issue, I have in the past opened the log file, deleted the contents, then performed the action that I wanted to see logs for.

bringe01:12:26

CC @UKFSJSM38 (just CC’ing here since it’s a new thread). Let’s keep the convo going in this thread.

👍 1
Chad kennedy01:12:21

When I run Calva Diagnostics: Open Clojure-lsp Log File I get The clojure-lsp server is not running or has not finished intializing.

ericdallo01:12:44

Yeah, that calva command won't work for this case :(

bringe01:12:05

(From main thread) > I can execute the code in hello_repl.clj, and go to definition works, for println at least. Just FYI, Calva uses the repl connect for evaluating code, and also for Go to Definition if a repl connection exists and returns a definition (otherwise it uses clojure-lsp for Go to Definition).

ericdallo01:12:08

Only if you set clojure-lsp config log-path

bringe01:12:01

I think that command only uses info from a running clojure-lsp instance. So if you define your log-path in your clojure-lsp config, you’ll have an easier time finding it manually.

☝️ 1
ericdallo01:12:56

I'm not sure though where the exceptions is happening, there is a chance being thown even before clojure-lsp check config settings

Chad kennedy01:12:04

I set clojure.trace.server to verbose as instructed in the troubleshooting section. Output above.

ericdallo01:12:47

I think it'd be good to test if that happens for a non native clojure-lsp

ericdallo01:12:21

You can download from latest release on clojure-lsp github

ericdallo01:12:35

And set calva to use that downloaded clojure-lsp from a calva setting

Chad kennedy01:12:52

Kk. Thanks for all your help so far!

Chad kennedy01:12:43

I've downloaded clojure-lsp.jar version 2021.12.20-00.36.56 into WSL and chmod 755 for it. When I run java -jar ./clojure-lsp.jar --versionI get

clojure-lsp 2021.12.20-00.36.56
clj-kondo 2021.12.19
I tried setting calva.clojureLspPath to java -jar ./clojure-lsp.jar but that didn't work (`Launching server using command java -jar /home/chad/clojure-lsp.jar failed.`). Then I noticed the text for that setting says "path to the clojure-lsp native binary". Not sure where to specify the use of the non-native java library.

ericdallo01:12:28

@U02RVND2N59 there is the clojure-lsp.bat you can download instead of the jar

Chad kennedy01:12:46

Ok, that runs, in the sense that I don't get Launching server using command ... failed. But I'm still getting the fireError from the beginning of the thread.

ericdallo01:12:39

I suspect the json sent by the client or the json sent by the server is wrong, causing clojure-lsp not parsing correctly

ericdallo01:12:41

@U02RVND2N59 I think I found the issue

🙌 1
ericdallo01:12:08

in the initialize request, the rootURI is null, which is a must for clojure-lsp works properly

ericdallo01:12:21

we need to know why vscode is sending that as null

ericdallo01:12:31

maybe try older calvas to confirm that behavior happens

ericdallo02:12:00

how are you opening vscode? are you opening a folder or a single file?

Chad kennedy02:12:01

I've tried calva versions back to 2.0.199 wwith the same results. I open vs code in Windows, just by clicking the icon in the start menu. From there, I open a new wsl window (in vs code), then run the Calva getting started REPL (also in vs code).

Chad kennedy02:12:18

If I go back to 2.0.177, I start getting different behavior where the REPL doesn't connect automatically. But I do see soemthing different in the Clojure Language Client window. Example:

[Trace - 8:09:58 PM] Sending notification 'workspace/didChangeWatchedFiles'.
Params: {
    "changes": [
        {
            "uri": "vscode-local:/c%3A/Users/Chad/AppData/Roaming/Code/User/globalStorage",
            "type": 2
        },
        {
            "uri": "vscode-userdata:/c%3A/Users/Chad/AppData/Roaming/Code/User/globalStorage",
            "type": 2
        }
    ]
}

Chad kennedy02:12:52

"rootUri": null, still shown at the top of that log though.

ericdallo02:12:06

yeah, doesn't seem related, the issue seems to be the missing rootURI indeed

ericdallo02:12:29

not sure what vscode does to get that, but usually it just pass the opened vscode worksapce proejct path

Chad kennedy02:12:45

Making some progress. So, when you run "Calva: Fire up the "Getting Started" REPL, the rootUri is null. But if I close and re-open that temp folder manually, rootUri is no longer null. Got the idea from here: https://github.com/eclipse/xtext-core/issues/57

ericdallo02:12:28

that's odd, AFAIK the repl should not be related with that rootURI param, any thoughts @U9A1RLFNV?

Chad kennedy02:12:52

When I manually open the temp folder created when I ran "Calva: Fire up the "Getting Started" REPL, the REPL is not connected, and I don't know how to make it connect. This could just be a beginner issue. Still learning the tool obviously.

Chad kennedy02:12:51

But, Clojure Language Client window shows a non-null rootURI and appears to be working.

ericdallo02:12:11

Good, so that was the issue indeed

ericdallo02:12:23

we just need to know why that uri is being passed as null

ericdallo02:12:32

also, we could at least improve clojure-lsp to not fail like that when rootURI is null and give a proper warning

Chad kennedy02:12:18

Ok. If, after opening the temp folder, I run "Calva: Fire up the "Getting Started" REPL again, but tell it to use the existing temp folder, the I have a working REPL and a working lsp server. From the issue 57 link above, it looks like this (rootUri being null) is because vscode wasn't opened to a particular folder. Could the command "Calva: Fire up the "Getting Started" REPL be updated to create the temp folder and files, and then open the folder, instead of opening the individual files? That might fix it.

Chad kennedy02:12:19

(Sorry I don't know enough Clojure yet to try out that fix myself. Hopefully soon!)

ericdallo02:12:44

I think you did a good debugging! @U0ETXRFEW and @U9A1RLFNV will probably know better about that

Chad kennedy02:12:03

BTW, I just wanna say how impressed I am by the level and responsiveness of support I've received here. I've been part of many different open source platforms and projects, and never seen anything this amazing. You guys are awesome!!!! I know it must be a lot of work, but it sure does make it an attractive platform to use!

gratitude 2
💜 2
pez07:12:46

We can't open a folder, only files. But we do know the folder uri. Maybe there is a way to give that to the lsp server when starting it?

👍 1
bringe19:12:21

@U02RVND2N59 Would you mind creating an issue describing the problem so we can track it? Stating the steps you took above that led to the issue would be great. It would be appreciated. We may be able to fix it by manually passing the root URI.

bringe19:12:47

Thanks for your responsiveness as well and your debugging efforts!

Chad kennedy00:12:50

I can execute the code in hello_repl.clj, and go to definition works, for println at least.

Stuart17:12:44

Is it possible to setup templates for a project in calva, so if I create a new .clj file it will give me my template. e.g., I can setup a template like

(ns stuartstein777.rosalind.rna-to-protein
  (:require [clojure.string :as str]
            [clojure.set :as set))

bringe19:12:53

I don’t believe so, but you may be able to do this with snippets. There may be extensions to help create and use snippets as well.

Stuart19:12:27

oh, i never thought of snippets. That's a good idea! Thanks

👍 1
bringe19:12:33

Although, I think you’d still have to create the file, then use a snippet within the file. I’m not sure if the file can be created with a snippet already in it.

Stuart19:12:57

yeah, i can at least create a snippet for this project WIth the same (:require) form

👍 1
bringe19:12:11

You could also write a babashka script to create files from a template babashka

agold18:12:26

I have the following namespace def:

(ns agold.cljip
  (:require [clojure.string :as str])
  (:gen-class))
But when I evaluate (str/lower-case "FOO") in Calva's repl, I get:
; Syntax error compiling at (src/agold/cljip.clj:19:3).
; No such namespace: str
But if I start a repl with clj, I can evaluate this form with no error. How do I troubleshoot this? Can I see the classpath Calva is using?

pez19:12:14

Have you loaded the file first?

bringe19:12:11

What steps do you take to start the repl when it doesn’t work?

agold19:12:28

Sorry, I misled you. Actual ns is:

(ns agold.cljip
  (:require [config.core :as e]
            [clojure.string :as str])
  (:gen-class))
deps.edn containss:
:deps {org.clojure/clojure {:mvn/version "1.10.3"}
        yogthos/config {:mvn/version "1.1.9"}}
On loading and evaluating file, I get:
; Evaluating file: cljip.clj
; Syntax error (FileNotFoundException) compiling at (src/agold/cljip.clj:1:1).
; Could not locate config/core__init.class, config/core.clj or config/core.cljc on classpath.
; Evaluation of file cljip.clj failed: class clojure.lang.Compiler$CompilerException
But config-1.1.9.jar is in my .m2 repository. repl is started in Calva with deps.edn and build selected. Here is the relevant clause from deps.edn:
:build {:replace-deps {io.github.seancorfield/build-clj
                 {:git/tag "v0.6.3" :git/sha "9b8e09b"
                  ;; since we're building an app uberjar, we do not
                  ;; need deps-deploy for  deployment:
                  :deps/root "slim"}}

agold19:12:45

The deps.edn file was created by Sean Corfield's "new" tool. I have always used lein until now. This is my first project with deps.edn, so maybe I'm not understanding something about loading dependencies.

bringe20:12:39

Can you share the command and args used to create the project? I can try the same/similar project and see if I can reproduce.

agold20:12:33

Here's deps.edn:

:build {:replace-deps {io.github.seancorfield/build-clj
                 {:git/tag "v0.6.3" :git/sha "9b8e09b"
                  ;; since we're building an app uberjar, we do not
                  ;; need deps-deploy for  deployment:
                  :deps/root "slim"}}
And here's the source file cljip:
(ns agold.cljip
  (:require [config.core :as e]
            [clojure.string :as str])
  (:gen-class))

(defn greet
  "Callable entry point to the application."
  [data]
  (println "conf key is: " (:API-KEY (e/load-env)))
  (println "foo is" (str/lower-case "Foo"))
  (println (str "Hello, " (or (:name data) "World") "!")))

(defn -main
  "I don't do a whole lot ... yet."
  [& args]
  (greet {:name (first args)}))

(comment
  (greet nil)
  (str/lower-case "FOO")
  #_(config.core/load-env)
  #_(e/load-env)
  )
Created using clj -Tnew app :name agold/cljip yogthos/config 1.1.9 subsequently added to deps edn.

agold20:12:17

Thanks, and Merry Christmas! I'll be out for a while, but all help is much appreciated.

bringe20:12:39

Merry Christmas to you too! 🎄

bringe20:12:00

I cannot reproduce the issue. :thinking_face:

bringe20:12:46

I created the project with clj -Tclj-new app :name agold/cljip, and added yogthos/config to the deps.

bringe20:12:34

And copied the same file contents from above and the file loads successfully. When I run (greet nil):

conf key is:  nil
foo is foo
Hello, World!
nil

bringe20:12:49

My deps.edn:

{:paths ["src" "resources"]
 :deps {org.clojure/clojure {:mvn/version "1.10.3"}
        yogthos/config {:mvn/version "1.1.9"}}
 :aliases
 {:run-m {:main-opts ["-m" "agold.cljip"]}
  :run-x {:ns-default agold.cljip
          :exec-fn greet
          :exec-args {:name "Clojure"}}
  :build {:deps {io.github.seancorfield/build-clj
                 {:git/tag "v0.6.3" :git/sha "9b8e09b"
                  ;; since we're building an app uberjar, we do not
                  ;; need deps-deploy for  deployment:
                  :deps/root "slim"}}
          :ns-default build}
  :test {:extra-paths ["test"]
         :extra-deps {org.clojure/test.check {:mvn/version "1.1.1"}
                      io.github.cognitect-labs/test-runner
                      {:git/tag "v0.5.0" :git/sha "48c3c67"}}}}}

bringe20:12:07

@U0ETXRFEW Any idea what could be going wrong for @U2CR1J4UV?

bringe20:12:00

Oh, to add more details, I used Calva’s jack-in command to start the repl, and did not select an alias.

agold20:12:39

Does that mean that after selecting deps.edn in the jack-in menu, you did not check either build or test?

bringe20:12:33

Ah, when I select both build and test, I can reproduce…

agold20:12:52

Yes, I just tried here, and it works if I deselect those. I thought I had to choose one. Thanks!

bringe20:12:12

If I just select test, there’s no issue as well.

bringe20:12:50

No problem! I don’t know much about build-clj , but it looks like the :build alias is meant for building an uberjar, so when starting a repl for general development, I don’t think you need to select that alias. I’m not sure why it causes that issue though.

agold20:12:36

Thanks again for the enlightenment. I need to understand the build-clj tool better, but at least I can drink my eggnog tonight without this problem nagging at me!

😄 1
👍 1
bringe20:12:29

@U0ETXRFEW Do you know why that alias causes that issue? Maybe it’s something with :ns-default : https://clojure.org/reference/deps_and_cli#_tool_usage.

agold20:12:21

You guys are amazing! Best support ever! Many, many thanks.

❤️ 1