Fork me on GitHub
#cursive
<
2018-10-04
>
grav07:10:58

When connecting to shadow-cljs server from Cursive via a "remote" configuration, is it possible to get Cursive to execute some code (eg api/watch and api/nrepl-select)?

claudiu09:10:20

@grav I have it commented in the user.clj and after connecting to the repl I run the code selecting the repl I want to use https://github.com/fulcrologic/fulcro-lein-template/blob/develop/resources/leiningen/new/fulcro/shadow-cljs/src/dev/user.clj#L10

cfleming08:10:06

@grav Do you mean when the REPL connects? There’s no way in Cursive to do that, but you might be able to use user.clj to do it at the Clojure level? If that doesn’t work let me know, and I can think about adding it to Cursive.

grav08:10:45

Yes, when the REPL connects. Can you explain what you mean with user.clj?

cfleming09:10:31

@grav Sure, when a Clojure REPL connects, if there’s a user.clj file at the root of the classpath (i.e. in a src folder, not in a namespace) then it will load that file automatically when it starts.

cfleming09:10:46

Do you want that code executed in clj or cljs?

cfleming09:10:04

I don’t know if cljs has something similar - #clojurescript could probably tell you.

grav09:10:12

In clj. It will (as I understand it) launch a cljs repl

cfleming09:10:32

Ok, then user.clj should work for you I think.

grav09:10:32

So I guess user.clj would work. I'll try it!

cfleming09:10:42

Great, let me know how it works.

grav09:10:25

Ok, so shadow-cljs server does execute whatever's in user.clj, but calling the above-mentioned functions causes an exception. If I execute it with a remote REPL connection, it works.

grav09:10:49

Maybe I should search for a hook in shadow-cljs that can execute the code, whenever a remote repl connection is initiated.

grav09:10:02

Or you could implement an "evaluate this file after connection" option for remote REPL configurations 🙂

grav09:10:46

The exception is

Exception in thread "main" java.lang.ExceptionInInitializerError
	at clojure.main.<clinit>(main.java:20)
Caused by: clojure.lang.ExceptionInfo: missing instance {}, compiling:(user.clj:4:1)
, but it's probably got something to do with shadow-cljs

cfleming09:10:07

In general I’m a little reluctant to duplicate functionality that’s in clojure itself, although admittedly user.clj has a discoverability issue since a lot of people ask about this.

grav09:10:12

Haha, yes. It's a bit magic. But I get your point about duplicate functionality. I could probably ask thheller about a hook in shadow-cljs

cfleming09:10:51

I think the first stop would be to investigate the exception - it’s possible that it’s something simple. thheller may have ideas about that too.

grav09:10:39

Ok. will do! Thanks 🙂

dilvan12:10:56

How to change the spacing for hiccup vectors? I know the standard is just one space, but I have difficulties in seeing this amount of space. I tried File->Settings->Editor->Code Style->Clojure but could not find an option to indent vectors (such as the one used by hiccup html code).

martinklepsch14:10:25

@cfleming hey 🙂 I'm just trying to setup cljdoc with Cursive on a friends computer and some resource that should be on the classpath can't be found. Specifically a file that's part of a :local/root dependency: https://github.com/cljdoc/cljdoc/blob/master/deps.edn#L43 We are on the latest EAP release, is this supposed to work and we're doing something wrong?

cfleming14:10:37

@martinklepsch Yes, that should work, what are you seeing?

martinklepsch14:10:28

https://github.com/cljdoc/cljdoc/blob/master/modules/shared-utils/src/cljdoc/util.clj#L12 This line is throwing with "Cannot open <nil> as a reader" (i.e. file not found)

cfleming14:10:02

This is in a REPL?

martinklepsch14:10:53

We're trying to load the namespace via CMD + Shift + L

cfleming14:10:07

Ok, let me clone that and try, one sec

martinklepsch14:10:42

thank you, much appreciated. I'm so clueless about Cursive haha

cfleming14:10:53

Your friend is on 1.8.0-eap8 right?

✔️ 4
cfleming14:10:18

Just waiting while it downloads the internet…

cfleming14:10:30

I get this error when syncing the project: “Manifest type not detected when finding deps for cljdoc/shared-utils in coordinate {:local/root “../shared-utils”}”

cfleming14:10:34

Did you get that?

martinklepsch14:10:00

I don't think so. What specifically are you referring to with "syncing the project" running clj for the first time?

cfleming14:10:15

No, when importing the project into Cursive.

cfleming14:10:20

How did you do that?

cfleming14:10:50

So that error message comes back from deps, and is of mysterious origin. But what’s weird is that the path is wrong.

cfleming14:10:39

Oh wait, it’s actually complaining about analysis-runner, not cljdoc

cfleming15:10:07

I fixed that problem by making modules/analysis-runner/deps.edn look like:

{:paths ["src" "resources"]
 :deps {cljdoc/shared-utils {:local/root "../shared-utils"
                             :deps/manifest :deps}}}

cfleming15:10:34

I see the problem you’re seeing, and for some reason those paths are coming through as:

/Users/colin/.gradle/caches/modules-2/files-2.1/com.jetbrains.intellij.idea/ideaIC/183.3283.2/f6ecc94209dbdecaea93389221b330c52f8f367d/ideaIC-183.3283.2/bin/modules/analysis-runner/src
/Users/colin/.gradle/caches/modules-2/files-2.1/com.jetbrains.intellij.idea/ideaIC/183.3283.2/f6ecc94209dbdecaea93389221b330c52f8f367d/ideaIC-183.3283.2/bin/modules/analysis-runner/resources

cfleming15:10:59

Investigating….

martinklepsch15:10:09

Ok we just tried with the :deps/manifest addition and the issue seems to remain the same but we're not 100% certain we did everything correct. Is there something specific we need to watch out for when launching the REPL process?

martinklepsch15:10:24

(we tried clearing .cpcache FWIW)

cfleming15:10:06

@martinklepsch No, this appears to be a large can of worms inside Cursive and tools.deps. I’m not sure exactly what the problem is, but my working theory is that it’s something to do with the CWD because I call tools.deps as a library.

cfleming15:10:22

Still investigating…

martinklepsch16:10:27

Ok cool, no rush ✌️

cfleming16:10:51

@tmarble I have one, and a debugger 🙂

cfleming16:10:15

It’s complicated however since IntelliJ starts background processes to do this stuff.

cfleming16:10:53

@martinklepsch This is partly a tools.deps bug, and partly a Cursive bug.

cfleming16:10:18

Alex says: > Transitive local deps with relative paths are a problem and that’s a known issue

cfleming16:10:43

You have that because cljdoc requires modules/analysis-runner, and that requires ../shared-utils.

martinklepsch17:10:10

Interesting. I never ran into that for some weird reason then @cfleming

cfleming17:10:55

That doesn’t look exactly like what’s happening in Cursive, but I think it’s related.

martinklepsch18:10:04

thanks for digging into this today Colin! Can cursive run the clj process with an alias somehow? I'm thinking of adding an alias with the source paths and dependencies manually added as a workaround

cfleming18:10:27

@martinklepsch Yes, you can do that. However it might be tricky if you run into the bug with the initial sync since Cursive has to do that first to know which aliases are available.

cfleming18:10:51

If you manage to get past that, then View-&gt;Tool Windows-&gt;Clojure Deps, open the cljdoc project, under Aliases select the aliases you need and then hit refresh.

cfleming18:10:10

When starting a REPL you can add the aliases in the REPL Run Configuration page.

martinklepsch18:10:38

ok cool, we'll give that a shot

kenny19:10:01

I see Run with Deps was added to the REPL run config. If I am creating a REPL, shouldn't Cursive ignore my :main-opts for any aliases I specify?

kenny19:10:32

The behavior I am seeing is: I have a :test alias that has :main-opts specified and when I click the Run button to open the REPL, it runs my tests in the REPL window and then exits the process. Nifty, but not what I expected.

cfleming20:10:40

@kenny I don’t think so, those are required to e.g. supply -m figwheel.main for a figwheel REPL

cfleming20:10:38

Deps does have the concept of separate alias types for things like this, but AFAICT no-one actually uses them and Cursive effectively always passes -A.

kenny20:10:45

Oh I misunderstood. I thought those were for specifying aliases to start a REPL with that differ from the project aliases.

kenny20:10:53

Is that something that will be added before deps support is complete?

cfleming20:10:45

You mean support for different alias types?

cfleming20:10:53

I’m not sure, I think it’s pretty confusing.

kenny20:10:55

No. I mean I can select the aliases Cursive uses to resolve things in my project by going to the Deps panel and checking the boxes. I may not want to start a REPL using those same aliases though.

cfleming20:10:21

@kenny That works now, those aliases are independent.

kenny20:10:37

Oh. How do I do that?

kenny20:10:19

i.e. I want to resolve my project with aliases :test and :dev but only start my REPL with :test.

cfleming20:10:47

You choose :test and :dev in the boxes in the toolwindow as always, and when running your REPL choose to run with deps and just put test in the aliases box.

cfleming20:10:02

But, that will use :main-opts from that alias.

kenny20:10:28

So that's the problem I started with.

cfleming21:10:07

Right, there’s no way to avoid that right now except to split that alias into two I guess.

cfleming21:10:27

One part with deps, and one with main-opts

kenny21:10:09

I guess. I'd prefer to not have to make code changes due to tooling though.

cfleming21:10:41

I’m afraid that’s the only option right now, if your main opts stop the REPL running and you need the test deps.

kenny21:10:02

It seems like the only real solution is to separate out -R and -A. In practice I don't ever use -R - CI runs tests using -A and Cursive starts the REPL with aliases and ignores :main-opts. But it makes sense for the case.

cfleming21:10:46

Sure. I spoke to Alex about it and he didn’t seem to be aware of anyone actually using the different types, and said he always uses -A. I’ll think about a way in which most people can just add some aliases there but you can partition them if you want.

cfleming21:10:26

maybe accept either alias, alias, alias or -Ralias -Calias or whatever.

cfleming21:10:52

If no flag types are entered, then everything is -A.

kenny21:10:36

Makes sense, I think. So you could do something like this :dev, -R:test?

kenny21:10:17

It almost seems like REPLs that are started via :main-opts should be another option entirely.

cfleming22:10:02

Why would they need another option?

kenny22:10:20

Because it sounds like there are two distinct tasks a user would want to do: 1. Run a custom REPL launched via :main-opts 2. Start a REPL with a particular set of aliases

cfleming22:10:59

Allowing the different alias types would meet both those needs though, right?

cfleming22:10:25

I mean, :main-opts comes from an alias.

kenny22:10:04

Right. I was trying to simplify things for users because the tools-deps alias flags can be quite confusing.

cfleming22:10:38

Yeah, they are. I think -A by default unless you specify is hopefully a good middle ground.

kenny22:10:21

Perhaps. Though it threw me a bit because I expected the aliases in the "Run with Deps" option to operate in the same way that clicking an alias in the Deps panel does.

cfleming22:10:08

Well, they do, except that the ones in the Deps panel are only for dependency resolution, so :main-opts is implicitly ignored since nothing is executed.

kenny22:10:41

Thus my initial confusion.