Fork me on GitHub
#calva
<
2023-01-17
>
lspector16:01:42

In case anyone might find it useful and/or have suggestions for improvement, I've just posted some Calva-based Clojure quickstart instructions, mostly for the sake of a class I'm teaching, at https://discourse.pushlanguage.org/t/clojure-quickstart-instructions/2169. This is aimed at undergrads who've taken just a few computer science courses, have never seen a Lisp, and may not have done much at a command line. Some of my students will have a lot more experience, but I want these instructions to work for everyone. One of my goals was to require as little installation as possible, so this requires just Java, VSCode, and Calva. That makes project creation a bit cumbersome, but I really do want to minimize installations, and maybe it's instructive anyway. I might provide the class with a project template too, with instructions about what has to be changed.

❤️ 4
🙏 2
calva 2
lspector17:01:09

BTW this isn't for a software development course, which is why I'm not expecting that students will know or be focused on learning much about more sophisticated setups or systems issues. This is for a course on Evolutionary Computation that focuses mostly on ideas from AI, machine learning, and evolutionary biology. Students will write and experiment with code for evolutionary algorithms in Clojure, and my goal is to get all of them set up for doing that as quickly and effortlessly as possible, even if they don't have a lot of software development experience or necessarily want to become professional developers.

pez17:01:11

I will steal a lot of stuff from this resource, @U06BV1HCH 😃 Love it. For the project creation: If people use VS Code for that, then no hidden extensions will be added. If you use something else, opening the project in VS Code is a good way to check if the extensions are right (since that might be tricky to figure out for someone who needs the instructions to watch out for it). Also, for the instructions, it could be nice to show what the project should look like when done. Something like:

.
├── deps.edn
└── src
    └── hello.clj
(I should fix so that Calva can help create a minimal project. And remember to use multi-segment structure then.) Super nice Calva instructions! It's great for me to read a fresh take on it. For the structural editing part you could mention that if you leave strict mode on, alt+backspace/delete will force-delete when the strict mode prevents it. For Learning Materials you could mention that the Getting Started REPL in Calva also has an intro to Clojure.

lspector18:01:22

Thanks for the great feedback @U0ETXRFEW! I will definitely incorporate a lot of your suggestions. On using VSCode itself for "manual" project construction, would one have to build the folders and files, then close the project folder, and then re-open it for it to be recognized as a deps.edn project? Of course it would fabulous if there was a Calva command that would take a project name and produce the full (minimal) project structure!

pez20:01:56

In your Clojure resources post you are recommending the command: > Calva: Send current expression (or selection) to REPL window and evaluate it I think it is a better workflow to use Calva: Evaluate Current Form (or selection, if any).

pez20:01:02

Which reminds me about this in the Quickstart instructions: > To evaluate an expression in the editor pane: With the cursor in or just after the expression, hold down Option (or Alt) key and hit return (or enter). Results will appear inline in the editor (but they’re not really in the file!) and also in the REPL pane. alt+enter will evaluate the current top level form, not the current form. Someone starting out and learning just one evaluation command should probably learn to evaluate the current form, since you can use it to evaluate top level forms too. So Ctrl + Enter, instead there, I think.

lspector22:01:27

Thanks for spotting that inconsistency with my Clojure resources page. But I'm actually going to keep the suggestion to use alt+enter in the Quickstart, and also use that on the resources page, because I think that evaluating the top-level form is what students will want and expect. Plus, evaluating non-top-level expressions that use symbols bound in surrounding code break (which makes sense, but it's not pretty). Worst, even when it works "correctly" the results appear inline in the middle of the surrounding expression which I find really disconcerting and I'm pretty confident this will be a source of confusion. I'd actually prefer no results to appear in the editor pane ever -- I think it's odd and confusing since they're "there but not really," and anyway the results are perfectly visible in the REPL window where they belong -- but at least when they're at the end of the expression, it's not too confusing.

pez22:01:50

It's your prerogative, but at least in the intro you describe evaluate current form, but give the shortcut to evaluate top level form. This might lead to confusion.

lspector22:01:56

Thanks! I think I've now made them both consistent, saying how to evaluate the top level form by using option/Alt+return/enter.

lspector22:01:09

Just answered my own question about creating the project "manually" but from within Calva. You don't have to close and re-open the folder. When jacking in it asks about the project type, and as long as there's a deps.edn containing at least {} at that point, it works! 😀 I'm going to mull whether to replace the OS/text-editor instructions with instructions for doing it within Calva

lspector23:01:41

(For now I'm including both options.)

lspector23:01:25

Just made a bunch of updates based on your super helpful suggestions. Thanks!!! The only one I think I didn't take was about deleting in strict mode, which I expect my students to mostly avoid.

pez07:01:38

> about creating the project "manually" but from within Calva. You don't have to close and re-open the folder. Oh, yes, forgot to answer that one. Glad you just tried it. 😃

pez08:01:42

Now I tried it myself and notice that I get an error message from clojure-lsp... Until we have fixed that, I don't think it is a good idea to tell beginners to create the project like this. But anyway, in the screen recording you can also see that it is easy to create files with non-existing parent folders with VS Code.

pez08:01:07

(Will record a new video.)

lspector22:01:25

That's great and the video is too! I didn't get the error message... but I'll try again starting from nothing and see if that makes a difference.

pez22:01:38

If you're fast to type the {} and save you don't get the error. Maybe tell your students that: ”You have to be very fast!” 😃

pez22:01:01

@UKFSJSM38 @U9A1RLFNV @U04HKE0BTC5, you know if there is a way we can avoid starting clojure-lsp with an empty deps.edn (or maybe clojure-lsp could use {} in that case?).

ericdallo22:01:23

Not sure I understood the problem, but without a deps file there is no way clojure-lsp knows what command to call to get the classpath

pez22:01:05

The problem is that if you create the deps file with VS Code, it starts out empty.

pez22:01:59

And if it is the first clojure file created, it's appearance will activate Calva and Calva will start clojure-lsp.

ericdallo22:01:13

So you are suggesting to clojure-lsp fill the empty edn with {} right?

ericdallo22:01:29

That would be nice, but for that, clojure-lsp would need to start 😂

ericdallo22:01:42

so chicken and egg problem

ericdallo22:01:34

An LSP server can't process any requests while initialize didn't finish :/

ericdallo22:01:23

So probably something that calva would need to manually do

pez22:01:43

Can clojure take the deps map on the command line? If so when clojure-lsp has read deps.edn and notice it is empty it could pass {} instead.

pez22:01:19

We can probably do something in Calva. But it gets a bit delicate since we would need good knowledge about how clojure-lsp will decide to try find the classpath.

ericdallo22:01:25

Maybe, ATM there is no custom logic to handle or read the files, if we found file X we start process Y

ericdallo22:01:46

So: if project.clj file found, then spawn a lien classpath command

ericdallo22:01:22

It's kind of weird, add a intermediate check that would read the file and if inconsistent pass a custom command or so IMO

pez22:01:24

That explains why I get errors in a project where I have both project.clj and deps.edn and no deps vector in project.clj. 😃

ericdallo22:01:00

That should not cause errors I guess, if the command works, clojure-lsp would merge both classpaths

pez22:01:03

I guess the lein command fails, I should get rid of that project.clj.

pez22:01:04

Anyway, Calva could solve it, but the problem isn't unique to Calva. Any client that has some auto-start clojure-lsp behaviour would need to solve it. Maybe it is clojure that should replace empty with {}... @U064X3EF3?

ericdallo22:01:09

Good point, if there is a way to solve that on the commands itself would be nice

Alex Miller (Clojure team)01:01:55

Can you catch me up so I don’t have to read the thread?

pez07:01:19

@U064X3EF3 Calva defaults to start clojure-lsp at activation. One activation trigger is that a Clojure file is opened. Creating a deps.edn file in VS Code means that an empty file is first created. clojure is called by clojure-lsp to figure out the classpath. If the file is still empty by then, the command fails, and the user gets a big error message. In most of these cases, when deps.edn is the first file created, things would work fine if clojure didn't exit non-zero. Observations: • If clojure-lsp starts and finds no project files, it will assume default project classpaths (`src`, test). So a beginner starting out with creating src/hello/core.clj gets no warnings. (But also no static help with Clojure Core things.) • If clojure is run when there is no deps.edn file, it returns the same as if there was a deps.edn with an empty map in it. The question to you is if clojure could have a special case for the empty deps.edn file, and treat that the same as if the file didn't exist/contained an empty map?

Alex Miller (Clojure team)13:01:25

Can you put it on https://ask.clojure.org and I’ll take a look when I get a chance?

❤️ 4
🙏 2
lspector21:01:26

@U0ETXRFEW if there was a Calva command that created the directories and files, and ideally then opened the project, then that would avoid this problem, right? I realize that it'd be good to fix this so that people could build different structures manually from within Calva without getting an error, and that it'd be good to fix the underlying issue that's causing the error for other uses and other tools. But maybe "Calva: Create and open a minimal deps.edn project" would be helpful enough to enough users (particularly beginners) that it be worth doing?

pez21:01:11

@U06BV1HCH agreed. There's an issue for this. https://github.com/BetterThanTomorrow/calva/issues/1779 In a minimal shape this feature shouldn't be too hard to implement.

❤️ 2