clojure-emacs / orchard

A fertile ground for Clojure tooling
Eclipse Public License 1.0
326 stars 54 forks source link

xref navigation of Clojure methods #180

Open simon-katz opened 6 years ago

simon-katz commented 6 years ago

(Feature request)

It would be good to have a way of viewing and navigating to all the methods for a multimethod.

Two things I've seen before (in LispWorks for Common Lisp) are:

bbatsov commented 6 years ago

Does anyone know if there's some existing API we can leverage to retrieve this info?

rymndhng commented 6 years ago

Looks like there's some data available via getMethodTable, i.e. (.getMethodTable print-method).

See https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/MultiFn.java#L579-L581

simon-katz commented 6 years ago

There's methods, which seems to give the same as .getMethodTable

(= (.getMethodTable print-method)
   (methods print-method))
=> true

EDIT Indeed they are the same: see https://github.com/clojure/clojure/blob/master/src/clj/clojure/core.clj#L1803-L1807

expez commented 6 years ago

Do we have a source location for the results of methods from somewhere? I tried calling meta on the functions in there, hoping for compiler metadata, but found none.

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution and understanding!

stale[bot] commented 5 years ago

This issues been automatically closed due to lack of activity. Feel free to re-open it if you ever come back to it.

simon-katz commented 5 years ago

Just to note that dumb-jump (https://github.com/jacktasia/dumb-jump) works with multimethods — it lets you select from all the methods of a multimethod.

It only works within the current project, though.

expez commented 5 years ago

It only works within the current project, though.

Could grep through the jars on path too to get the rest, right?

bbatsov commented 5 years ago

I think implementing this in the middleware is the simplest path, it's just a matter of someone finding the time to do it. Grepping is easy, but it's never accurate.

scimetfoo commented 3 years ago

Does Orchard support this?

bbatsov commented 3 years ago

Not yet.

scimetfoo commented 3 years ago

defmethods aren't vars and don't have metadata. What would the alternative to grepping be in this case?

vemv commented 1 year ago

I've moved this issue to Orchard.

methods indeed seems useful:

> (methods print-method)
{nil #function[clojure.core/fn--7368],
 clojure.lang.IRecord #function[clojure.core/fn--7480],
 refactor_nrepl.inlined_deps.rewrite_clj.v1v1v47.rewrite_clj.node.meta.MetaNode
 #function[refactor-nrepl.inlined-deps.rewrite-clj.v1v1v47.rewrite-clj.node.protocols/make-printable!/fn--422],
 refactor_nrepl.inlined_deps.rewrite_clj.v1v1v47.rewrite_clj.node.stringz.StringNode
 #function[refactor-nrepl.inlined-deps.rewrite-clj.v1v1v47.rewrite-clj.node.protocols/make-printable!/fn--422],
 java.lang.Character #function[clojure.core/fn--7486],
 clojure.lang.MultiFn
 #function[cider.nrepl.print-method/eval825998/fn--825999],
 refactor_nrepl.inlined_deps.rewrite_clj.v1v1v47.rewrite_clj.node.regex.RegexNode
 #function[refactor-nrepl.inlined-deps.rewrite-clj.v1v1v47.rewrite-clj.node.protocols/make-printable!/fn--422],
,,,

We can take those function objects, infer the namespace that backs them, and read their whole source in search of something like looks like a matching defmethod.

i.e. bit of a mixture of static and dynamic approaches 😄