Fork me on GitHub
#lsp
<
2024-05-16
>
neilyio18:05:06

I'm trying to get clojure-lsp working with https://helix-editor.com and Babashka. I've created an empty file ~/Desktop/bb.clj, and Helix starts up clojure-lsp as soon as I navigate to the file. But I'm finding that the language server crashes immediately. I'm hoping to use the language server directly on a bb.clj script, with no project or bb.edn or anything. I thought that was appropriate use of Babashka. Sorry if I'm doing something obviously wrong, this is my first foray back into Clojure in a couple years and I've forgotten everything. Here are the clojure-lsp logs. It seems like some kind of uri is missing, but I'm not sure what it's supposed to be.

2024-05-16T17:10:34.261Z  INFO [clojure-lsp.server:627] - [SERVER] Starting server...
2024-05-16T17:10:34.308Z  DEBUG [clojure-lsp.nrepl:21] - nrepl not found, skipping nrepl server start...
2024-05-16T17:10:34.321Z  INFO [clojure-lsp.server:509] - Initializing...
2024-05-16T17:10:34.328Z  ERROR [clojure-lsp.server:55] - Error receiving message: Internal error (-32603)
{:id 0, :method "initialize"}
com.oracle.svm.core.posix.thread.PosixPlatformThreads.pthreadStartRoutine  PosixPlatformThreads.java:  211
            com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine       PlatformThreads.java:  833
                                                     java.lang.Thread.run                Thread.java: 1583
                                                 java.lang.Thread.runWith                Thread.java: 1596
                       java.util.concurrent.ThreadPoolExecutor$Worker.run    ThreadPoolExecutor.java:  642
                        java.util.concurrent.ThreadPoolExecutor.runWorker    ThreadPoolExecutor.java: 1144
                                                                      ...                                 
                                        clojure.core.async/thread-call/fn                  async.clj:  486
                                            lsp4clj.server/thread-loop/fn                 server.clj:  122
                                             lsp4clj.server.ChanServer/fn                 server.clj:  260
                                lsp4clj.server.ChanServer/receive-request                 server.clj:  365
                                  lsp4clj.server/pending-received-request                 server.clj:  181
                                                                      ...                                 
                                                    clojure-lsp.server/fn                 server.clj:  520
                             clojure-lsp.shared/normalize-uri-from-client                 shared.clj:  546
                                              clojure.string/starts-with?                 string.clj:  365
java.lang.NullPointerException: 

borkdude18:05:52

it seems clojure-lsp expects a uri field in the JSON that is possibly missing

neilyio19:05:18

I got this working. The issue was that I did not have a git repository initialized. clojure-lsp is looking for rootUri (`:root-uri` in codebase) to be sent along with the initialization. Helix does not send rootUri if you're not in a git repo. It would be great for there to be more help for the user here... I'm pretty used to language servers "just working" in Helix. It's possible this problem is on the Helix side (maybe Helix should know to send a "dummy" root path to clojure-lsp?). But I think think there's also an argument that clojure-lsp should handle this gracefully. If Babashka is supported, opening a .clj without a git repo is probably pretty common.

Chase19:05:43

I'm off topic here but I'm curious what are you going to use for structural editing (paredit, parinfer) and repl driven development (eval'ing expressions from the editor to a running repl) with Helix or are you just opting to go without? I was under the impression there are currently no solutions for such things at the moment

ericdallo19:05:02

> . Helix does not send rootUri if you're not in a git repo. That sounds like something to be fixed on Helix

ericdallo19:05:29

clojure-lsp totally depends on project root which this is the only flag that tells it

ericdallo19:05:39

Checking the spec this is indeed a optional field, we could make clojure-lsp ignore it and work as a "dummy" mode

ericdallo19:05:18

I'm interested on Helix as well, but AFAIK it still doesn't support plugins, waiting for that support to give it a try

neilyio19:05:12

@UKFSJSM38 thanks for the reply. It could be a tough sell to get Helix to change their behavior with clojure-lsp, I think they are pretty homogenous with their interaction with language servers. I agree having clojure-lsp pick "something" to use in place of an empty rootUri (and maybe a warning for the user) would be very helpful here. Especially as Babashka encourages people to write one-off scripts.

neilyio19:05:33

@U9J50BY4C Great question. As for REPL eval, I've found a hacky but surprisingly pleasant workaround using tmux. Here's the entry in my config.toml:

[]
# REPL hack from: 
e = [''':pipe-to tmux load-buffer - \; paste-buffer -dpr -t '{right-of}' \; send-keys -t '{right-of}' Enter''']
This gives tmux the selected text I have in my Helix editor, and tells it to paste it in the adjacent tmux window (and press Enter). Yes, the text has to be selected in Helix, but Helix natively has many tree-sitter-based structural movement/selection commands, so selecting my defn block or whatever is pretty easy. So I'm "kind of" opting to go without. It's obviously not the experience I had when I used Emacs, but I'm happy enough for now, and will adopt any improvements that eventually come with Helix's plugin system.

ericdallo19:05:30

Yeah, checking the spec it's expected to the server to handle a missing rootUri, I think clojure-lsp should handle it null and act as dummy but not crash, please create a issue for that

Lyn Headley18:05:56

Having trouble downloading clojure-lsp for my new mac M2. I downloaded the latest "macos-aarch64" binary (don't see what I expected, which is macos-arm64) and tried to run it, but mac os won't allow me because it is unable to scan it for malicious software. Any ideas?

dawdler18:05:17

I think you can «un-quarantine» it: xattr -d com.apple.quarantine That said, I have not experienced any problem with lsp binaries on MacOS, silicon or otherwise.

borkdude18:05:45

Try downloading it from the terminal with curl and unzip it also in the terminal. Do not open it with a browser or finder and you will bypass all of this stuff

👍 1
Lyn Headley18:05:25

Thank you both!

practicalli-johnny06:05:54

Or if already using Homebrew

brew install clojure-lsp/brew/clojure-lsp-native

Lyn Headley18:05:32

Emacs is not able to find my downloaded clojure-lsp executable. Do I need to put it in a particular place?

Samuel Ludwig18:05:00

for a sanity-check, I'm assuming which clojure-lsp outputs what you'd expect?

Lyn Headley18:05:24

hmm good point (new machine). thank you!

Samuel Ludwig19:05:17

new fancy mac- im sure theres some wizardry going on 😄

practicalli-johnny06:05:31

If using lsp-mode then Emacs will prompt to download the relevant LSP server for you, so a manual install is not required. https://emacs-lsp.github.io/lsp-mode/ If installing clojure-lsp manually, it should be on the execution path that Emacs is aware of (e.g. /user/local/bin or .local/bin (depending on your shell PATH config) There is also lots of information at https://clojure-lsp.io/

Lyn Headley00:05:43

Emacs tries to automatically download but it never completes and reports nothing