Fork me on GitHub
#calva
<
2023-02-18
>
lspector03:02:19

Having some issues with Calva and leiningen projects. I've been using/teaching it only with deps.edn projects, but a student reported some odd REPL behavior in a leiningen project, and trying to replicate it I couldn't even get as far as jacking in. Created a project with lein new app leinproj, then opened it in Calva and got:

LSP classpath lookup failed when running `lein with-profile +test,+dev classpath`. Some features may not work properly if ignored. Error: Cannot run program "lein" (in directory "/Users/leespector/Amherst/Courses/COSC452S23/leinproj"): error=2, No such file or directory Choose an option:
Trying to jack in, and selecting Leiningen, I get:
/bin/sh: lein: command not found
Jack-in process exited. Status: 127
lein new app leinproj works, so clearly lein can be found from my terminal, but not by Calva?

pez08:02:43

See if it works if you start VS Code from the command line. code.

lspector14:02:14

That worked! More specifically, I had to make the command available by launching VSCode in the usual way, then following the instructions at https://code.visualstudio.com/docs/setup/mac to get it on my PATH, then close the VSCode window for the leiningen project, quit VSCode, relaunch it via the command line in a new Terminal window, open a new window and "open folder" in it with the leiningen project, then jack in (selecting Leiningen, and then "OK" without selecting anything in the dialog asking about profiles to load)... and then it worked! It didn't work the first time I tried, and I think the step I added that made the difference was first closing and then after the re-launch reopening the leiningen project.

pez14:02:26

Yes, it needs to be a new main process. You can give a folder as an argument to the command to open it directly. Saving some steps.

pez14:02:06

I didn’t know if you had installed the command line tool, but figured you would figure it out. 😀

lspector14:02:52

I hadn't, but I did, and I'm describing it to students now, though of course it would be great if this worked when VSCode was launched in the normal (non-command line) way...

pez14:02:34

It’s good to have there. You can quickly open files in the right VS Code window from the integrated terminal. Like log files or whatever.

lspector14:02:35

If I understand all of this correctly Calva can't deal with leiningen projects unless it is launched from the command line. Is that true? If so, is it something that might be fixed?

pez15:02:06

It’s not really within our reach to fix this. Not specific to Leiningen or vscode. If the environment that a program runs in does not have a command on the path, all bets are off. Compare with this old question https://stackoverflow.com/questions/52428657/command-line-tools-not-accessible-from-eclipse-on-osx

pez15:02:23

You can probably fix this by analyzing how the shell environment is set up on your machine, and what the terminal does that other programs don’t.

lspector15:02:13

I'm pretty confused by this! In particular, I don't understand why this is an issue for leiningen projects but not deps.edn projects. In any case, I think I just discovered something useful: Now that I've installed the shell command, it seems that I can launch VSCode in the normal way (from the GUI, not the command line), and the leiningen project still seems to open correctly, and jacking in works fine. Does it make sense to you that this works? If so, can I just add a line to my setup instructions telling students to do the shell command thing in VSCode, and then, even if they never actually launch VSCode from the terminal, it should work okay, even for leiningen projects?

pez15:02:31

The reasons it worked with deps projects are two, afaik: 1. The clojure executable was on whatever PATH that VS Code was launched in 2. Calva bundles deps.clj which is a sort of a drop in replacement for clojure, in order to cut down on requirements for first time users. Only Java is needed.

pez15:02:09

I don't know if installing the code command line tool also fixes the PATH issue for the GUI launch of VS Code. Might be why it works on my machine... ¯\(ツ)

lspector15:02:04

Oh... so maybe some of the things that I'm thinking will work for students actually won't if they haven't installed the CLI tools and/or Leiningen at their command lines? That would be too bad. I can't really test it without uninstalling stuff... But is your guess that for someone to use a leiningen project in Calva they have to do both 1) install leiningen at your command line, and 2) do the shell command thing in VSCode?

pez15:02:34

If there is no particular reason for it being a Leiningen project, you could make it a deps project and that should cut the error surface down to Windows machines running old Oracle Java installs.

lspector15:02:28

Yeah, I'm trying to teach the class entirely with deps rather than leiningen, but a student was having trouble pulling in libraries with deps, because the library readmes only showed how to use them in leiningen, and we went down a rabbit hole trying to figure out how to do them in deps instead. There are some docs on this, but we couldn't get it to work. I suggested to make a leiningen project instead, which would solve the library problem, but I didn't understand that this would keep them from being able to use Calva. Not yet clear to me if they can fix that by doing the shell command command in VSCode and/or installing leiningen.

pez17:02:22

As long as they can run lein from the command line, they can start VS Code from that command line and it will work.

pez17:02:47

What I don't know is if you can rely on that it fixes the problem with VS Code started from Finder.

pez17:02:56

Do you remember the problem with the library? Maybe we can figure that out together so that you know how to solve it with deps.edn.

lspector17:02:47

Cool. So one piece of this (lmk if I've got it wrong) is that Calva can only work with a leiningen project if you have leiningen installed at the command line. Even if you do, you might have to run the shell command command in VSCode, and possibly (still TBD) launch VSCode from the command line.

pez17:02:55

Yes. Maybe I don't understand "Calva can only work with a leiningen project if you have leiningen installed at the command line". Leiningen won't work if it is not installed. It's not really a Calva thing.

lspector17:02:52

I guess it wasn't obvious to me that one would need the actual leiningen code in order to open and run a REPL for a project if its dependencies are listed in project.clj rather than deps.edn. Now I think I understand that in this case Calva actually runs leiningen in order to read and pull in the dependencies. And it's not bundled, so it has to be installed. I'm thankful that this isn't necessary for deps.edn projects, and agree that I should probably concentrate on getting deps.edn dependencies to work correctly. I don't remember the specific library that was tripping us up, but I'll look into it and maybe take you up on helping with that if we can't get it working.

👍 2
skylize05:02:15

To reiterate something @U0ETXRFEW said earlier, with more detail: Calva includes deps.clj, which can emulate the Clojure CLI Tools shell command (`clojure`/`clj`) without actually calling out to the shell. <Not accurate: still calls out to the shell for deps.clj, but doesn't need anything from environment to know that path with certainty.> That means we have a fallback mechanism for deps.edn projects if Calva fails to locate Clojure CLI Tools from the environment. (As such being able to work with a deps.edn project does not guarantee that the CLI Tools are actually set up correctly. You might be using deps.clj instead and not realize it.) Lein is it's own separate application. If the environment does not provide a path to Leiningen, there is no fallback.

👍 2
skylize23:02:12

Correction added to my post above, for accuracy. But don't let such minutiae distract you from the main point. 😎

👍 2