Skip to content

Implement find-usages #51

@bbatsov

Description

@bbatsov

Cognitect recently released a new version of REBL that has a find usages feature. @SevereOverfl0w asked Rich about the implementation and Rich was kind enough to share the crux of it:

(defn fdeps [val]
    (set (some->> val class .getDeclaredFields
                  (keep (fn [^java.lang.reflect.Field f]
                          (or (and (identical? clojure.lang.Var (.getType f))
                                   (java.lang.reflect.Modifier/isPublic (.getModifiers f))
                                   (java.lang.reflect.Modifier/isStatic (.getModifiers f))
                                   (-> f .getName (.startsWith "const__"))                                  
                                   (.get f val))
                              nil))))))

Some notes from Rich:

It reflects against the fn classes themselves, every closure put fields in for vars,
that’s what makes vars fast.
So these are ‘runtime’ deps, not source deps. You won’t see inlined fns or macros.
fdeps works on the fn value, not the var.

So people have already been building cool things with that idea https://gist.github.com/vlaaad/0350b61e127e82165d195b490999ec0a

So, what we need to do now is add this to Orchard and then wrap it in CIDER nREPL. That should be pretty easy and have a huge impact for the end users.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementImprovement to an existing feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions