Fork me on GitHub
#calva
<
2022-12-02
>
Namit Shah07:12:47

Hello everyone, is it possible to run multiple commands at once in jacked in nREPL? Or do I have to run each of them individually?

pez08:12:29

Hi! Do you mean to evaluate several things in succession? There are a few Clojure constructs for that. The one simplest one is to wrap your expressions in do. So, (do (this) (that) (this too))

👍 1
skylize13:12:43

You can highlight multiple forms and use Calva: Evaluate Current Form (or selection, if any), which defaults to Ctrl-Enter on Win/Linux, and I assume probably Cmd-Enter on Mac. There is also Calva: Load/Evaluate Current File and its Requires/Dependencies to load in the whole namespace. Open the Command Palette and type "eval" to see all the different variants Calva offers for evaluating in different contexts.

👍 1
elena.poot17:12:25

Newbie question: Trying to move from Cursive to Calva, and I can't get it to stop linting the target directory (I use leiningen). So as soon as I change a file, I get a pile of entries in the problems window for all the duplicate functions, and things like find references or go to definition are actively dangerous to use, as they're equally likely to pull up the target version. I've tried everything I could find. The

:use-source-paths-from-classpath false
setting for clojure-lsp doesn't seem to actually exist, per the clojure-lsp docs. I know this is supposed to work out of the box, but I can't figure out how I broke it.

ericdallo17:12:55

This is a clojure-lsp issue, could you provide a sample project where I can test if the issue happens there as well?

skylize18:12:35

Why is your build target on the classpath?

elena.poot18:12:33

Shouldn't it be? lein calculates the classpath and includes it, and I assumed the compiled classes needed to be on the classpath to be found. Apparently I don't understand the classpath, but I also haven't done anything explicitly to change it from the default.

elena.poot18:12:11

@UKFSJSM38 I will do that unless another answer presents itself first. I can't share any actual projects, of course. But all my projects do this, so it's a config thing and my configs aren't at the project level, so should be easy to recreate.

👍 1
ericdallo18:12:19

We did some classpath refactors some months ago, so there is a chance we introduced a bug, thanks

skylize18:12:55

Typical project structure would have a src folder for the source code, and a separate folder for a build target. The classpath while building will should only see your src folder and any other folder that you need resources from. Then lein dumps the build into a separate folder which runs self-contained from your source.

- root
   - out
      (lein dumps stuff here)
   - src
      - my_project
         - core.clj
   - resources
I haven't used Lein in a while, but I'm pretty sure it defaults to adding src to the classpath if not specified. So in that case, the target dir, out in the example, needs to somewhere outside of src.

elena.poot18:12:55

That is how I am set up, and it is the default lein structure, but out is named target. But lein does add it to the class path.

elena.poot18:12:06

The default regex does exclude it, and the lsp server info does show the paths it uses, which do not include target. But when I change a source file, the log mentions a change to a watched file, and suddenly the target file shows up. The json file in the clj-kondo cache specifically mentions the path to the file in the target folder.

elena.poot18:12:27

Btw this is all on windows, if that matters.

elena.poot18:12:37

(actually, lein specifically adds 'target\classes' to the class path, but that path includes copies of the source files)

ericdallo18:12:51

Hum, the file watch may be watching the target and scanning it when lein recompiles it, certainly causing clojure-lsp know about that file

ericdallo18:12:03

Definitely something we should try to avoid on clojure-lsp

ericdallo18:12:46

@U4LCNMMGS please, open a clojure-lsp issue with a minimal repro repo if possible so I can try to understand and find a way to avoid file watch consider those files

elena.poot18:12:26

I, um, I just tried a project I'd not previously opened in Calva, and can't repro it. I've been messing with configs trying to solve this and may have corrupted something. But yeah, if I can repro it I'll file an issue, and if I clean all the artifacts from the project I've been working on and it stops happening, I'll report back that it was a false alarm. Thanks!

ericdallo18:12:55

A git branch change may help repro or a process like shadowcljs watching changes to source to recompile the target

elena.poot18:12:57

Apparently Calva is doing that. I'm still figuring this stuff out, but this is straight clj, no cljs, so there aren't any watchers that aren't provided by some part of Calva.

ericdallo19:12:12

Oh, the fact you have your folder called as out and not target or build, may cause vscode file watcher to not ignore and consider as code to be analyzed if changed... I'd suggest trying to check if renaming it fixes

elena.poot19:12:42

no, it's called target. out was from skylize's example

skylize19:12:57

I was the one who said out

👍 1
elena.poot19:12:04

OK, I'll start on a clean project to try to repro. I just got it to fail again on a "clean" project. The ones I couldn't repro on were single namespace projects, which might be related, but it's still doing it on the larger ones, even after removing all calva artifacts and re-opening.

👍 1
elena.poot20:12:24

Hmm, can't repro yet, but while lsp maybe shouldn't be linting those files, they sholdn't be there. lein doesn't put them there, nor does intellij/cursive. But in Calva in a project that has this problem, if I just hit ^S to save a file, even an unchanged one, it writes it to the target directory as well. Even if I just did a lein clean and the target directory doesn't exist. But so far I can't reproduce that in a blank project, or even any of my own smaller ones.

elena.poot21:12:11

I'm sorry, I can't repro it In a small lein project, if you hand-copy a .clj file into the target/classes directory (in the namespace-appropriate location), lsp WILL lint it and update its cache, and it will show up if you check references on one of those functions. I think that's wrong, but it doesn't cause any of the other issues I mentioned. And of course, the source files shouldn't be there so it shouldn't ever happen anyway. In my larger projects, if you simply save a file in the source directory, it gets immediately copied to the target/classes folder, and linted, but then it notes all the functions as duplicated, and they show up as references, but go to declaration seems to pick the last one linted, which is usually the target/classes copy. And I can't make that happen in a new project.

ericdallo21:12:26

If you open the target file or file watch report as a file to analyze it will mess things for clojure-lsp indeed, as it will consider as part of the project, not sure there is a easy way to fix that, as I mentioned, a repro would help a lot

elena.poot21:12:46

yeah, I know. But when I mentioned copying it to target/classes, I did that with explorer, not from within vsc. I didn't have the file open, although, of course the target folder does show up in explorer. Since that's a folder it is supposed to ignore, I would have thought it wouldn't react to updates to it. But then, nothing should be writing source files there, so I can easily see that not being checked. I still have no clue what IS writing those source files, except that it's something in VSC/Calva/whatever else is loaded (and I only installed VSC to run Calva)

elena.poot22:12:25

If I can ever repro the issue, I'll report it, but I've spent days on this, and don't know how much more time I can justify spending on it. (But then I'll think of something else to try and fall down the rabbit hole again.) sigh Thank you SO much for trying to help though!

phill00:12:58

Youall are heroic for looking for a way to solve this. The duplicates I can try to ignore, but when I "go to definition" and I land (unawares) in the "decoy" file in the target directory, I sometimes work there by accident. I think Leiningen includes target on the classpath in order for it to encompass AOT-compiled class files. As for how clj files get in target, I think it might be "lein test" or "lein package" or "mvn test" (with clojure-maven-plugin)... so, theoretically, if you had a lein file watcher that re-ran tests or something, then that might do it.

ericdallo00:12:48

Yeah, I know it's a terrible experience since I already faced something like that in the past, that's why if there is anything to improve on lsp side, I'd love to help

elena.poot00:12:05

Actually, if you watch the LSP logs, you'll see that the file written to target happens immediately, I don't think any other tools, even lsp, have had a chance to run

elena.poot00:12:26

(I could be wrong, of course)

ericdallo00:12:28

does that happens with REPL on or off or both?

elena.poot00:12:03

off, definitely. I haven't even tried to tackle the dependency conflicts to get the repl to run yet. First, I have to be able to edit lol

ericdallo00:12:07

yeah, one more reason to possibly be something to improve on lsp side

ericdallo00:12:39

I'm no cljs heavy user, but I know it's easier to have target folders being updated when coding with shadow-cljs

1
elena.poot00:12:46

I'm waiting to see if it starts again, but I shut down VSC, deleted EVERYTHING related to calva/lsp, and the target directory, and then started it again, and now it's not doing it. But it also seems to not be integrating the lint data properly

elena.poot00:12:43

i.e. it doesn't show any problems until I open a source file, and then everything is unreferenced until I open the referencing file, and save one or both of them. So something's still off in that project, but it's not duplicating the source files

elena.poot00:12:55

(that's almost more mysterious)

ericdallo00:12:59

that used to happen when clojure-lsp classpath was not found, but recent releases we made that required showing a warning if the classpath is not found

elena.poot00:12:44

OK, I've reproduced it, but I had to use my parent project. Going to try the same steps after removing it, but I'll save this first. It takes 3-4 vsc restarts to start happening.

skylize00:12:19

One more reason to switch to tools.deps. 😛🙉

elena.poot00:12:27

Yep, I can reproduce the behavior where it creates the clj files under target, but not all of the other symptoms I mentioned (duplicate definitions, etc.)

elena.poot00:12:34

I'm on windows

skylize01:12:04

If a clean project is not reproducing, you might try the other direction. Clone the problem project, and start deleting things until it goes away.

elena.poot01:12:45

This is a clean project. I had dirtied it up, but it works clean, that is what I just tested. But it takes 3 edit sessions, so I had started adding some of my stuff to see when it started happening.

elena.poot01:12:28

The thing is, I don't know if this is really an lsp issue, per se. The issue is the files being written and I don't know what is doing that.

elena.poot01:12:01

Also, I need to strip it down further if I can, now that I know the steps required

phill01:12:12

@U4LCNMMGS It is right and proper for clj files to be copied to target/classes because that's how they get included in the jar when you package a jar. Maybe the linter knows about file paths to not scan, but it scans the whole classpath and neglects to exclude the intersection of the classpath and the directories it intended not to scan

elena.poot03:12:13

Is it? I've only used leiningen and intellij/cursive and neither of those does that. In vsc/calva this happens inconsistently (I have to stop and start it about 3 times before it starts doing it), but when it does, clojure-lsp will lint them. I don't honestly know enough about all the various tool chains to know whether it is reasonable to put them there, but if this is intentional, why is it inconsistent? But if it is reasonable, then yeah, clojure-lsp should avoid scanning them from watch events. The docs at http://calva.io actually mention this case (the target directory setup), though only in the context of cljs, and give a clojure-lsp setting to prevent that, but that setting doesn't exist in the clojure-lsp docs or sample settings file, which is supposed to show all the settings. I'm just confused. Does this happen to everyone then? Do people just ignore it all? I'm used to having decent static analysis with intellij/cursive and I find it helpful. Is that not something most people have or care about?

elena.poot03:12:02

btw, I was wrong, the 2 files are written 450ms apart, so some other tool could have been involved, but clojure-lsp logs nothing between receiving those 2 events.

skylize03:12:41

The default lsp config includes this setting, which should be ignoring the target dir.

:source-paths-ignore-regex ["resources.*" "target.*"]
Maybe you have an lsp config file that changes that setting?

skylize03:12:02

Pretty sure the comment in Calva docs is in reference to that setting. But the default shown above should already cover it with a standard Lein project structure.

elena.poot03:12:09

No, I don't. That setting is in effect. In fact, lein classpath returns a classpath that includes both resources and target/classes. clojure-lsp server info shows a classpath that omits those. However, if you write a source file to one of those directories while calva is running, clojure-lsp will lint it. If you then check the corresponding file in the clj-kondo cache, it will show the path to the file in target/classes.

skylize03:12:49

LSP is not changing the classpath. But it should be ignoring things that come from those paths.

elena.poot03:12:15

I was referring to the comment from https://calva.io/linting/ under "Exclude entire folders from the linter", which mentions the :use-source-paths-from-classpath setting, which does not exist in the file you just posted.

elena.poot03:12:30

form my test project, the server info from clojure-lsp shows the following: "source-paths": [ "C:\\Projects\\lsp-test\\src", "C:\\Projects\\lsp-test\\test", "src", "test" ],

elena.poot03:12:29

it doesn't change the classpath, it harvests source paths from the classpath, and removes those matching the regex you showed above, yielding a set of source path that does not include target/classes.

elena.poot03:12:19

(and that project isn't exhibiting the problem at the moment, so switching to one that does) and yet when a file is written to target/classes, the clojure-lsp log shows: 2022-12-03T03:09:28.418Z DEBUG [clojure-lsp.server:55] - [Trace - 2022-12-03T03:09:28.418Z] Received notification 'workspace/didChangeWatchedFiles' Params: { "changes" : [ { "uri" : "file:///c%3A/Projects/farm-decider/target/classes/com/unifilabs/outcome.clj", "type" : 2 } ] }

elena.poot03:12:53

Source paths from that project: "source-paths": [ "C:\\Projects\\farm-decider\\src", "C:\\Projects\\farm-decider\\test", "src", "test" ],

elena.poot03:12:52

I knew something was out of date. 🙂 I tried it anyway, but yeah, I assumed the clojure-lsp docs would be more correct. But I don't see a way to do what that setting says it does, and it explicitly was given as a way to avoid linting the target folder

elena.poot03:12:06

(oh, and the reason "src" and "test" are in that list was from when I was trying that setting with different values, failed to remove my last attempt)

elena.poot03:12:13

(removed those. behavior unchanged)

bringe03:12:26

Just FYI, I created an issue about the outdated docs: https://github.com/BetterThanTomorrow/calva/issues/1988

👍 1
orestis22:12:49

What, the Clojure Notebooks and Portal integration is already working??? Super!

orestis22:12:00

@U02EMBDU2JU I have a first piece of feedback. While seeing my rich comment expressions as top level cells is super nice, I am terrified to run them automatically (by clicking say, execute cell and all below). It would be nice to opt-in some comment blocks for the auto-execute, or even opt-in comment blocks that should take part in the notebook.

orestis22:12:59

Is there a better place to provide feedback than a Slack thread? 🙂

Lukas Domagala15:12:15

I think a ticket or a discussion on github would be best. To answer your question: I'm kind of opposed to add special stuff into the file to support notebooks. They are meant to be just run on normal clj files. In your case I'd put the stuff you just want to execute, like defn at the top of the file and the comment at the bottom. That way you can "run all above". Usually you shouldn't even need to, since the namespace was usually loaded anyway. That said, I would mind an option in the config that disables the comments being put into their own cells.

Lukas Domagala15:12:37

The other option I could see is having special ".cljnotebook" files that give you more stuff

Lukas Domagala15:12:40

I might also be convinced to put it into normal clj files if you come up with something that's very unobtrusive to normal clojure work 😉

orestis17:12:02

Thanks for the reply! In my initial testing I thought that the notebooks are not connected to the already running REPL (I saw some execution errors and without feedback I thought I had to run all the above functions. When I tried again it worked so probably some error on my part.

orestis17:12:04

I have a thread in ClojureVerse but I can move the discussion to GitHub if you prefer, is Calva the correct repo for this?

Lukas Domagala18:12:44

Yeah calva github makes sense

❤️ 1
elena.poot22:12:37

While what I mentioned above looks like a clojure-lsp issue, I think it's not. In some projects, whenever I save a file, that file is also saved to the target/classes directory (in a namespace-appropriate location; this is a leiningen project with the usual directory structure). Not a compiled .class file, but the actual .clj source file, identical to the one in the src directory. It shouldn't be there, and this causes lsp to lint it and all the other weirdness comes from that. I have no idea why the file is being written, and I can't reproduce it in a new project, or even most of my existing ones. It happens in some very large library projects with lots of namespaces that are combined just to reduce the number of deliverables. If this didn't happen, none of the lsp issues would happen. If anyone has any idea what I could look for as the cause of this behavior, I'd be grateful. I'm new not only to Calva, but to VSC as well, I only installed it to run Calva, and haven't installed anything else other than what comes in with Calva (and some themes).