Cursive already allows this with no syntax changes, but it does require
reproducing Clojure's type inference in the editor. Cursive performs this
type inference, so (modulo bugs) it knows the types of basically everything
that the Clojure compiler does (and in fact in some situations can do
better, but I deliberately use just what the compiler knows right now).

This is used in various ways in completion. All of the cases that Aaron
enumerates above work, since Cursive can correctly propagate the types in
threading forms/doto etc (| is the caret):

(-> "my-string"
    (.ch|))    ; <- Only String methods here

(-> (new MyType)
    (.|))      ; <- MyType methods here

(def foo "hello")

(-> ^String foo
    (.to|))    ; <- String completions here too, because of the type hint.
               ;    Cursive can do better here even though the Clojure
compiler doesn't.
               ;    Currently I restrict this, but completing could e.g.
automagically insert the type hint.

(let [foo "string"]
  (-> foo (.to|)) ; <- No type hint required, since we know the type of foo

Additionally, Cursive supports the following:

(let [foo (ArrayList.)
      iterator (.iterator foo)]
  (.ne|))      ; <- Here, .next will be offered even though Iterator isn't
imported,
               ;    because Cursive knows the types we have in scope at the
caret.

(let [foo (ArrayList.)]
  (foo .i|))   ; <- Here, I've put the receiver first, then I'm completing
the method call.
               ;    Since Cursive knows the type of foo, only ArrayList
methods will be completed.
               ;    When I select a completion, Cursive will swap the two
around, like:
(let [foo (ArrayList.)]
  (.iterator foo|))

I use this last one all the time, and it basically makes Clojure completion
as good as Java completion. Someone pointed out to me that this should
really use the existing dot syntax, like:

(let [foo (ArrayList.)]
  (. foo it|))  ; <- completes to:

(let [foo (ArrayList.)]
  (.iterator foo|))

But I haven't implemented that yet.

I don't do any of the more tricky stuff that IntelliJ does like
transitively searching across chained method calls based on the type, etc,
but that's just a time issue - there's nothing preventing Cursive from
doing that too. Also, offering completions from classes that are not
imported but are in scope makes a huge difference, even without any
switching trickiness.

Cheers,
Colin

On Wed, 17 Oct 2018 at 04:34, Didier <didi...@gmail.com> wrote:

> How does the new syntax help the tooling figure out the type?
>
> (def var (SomeType.))
> (.method var)
>
> Or
>
> (jvm (var.method))
>
> I'm not sure how you narrow down to only the SomeType methods?
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to