cursive

Issues at: https://git.io/cursive-issues
golanweiss 2021-04-21T06:47:42.223900Z

Hi, I’m using deps, and each time after initial project scanning, Cursive overrides my definitions for my modules’ source root, test root, resources etc. Seems it takes what is in the deps.edn under :paths and marks each of them as source root. Is this a known issue? is there a workaround?

cfleming 2021-04-21T07:25:40.224Z

No, that's how it should work, and it's also how all the other integrations (e.g. Maven) work. If you're using a build integration to manage your module, then you need to put the config into your module file (deps.edn in this case) and that will be reflected in the IDE setup.

golanweiss 2021-04-21T07:47:13.224200Z

Thanks for the quick response. what do you mean exactly? Can you give me an example of what to put in the deps.edn? There’s only :paths and adding “test” there doesn’t help.

golanweiss 2021-04-21T07:47:47.224400Z

I think the correct behavior should be to keep user decisions of the IDE and not override them.

golanweiss 2021-04-21T07:48:59.224700Z

> If you’re using a build integration to manage your module I did not understand what do you mean exactly. This is just a clojure deps monorepo project in IntelliJ.

cfleming 2021-04-21T22:44:41.234900Z

When you use a build system like Lein, Deps or something like Maven, then the details of the corresponding IntelliJ module are updated to match the details from the build file. So if you want the details reflected into IntelliJ to change, you need to update your build file rather than updating the configuration in the IDE. This means that things you want marked as source roots need to be either under :paths or under :<alias>/:extra-paths.

cfleming 2021-04-21T07:25:40.224Z

No, that's how it should work, and it's also how all the other integrations (e.g. Maven) work. If you're using a build integration to manage your module, then you need to put the config into your module file (deps.edn in this case) and that will be reflected in the IDE setup.

golanweiss 2021-04-21T07:47:13.224200Z

Thanks for the quick response. what do you mean exactly? Can you give me an example of what to put in the deps.edn? There’s only :paths and adding “test” there doesn’t help.

golanweiss 2021-04-21T07:47:47.224400Z

I think the correct behavior should be to keep user decisions of the IDE and not override them.

golanweiss 2021-04-21T07:48:59.224700Z

> If you’re using a build integration to manage your module I did not understand what do you mean exactly. This is just a clojure deps monorepo project in IntelliJ.

2021-04-21T09:25:38.226Z

My src/clj folder ends up being marked as test source, not source. I have src/cljc in :paths and adds src/cljs and src/clj through :extra-paths in different aliases.

{
 :paths ["src/cljc"]
  ...

 :aliases {
           ...
   :server {:extra-paths ["src/clj"]
            ...
   :test {:extra-paths ["test" "src/clj"]
Is it last alias that wins? How does Cursive figure out that a path should be test source, does it look at the alias name?

golanweiss 2021-04-22T07:46:25.238500Z

@cfleming > 2. If you have other source roots (either from `:paths` or some `:extra-paths`), if you have manually marked those as a test root then Cursive will continue to respect that. This is great, indeed works! Can it be done also for “Resources root”? Right now if I put the “resources” folder under :path it override-marks it with “Source root”, and if I put in :extra-paths it just clears my marking.

cfleming 2021-04-22T09:35:03.238800Z

Yeah, I’m not sure about making that change, since it’s very hard to predict what it might break. I guess the effect would be limited to the IDE (i.e. it won’t break anything for deps itself), and the workaround would just be to manually mark those cases as tests.

cfleming 2021-04-22T09:37:17.239Z

> Can it be done also for “Resources root”? Right now if I put the “resources” folder under :path it override-marks it with “Source root”, and if I put in :extra-paths it just clears my marking. In :extra-paths it will also mark as a source root if the alias is selected to be synced as described in the doc link above. Cursive doesn’t support resource paths for deps, because deps itself doesn’t support them - it only has the concept of “things which are on the classpath”. I wouldn’t even worry about the test marking (since deps doesn’t support that concept either), except that some things in IntelliJ rely on it.

2👍
octahedrion 2021-04-21T09:49:52.226700Z

is there a way to add middleware to Cursive's nREPL server ?

Janne Sauvala 2021-04-21T10:20:21.226800Z

These are configured by IntelliJ, so if you click that folder, open the menu, select “Mark Directory as…” and then change the type which one you want it to be

Janne Sauvala 2021-04-21T10:21:40.227Z

I think Cursive doesn’t affect to how these directories are marked in IntelliJ 🙂

imre 2021-04-21T10:51:21.227300Z

Cursive does mark them

imre 2021-04-21T10:51:38.227500Z

Bring up your "clojure deps" tool window

imre 2021-04-21T10:52:20.227700Z

under aliases, select the ones you need for development

imre 2021-04-21T10:52:56.227900Z

in my experience that affects what cursive will see as dev/test roots

imre 2021-04-21T10:53:38.228100Z

wrt how cursive decides whether something should be a dev or a test root, I don't know

imre 2021-04-21T10:55:00.228400Z

I guess one could circumvent this by not having the same path in more than 2 aliases and then combining those aliases when running the tests

imre 2021-04-21T10:55:17.228800Z

but that might not work in your case

flowthing 2021-04-21T10:57:10.229Z

Cursive respects .nrepl.edn: https://nrepl.org/nrepl/usage/server.html#server-configuration

1🙏
2021-04-21T11:50:31.229300Z

@janne.sauvala I can use “Mark Directory as…” to change the type. But Cursive will change it back after a while.

2021-04-21T11:54:15.229500Z

@imre I have both aliases checked in “clojure deps” tool window. I can try to move alias ‘server’ after ‘test’ to see if it’s an order issue.

imre 2021-04-21T11:55:28.229700Z

Those are inside an unordered map so I doubt that would help. I'd imagine Cursive has some logic along the lines of "if the path appears in an alias that looks test-y then it will be marked a test path"

imre 2021-04-21T11:55:41.229900Z

But if it does help, all the better

Janne Sauvala 2021-04-21T11:55:59.230100Z

Oh okay, good to know that Cursive controls also that :thumbsup::skin-tone-2:

2021-04-21T11:58:37.230300Z

Combining aliases is an option, but then we need to change our build script that expect all projects being able to run tests with clj -A:test

imre 2021-04-21T11:59:06.230500Z

yeah, that's what I had in mind

1👍
imre 2021-04-21T12:00:14.230700Z

@cfleming should be able to shed some light on the underlying logic. I don't see anything flawed with your project config so it would be ideal if the ide could accommodate it

golanweiss 2021-04-21T12:23:58.231Z

Actually I started asking exactly about this issue https://clojurians.slack.com/archives/C0744GXCJ/p1618987662223900

2021-04-21T12:35:17.231300Z

Yes, but I want Cursive to take control, similar to how IntelliJ works with other types of projects. Just need to configure my project such that Cursive does the right thing

dangercoder 2021-04-21T19:21:11.234100Z

Has anyone tried to use https://github.com/kkinnear/zprint or cljfmt with Cursive? The way we keep our code style consistent right now with Cursive is pull-requests and a “code formatting standard” which follows the community style guidelines. I would much like to use a formatting tool instead, I did see someone who had a intellij clojure codestyle that resembles cljfmt: https://gist.github.com/d-t-w/a239dfca4f57b7ff6f38c895b7f45405.

cfleming 2021-04-21T22:44:41.234900Z

When you use a build system like Lein, Deps or something like Maven, then the details of the corresponding IntelliJ module are updated to match the details from the build file. So if you want the details reflected into IntelliJ to change, you need to update your build file rather than updating the configuration in the IDE. This means that things you want marked as source roots need to be either under :paths or under :<alias>/:extra-paths.

cfleming 2021-04-21T22:49:00.235100Z

The problem with this is that deps doesn’t provide a way to specify that something is a test path. Here’s what Cursive does currently: 1. Anything from :aliases/:test/:extra-paths is marked as a test root. 2. If you have other source roots (either from :paths or some :extra-paths), if you have manually marked those as a test root then Cursive will continue to respect that.

cfleming 2021-04-21T22:50:42.235300Z

The use case which is not handled by this is if you have a root in :aliases/:test/:extra-paths which you have manually marked as a normal source root - I think this is Ronny’s case. I’d have to go through the logic with a fine tooth comb, but I don’t think there’s a good way to allow a path under the :test alias to be a normal source root.

cfleming 2021-04-21T22:57:15.235500Z

One way to think about this is: when Cursive syncs the project to the module, it has to decide how to mark each root. Imagine that your server alias instead looked like: :server {:extra-paths ["server-sources" "src/clj"] .... Presumably in the IDE you would select both the server and test aliases (like this: https://cursive-ide.com/userguide/deps.html#working-with-aliases) because you’d want all of the folders “server-sources”, “src/clj” and “test” from the two aliases to be marked as roots. In that case, how should Cursive mark the “src/clj” folder? It’s inherently ambiguous.