Fork me on GitHub

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?


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.


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.


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


> 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.


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.

Ronny Løvtangen09:04:38

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?

Janne Sauvala10:04:21

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 Sauvala10:04:40

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


Cursive does mark them


Bring up your "clojure deps" tool window


under aliases, select the ones you need for development


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


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


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


but that might not work in your case

Ronny Løvtangen11:04:31

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

Ronny Løvtangen11:04:15

@U08BJGV6E 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.


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"


But if it does help, all the better

Janne Sauvala11:04:59

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

Ronny Løvtangen11:04:37

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


yeah, that's what I had in mind

👍 3

@U0567Q30W 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

Ronny Løvtangen12:04:17

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


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.


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.


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: 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.


One way perhaps could be that paths that are in aliases/test/extra-paths and also under aliases/somethingelse/extra-paths could be handled per point 2. Approaching another way: only paths that only appear in the test alias would be automarked as test source roots


Of course this could break another edge case

Ronny Løvtangen06:04:03

Makes sense to only mark paths that are exclusively in :test alias as test source. Test classpath needs, by nature, to include source under test, and tools-deps doesn’t provide a way to inherit paths from other aliases, only from the top level :paths. If I include src/clj in the top level :paths it will also be part of the ClojureScript part of our build, which I am trying to avoid. Of course there is the possibility to invoke test with more aliases to combine the needed classpath, something like clj -A:clj-src:test , but there is something nice about expecting all projects to run tests with the simple clj -A:test


@U0567Q30W > 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.


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.


> 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.

👍 4

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


Has anyone tried to use 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: