This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-06-20
Channels
- # aws (1)
- # babashka (68)
- # beginners (68)
- # braveandtrue (6)
- # calva (4)
- # cider (10)
- # clj-kondo (26)
- # clojure (76)
- # clojure-dev (18)
- # clojure-europe (1)
- # clojure-norway (25)
- # clojure-spec (8)
- # clojure-sweden (7)
- # clojure-uk (3)
- # clojuredesign-podcast (1)
- # clojurescript (11)
- # conjure (29)
- # cursive (31)
- # datomic (29)
- # emacs (12)
- # fulcro (29)
- # graphql (3)
- # helix (2)
- # hoplon (39)
- # hugsql (4)
- # malli (3)
- # off-topic (62)
- # pedestal (8)
- # re-frame (23)
- # reagent (14)
- # rewrite-clj (10)
- # shadow-cljs (18)
- # spacemacs (3)
- # sql (13)
- # xtdb (32)
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
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"]
That seems like it should be added to the dev profile of project.clj. I bet it works then
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
Not saying you aren’t seeing a bug. Just a potential workaround that seems to also make good sense in this case
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"]}}
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?
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
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.
I ran my tests from command line using lein with-profile +test test
that's why it was working...
Curious what the blockers/points of progress are on type inference when the type isn't explicitly imported
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?
(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)))))
@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
.
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.
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.
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 🙂
I feel like there is no reason clojure couldn't track generic stuff - types aren't always erased
(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))
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
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.