Fork me on GitHub
#lsp
<
2022-04-16
>
andy.fingerhut18:04:30

By any chance is there a "toy example" LSP implementation in Clojure anyone knows about? clojure-lsp is awesome stuff, but if someone has already published the equivalent of a "hello world" LSP implementation in Clojure, that might be useful to look at.

andy.fingerhut19:04:46

Thanks for the pointer

ericdallo19:04:56

Yes, open source I only know kondo one and clojure-lsp itself

ericdallo19:04:11

I recommend reading the spec, it helps a lot understand most of it

borkdude20:04:18

I was also going to say: clj-kondo, since that has only diagnostics, so fairly easy to understand. There is also this one I've been working on for a DSL in .edn: https://github.com/zen-lang/zen-lsp

borkdude20:04:00

And now clojure-lsp has a lsp4clj library you can use to bootstrap your own lsp server, next time I might use that one

šŸ‘ 1
andy.fingerhut19:04:20

OK, I've been trying out this small LSP server: https://github.com/clj-kondo/clj-kondo.lsp

andy.fingerhut19:04:15

On a freshly-installed Ubuntu 20.04 Linux VM, I installed a recent Temurin/Adoptium JDK 1.8, Homebrew, Leiningen, Babbashka, and probably one or two other things I'm forgetting.

andy.fingerhut19:04:45

I cloned that repo, and following advice from borkdude, who graciously updated the README, ran the command bb vscode-server from the root directory of that cloned repo. That created the uberjar and copied it into the vscode-extension directory of my cloned repo.

andy.fingerhut19:04:39

Then following the project README, I did cd vscode-extension and then npm install . There were some warning messages (copied below), but nothing that looked serious, and the result was a subdirectory node_modules created with about 66 MBytes of files in it.

andy.fingerhut19:04:50

Output from npm install I saw looked like this:

npm WARN [email protected] license should be a valid SPDX license expression

audited 79 packages in 1.093s

4 packages are looking for funding
  run `npm fund` for details

found 2 vulnerabilities (1 moderate, 1 critical)
  run `npm audit fix` to fix them, or `npm audit` for details

andy.fingerhut19:04:11

The clj-kondo.lsp README next suggests this: "In VSCode open the project directory and hit F5 (Start Debugging) to run the extension. Edit a Clojure file (`.clj`) and you will get diagnostic feedback."

andy.fingerhut19:04:06

I run code (which I did from my home directory, not my clone of clj-kondo.lsp, if that makes a difference), opened a directory of a small Clojure project I have (again, not clj-kondo.lsp), opened one of its .clj files, and typed the F5 key. VSCode popped up a window with this message: "You don't have an extension for debugging Clojure. Should we find a Clojure extension in the Marketplace?" with buttons "Cancel" and "Find Clojure extension"

andy.fingerhut19:04:41

I am guessing there is a way to install clj-kondo.lsp on my local system without publishing it to the VSCode Marketplace. Does anyone know the steps for that?

andy.fingerhut19:04:25

Sorry, I should probably put all of those steps I've followed into a file that I link to somewhere else, rather than dumping it all in messages here.

borkdude19:04:04

You should open VSCode in the vscode-extension directory

borkdude19:04:16

And then run the project

borkdude19:04:22

That will run the extension in a new window

andy.fingerhut19:04:53

Thanks. Let me try that ...

andy.fingerhut19:04:42

So you mean to, in a bash shell, cd to the vscode-extension directory, then run the command code. By "And then run the project" do you mean to open a folder of some arbitrary Clojure project in VSCode? I tried that with some other Clojure project besides "clj-kondo.lsp", but got same error when pressing F5 as mentioned above.

borkdude20:04:48

Yes, execute code . in the vscode-extension directory

borkdude20:04:58

I'll try it now locally

borkdude20:04:38

With "run the project" I mean, "Start debugging"

borkdude20:04:47

That will open another window in which the extension is active

borkdude20:04:05

And in that new window open a random Clojure file which then will activate the lsp server

andy.fingerhut20:04:23

OK, I did happen across a similar step before on my own where it opened another VSCode window different than the original window, and I had no idea if that was normal or unxpected. Good to know it is what should be happening.

šŸ‘ 1
andy.fingerhut20:04:07

I am happy to write down a more detailed sequence of steps and suggest it in a PR in the clj-kondo.lsp project README, once I think I have a correct sequence of steps.

borkdude20:04:34

In the zen-lsp project, it is set up in a way that you have an nREPL server running in debug mode when you start the extension in debug mode and you can just program directly agains that

andy.fingerhut20:04:44

Part of what I am up against is lack of familiarity with developing extensions for VSCode, as well as learning what LSP is.

borkdude20:04:05

I want to port that to clj-kondo.lsp as well, but the code in clj-kondo.lsp is pretty much "done" so I don't have an urgent need to do so

borkdude20:04:34

@U0CMVHBL2 What is your goal of this exercise?

andy.fingerhut20:04:02

I am considering writing a new LSP server, in Clojure, for a programming language unrelated to Clojure.

andy.fingerhut20:04:26

Trying to walk with existing code to figure out some of the basics, before I run.

borkdude20:04:34

That's what zen-lsp is also doing (although the language is implemented in .edn). But yeah, that should be doable.

borkdude20:04:53

What is the language (out of curiosity)?

borkdude20:04:20

You can test your lsp server from emacs as well btw, just use lsp-mode. I've also documented this in zen-lsp

andy.fingerhut20:04:29

https://p4.org. A niche programming language for programs specifying how network devices like switch ASICs and NICs process data packets.

šŸ‘ 1
borkdude20:04:41

I just find vscode easier since that gives you that new "popup" window where the extension is running without additional setup

andy.fingerhut20:04:12

Yep, one of my reasons for looking at LSP is I also want to be able to use it from Emacs. I'm trying VSCode first partly because I suspect that most of the users of the LSP for the language P4 would prefer VSCode over Emacs.

borkdude20:04:22

The REPL-into-the-server-under-development is recommended when you want to develop such a server, it's such a time-saver

borkdude20:04:14

In clj-kondo.lsp you don't really need to run the uberjar, you could just launch a clojure process which runs the server + a REPL to connect to

andy.fingerhut20:04:29

Oh, I definitely want to do that, so thanks for the tip. One step at a time. I'm not the quickest at this stuff, but once I figure out how to do it, I tend to write down all of the steps for how to do it AGAIN on a freshly installed system, in case I want to start over.

šŸ‘ 1
andy.fingerhut20:04:14

(or want to point someone else at a working sequence of steps, in detail, leaving little to the imagination)

borkdude20:04:40

If you want to improve the docs in clj-kondo.lsp, I'd be happy to receive those improvements

borkdude20:04:09

and/or the REPL stuff too

andy.fingerhut20:04:38

Will definitely consider it, once I get it reproducible for myself šŸ™‚

snoe22:04:19

personally i found vscode the hardest to bootstrap the server because it seemed to require a custom client plugin for each language. emacs and vim allow you to very easily say run this command to start the server for this filetype.

ā˜ļø 1
andy.fingerhut00:04:43

Thanks, good to know. I'll keep an eye out for that and perhaps try out Emacs + LSP sooner than I might have otherwise.

andy.fingerhut00:04:12

Seems weird that VScode would make it trickier than other editors, given that Microsoft started VScode and LSP

Lukas Domagala11:04:04

@U0CMVHBL2 One thing that will help in the future: Iā€™m working on adding websocket support to lsp4clj. A dev benefit would be that you can just start the LSP like any Clojure program and connect your IDE to the LSP, instead of doing it the other way round.