Fork me on GitHub
#lsp
<
2023-10-04
>
bzmariano03:10:29

Hello, I'm encountering an error when opening a project in Neovim. This error message reads as follows: "lps[clojure_lsp] Classpath lookup failed when running 'clojure -A:test:dev -$path'. " What's strange is that this error started occurring yesterday in a project I'm working on, but not in others. Additionally, to test it out, I downloaded some Clojure projects from GitHub, such as the reitit examples, and this error also appears when exploring them. This leads me to believe that the problem is not in the deps.edn of my current project nor in Neovim. Has anyone else experienced the same problem or understands what the error message might be referring to? Thanks in advance !

ericdallo12:10:30

Does running in your project clojure -A:test:dev -Spath works?

bzmariano16:10:52

yes, it does

ericdallo16:10:52

so seems like the PATH your neovim is using is not the same that your terminal uses, that's why neovim spawns clojure-lsp project with a PATH that doesn't contain clojure , I saw those issues with brew packages

ericdallo16:10:07

and already saw that issue with emacs and intellij

bzmariano03:10:56

I tried with Calva on vscode and it shows me the same error. "LSP classpath lookup failed when running clojure -A:test:dev -Spath. Some features may not work properly if ignored. Error: Cannot run program "clojure" (in directory "/home/user/code/clojure/web-app"): error=2, No such file or directory. Choose an option: <blank>"

ericdallo12:10:43

the issue is the PATH being used by your editors, which probably doesn't have clojure in there

ericdallo12:10:23

try to spawn vscode or vim from the same terminal you have clojure working, you will see that probably will work

bzmariano17:10:14

I solved it manually installing clojure_lsp on /usr/lib/bin, I still dont get why all of a sudden it started to failed without me changing any system config. but it works for now. Thanks for your help Eric !

šŸ‘ 1
bzmariano17:10:40

False alarm šŸ˜… In a new terminal, the problem persists.

bzmariano19:10:41

Ok, apparently I had a skill issue with Linux šŸ˜…. I had the java and clojure paths enclosed in " ". After removing those quotes, everything started working correctly. My bad.

Matthew Twomey15:10:52

Is it possible to force lsp to engage clj-kondo on a babashka script when there is no accompanying bb.edn file adjacent to that script? I am now using babashka scripts wholesale, everywhere I would have previously used a bash script. This works great, but I donā€™t want to keep putting empty bb.edn files everywhere on my system. Right now it appears that this is necessary or I donā€™t get completions.

āž• 1
ericdallo15:10:24

yes, you can start LSP without a valid classpath but that will highly affect most features including completion which would work only for current ns or opened ns in the editor

ericdallo15:10:52

without a classpath we don't know your project source-paths and dependencies so we only know/analyze what you opened

ericdallo15:10:10

so, probably not worth it to try to use LSP that way

ericdallo15:10:01

it's just easier to setup the bb.edn file or specify in .lsp/config.edn a :project-specs teaching how to get that classpath

Ellis15:10:03

I just keep them all in one directory with a blank bb.edn in

Matthew Twomey15:10:33

Ok, so I donā€™t think I need anything here related to the classpath? Sorry if Iā€™m misunderstanding. These are standalone babashka scripts and completions work fine as long as I have a bb.end file containing an empty map. This leads me to believe that there is nothing really gained from having that bb.edn file, or am I misunderstanding? What Iā€™d love to do is be able to get lsp to ā€œdo itā€™s thingā€ without that empty bb.edn file

ericdallo15:10:46

when you say completion, you mean completion for that file vars or completion of vars from other ns?

Matthew Twomey15:10:07

As an example:

(require '[clojure.string :as str]
         '[babashka.fs :as fs]
         '[babashka.process :refer [shell]])

Matthew Twomey15:10:26

With an empty bb.edn file, completions for fs or str work fine.

Matthew Twomey15:10:34

Without an empty bb.edn file, they do not.

Ellis15:10:05

AFAIU, there's no way to it to be discerned that's bb vs just some library called "babashka" that exists on the classpath So when it sees the marker, clojure-lsp knows "ah, this is babashka, okay I can find these deps"

ericdallo15:10:09

yep, how clojure-lsp will know about babashka.process and other ns if that code is not available for clojure-lsp?

Matthew Twomey15:10:52

So right now itā€™s checking for the existence of a bb.edn file and then it knows?

ericdallo15:10:15

almost, it runs a command when find a bb.edn

ericdallo15:10:05

bb --print-deps --format classpath

Matthew Twomey15:10:08

I mean emacs engages clojure-mode when I open the file.

ericdallo15:10:18

but we only do that when we find a bb.edn file

ericdallo15:10:51

clojure-mode don't need information about babashka and analysis since clojure-mode is way easier than clojure-lsp , it only needs context about the current opened file not a whole project analysis

āœ… 1
Matthew Twomey15:10:29

Yes, but wondering if lsp can see that weā€™re in clojure-mode and use that as an indicator? Sorry - Iā€™m out of my depth a bit here on how this all works.

ericdallo15:10:07

nope, clojure-mode it's a client thing (emacs), it only says: "Oh we need to start lsp", it starts LSP, but then clojure-lsp needs to know about the project

Ellis15:10:22

Same issues raised "there's no way to it to be discerned that's bb vs just some library called "babashka" that exists on the classpath" It's clojure sure, but are you writing regular clojure against a library called babashka or is it a babashka script? How can we ever know?

Ellis15:10:08

There's no way from a simple require form to guess what dialect you're using šŸ˜„

Matthew Twomey15:10:20

ok, I see. Do you know if there is elisp that can ā€œforce it onā€? If thatā€™s the case, I can code around it.

Ellis15:10:22

(feel free to correct me eric)

borkdude15:10:43

.bb is an indication that it's a bb script

ericdallo15:10:51

one possible improvement that would need more thinking is: try to spawn all classpath commands like bb print-deps and consider the classpath if the command returns ok, but I think bb 100% returns a classpath, and we would consider bb classpath even for non bb projects, besides other corner cases

ericdallo15:10:30

@U0250GGJGAE it's not a emacs problem, it's something on server side, clojure-lsp

Ellis15:10:56

@UKFSJSM38 checking for a bb shebang might help too

šŸ‘ 1
ericdallo15:10:34

let me explain how that works:

Matthew Twomey15:10:56

Ok I see. Iā€™m just moving towards using babashka scripts as drop-in replacements where I would have had sh scripts. This is been pretty awesome overall. Getting past this would just be one more improvement. I understand that itā€™s possibly not super straight-forward (I donā€™t mean to be over-simplifying).

ericdallo15:10:15

client: open a clojure related file (.clj, .bb etc), then the client knows it should spawn clojure-lsp server passing the project-root. server: during initialization, checks project-root for known deps files like bb.edn, and spawns the related classpath command bb print-deps --format classpath , then returns to client that server initialized client: then sends the opened files as textDocument/didOpen requests to server.

Matthew Twomey15:10:45

Oooh, thatā€™s helpful

ericdallo15:10:06

so server doesn't know about open files until initialized, server could try to infer grepping the whole project root for .bb files or so, but that sounds kind of error prone and may have other corner cases

borkdude15:10:38

clj-kondo does work on any .clj file, no matter if it's in a project šŸ¤·

borkdude15:10:47

if you use it separately from lsp that is

ericdallo15:10:55

clj-kondo doesn't known project

borkdude15:10:14

kinda, it keeps information around from any visited .clj file in the project in the .clj-kondo folder

borkdude15:10:31

and many things aren't a project at all :P

ericdallo15:10:54

if you open a single file with clj-kondo it won't mention all other project errors besides other linters like unknwon-var because didn't lint the var-definition

ericdallo15:10:22

anyway, I do see value on that feature request

ericdallo15:10:27

but not sure how about the solution yet

ericdallo15:10:36

we can start with a issue maybe

borkdude15:10:39

this was one of my major complains when I moved my local clj-kondo install to lsp ;)

borkdude15:10:58

this and the speed of feedback, which was solved. but this one still exists.

ericdallo15:10:24

yes, this is something I try to prioritize, LSP should work similar to an IDE, so work out of the box without extra config

Matthew Twomey15:10:33

> we can start with a issue maybe I am happy to start an issue to track the discussion? In the clojure-lsp repo?

Ellis15:10:55

Mm, the single file vs project issue has been plagued many LSP servers šŸ˜„

Ellis15:10:04

Hard to nail it perfectly

Matthew Twomey15:10:26

ok, will do and thanks for listening. This is all pretty awesome, I really appreciate all the work and support everyone is putting into these tools!

ā¤ļø 1
Matthew Twomey15:10:14

Thank you all ā¤ļø