This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-11-10
Channels
- # announcements (3)
- # asami (19)
- # babashka (38)
- # beginners (42)
- # cider (19)
- # clojure (17)
- # clojure-europe (34)
- # clojure-hungary (3)
- # clojure-nl (1)
- # clojure-norway (53)
- # clojure-uk (7)
- # clojuredesign-podcast (34)
- # conjure (2)
- # cursive (7)
- # data-science (13)
- # datalevin (3)
- # datomic (19)
- # dev-tooling (1)
- # events (1)
- # honeysql (2)
- # hyperfiddle (31)
- # integrant (16)
- # juxt (39)
- # missionary (14)
- # nrepl (14)
- # off-topic (57)
- # overtone (22)
- # podcasts-discuss (1)
- # practicalli (32)
- # reitit (12)
- # releases (2)
- # ring (13)
- # ring-swagger (2)
- # sql (85)
- # squint (75)
Not sure if this is a cider or rather a general clojure question, but: how should I write code dealing with Java objects such that cider could provide meaningful code completion candidates?
For example, let's say I have some Java object factory
, which provides methods such as
public SomeClass createSomeClass() { return new SomeClass(); }
I'd like to write code such as
(let [object (doto (.createSomeClass factory)
(.setFoo 1) ;; <- I'd like completion here
(.setBar 2)) ;; <- and here
quuz (.getQuuz object)] ;; <- but also here
(.toString quuz))
at the moment it feels like I need to write
(let [^SomeClass object (doto ^SomeClass (.createSomeClass factory)
(.setFoo 1)
(.setBar 2))
quuz (.getQuuz object)]
(.toString quuz))
for cider to suggest the completionsAlso, it looks like the autocomplete does not suggest any inherited methods, e.g. if SomeClass extends SomeOtherClass
.
As for the first question, is your only concern having to write type hints? There are many reasons to write them, I summarized them in https://github.com/jonase/eastwood#reflection
> Also, it looks like the autocomplete does not suggest any inherited methods, I'll check. That would sound like a Compliment issue (@U06PNK4HG)
sure, I naturally have (set! *warn-on-reflection* true)
like any good boy. But in this case those type hints are not strictly needed
I don't have the code at hand at the moment, but something like (def ^ObjectFactory factory (ObjectFactory.))
. The use case here is building a hierarchy tree of objects when doing XML generation from java classes.
Yep, that type hint looks like a correct (type-hinted) declaration.
Generally, type tags propagate nicely across def
s, let
s, ->
and so on. It's a non-trivial problem to solve but Compliment solves a good chunk of it.
Feel free to verify that for a good variety of simple (and not-so-simple) expressions, we offer the right completion for a given interop object.
If you can check that a) it works for certain cases and b) it doesn't work for a certain code shape (e.g. let + doto), it would be reasonable to create an issue in Compliment.
I assume Compliment is alexander-yakushev/compliment
? Sure, I can document a couple of examples of my problem there
When running tests with cider, every log message that is output to the repl also appears as an overlay and as a minibuffer message. Is there some way to disable this?
Log output is not supposed to be handled that way and would warrant a GH issue, will be happy to attend it swiftly
Is there a handy elisp function for evaling something in the repl and getting results? Something akin to shell-command-to-string
or process-lines
? I've been trying cider-interactive-eval
but it seems to have so many bells & whistles, it doesn't look very straightforward.
In case you want to use cider-interactive-eval this should work :
(cider-interactive-eval "(+ 1 2)" nil nil `(("ns" "user")))
interactive-eval is async, I needed something simpler. I just wrote this: https://clojurians.slack.com/archives/C03S1KBA2/p1699647418659749?thread_ts=1699572048.111389&cid=C03S1KBA2