Fork me on GitHub
#cursive
<
2020-06-20
>
adam13:06:20

Is it possible to make cursive recognize my tests without clj prefix? If I have my namespace as (ns myproj.util.string-test Cursive show the red line underline and is unable to run tests, if I change it to (ns clj.myproj.util.string-test it recognizes and everything works. However, my tests run just fine from the command line without clj prefix

adam13:06:11

I have this in my project.clj:

:source-paths ["src/clj" "src/cljs" "src/cljc"]
And this in my profiles.clj
:test {:source-paths ["test/clj"]

dpsutton13:06:58

That’s in your user profiles.clj and not in the project?

adam13:06:08

:test {:source-paths ["test/clj"] is in my profiles.clj

dpsutton13:06:17

That seems like it should be added to the dev profile of project.clj. I bet it works then

dpsutton13:06:49

That seems a legitimate config for this project. And cursive is thinking “test” is on the class path. Not sure if that’s a default or also configured in the project

dpsutton13:06:45

Not saying you aren’t seeing a bug. Just a potential workaround that seems to also make good sense in this case

adam13:06:38

The following fixes the problem but I assume I shouldn't be doing this on the top level of project.clj: :source-paths ["src/clj" "src/cljs" "src/cljc" "test/clj"] This doesn't seem to have any effect: :profiles {:uberjar {:aot :all} :dev {:source-paths ["test/clj"]}}

dpsutton14:06:36

I wonder if there’s two profiles named test. Maybe rename the test one in profiles.clj and reimport the project. Open the profiles config window and see if you can select it?

adam14:06:39

Not sure how I can import the changes on profiles.clj. I am asked to import the changes when I modify projects.clj only via the little popup that appears at the bottom right

dpsutton14:06:06

Right click on project.clj and it’s in that menu I believe

adam14:06:14

Thanks - your tip "should be added to the dev profile of project.clj" helped me solve the problem. I was under the impression that it's enough to have :source-paths ["test/clj"] in my test profile. I added it to my dev profile in profiles.clj and restarted the IDE. Now it works.

adam14:06:28

I ran my tests from command line using lein with-profile +test test that's why it was working...

emccue17:06:35

Curious what the blockers/points of progress are on type inference when the type isn't explicitly imported

cfleming23:06:08

The types aren’t required to be explicitly imported, Cursive will track them anyway. In your example there must be something else going on. Can you give a concrete example that fails that I could take a look at?

emccue22:06:57

ran into one in the wild

emccue22:06:03

(ns dev.mccue.egge.aws
  (:import (com.amazonaws.services.simpleemail AmazonSimpleEmailServiceClientBuilder)
           (com.amazonaws.services.simpleemail.model SendEmailRequest Destination Message Content Body)))


(defprotocol PhotoService
  (upload-photo! [this path contents])
  (retrieve-photo [this path]))

(defprotocol EmailService
  (send-support-email! [this to subject body]))

(def noop-email-service
  (reify EmailService
    (send-support-email! [_ _ _ _])))

(def ^{:private true} support-email "")

(def aws-email-service
  (reify EmailService
    (send-support-email! [_ to subject body]
      (let [client (-> (AmazonSimpleEmailServiceClientBuilder.)
                       (.build))
            request (-> (SendEmailRequest.)
                        (.withSource support-email)
                        (.withDestination (-> (Destination.)
                                              (.withToAddresses [to])))
                        (.withMessage (-> (Message.)
                                          (.withSubject (-> (Content.)
                                                            (.withCharset "UTF-8")
                                                            (.withData subject)))
                                          (.withBody (-> (Body.)
                                                         (.withText (-> (Content.)
                                                                        (.withCharset "UTF-8")
                                                                        (.withData body))))))))]
        (.sendEmail client request)))))

emccue22:06:16

i'll make a project and zip it up

cfleming00:06:20

@U3JH98J4R The problem in this snippet is that you can’t use (AmazonSimpleEmailServiceClientBuilder.) because the constructor is private. However Cursive doesn’t warn about that, which it should. In fact, oddly, I can open that whole snippet and the only warning I see is in .sendEmail.

cfleming00:06:31

The solution to that problem is to use (AmazonSimpleEmailServiceClientBuilder/standard) instead, then the type of the builder resolves, at least. However the type of client is still unknown, but that’s a Clojure problem due to type erasure - the type of build() is a generic type which Clojure doesn’t understand.

cfleming00:06:28

I think the constructor problem is because Cursive resolves constructor invocations to the class in cases where the class doesn’t have an explicit constructor. In this case it looks for a constructor but filters out the private ones so it thinks that there aren’t any.

cfleming00:06:39

There’s definitely scope here for Cursive to track more precise types than Clojure is able to, and to suggest type hints in the appropriate places to fix the code so it actually means what you probably thought you were saying 🙂

emccue00:06:07

Yeah, sorry I wasn't running the code so I missed the constructor thing

emccue00:06:09

I feel like there is no reason clojure couldn't track generic stuff - types aren't always erased

emccue00:06:02

Like sure they are "erased", but that info is in the class file

cfleming10:06:57

Right, but Clojure doesn’t track those types at all, it only uses raw types.

emccue17:06:53

(ns thing
  (:import (some.package A)))

(-> (A/builder)
    (.b "c")  ;; Won't be able to infer this method exists since A$Builder isn't imported
    (.build))

emccue17:06:46

the annoyance is just that when i import a class just for cursive to be able to infer properly, it is still listed as unused in the imports list

thosmos17:06:15

I recently attempted to Refactor->Move File a file like app.ui.foo to app.foo and found the refactor support not really working. All it did was move the file, but no refactoring happened. I wound up doing a global search/replace, which was easy enough, but there were some snags that would be avoided by having tooling automation. Is this supported via a different method? I would also like to be able to move individual fns from one namespace to another like from app.foo/myfn to app.bar/myfn and have the tooling change all namespace refs.