orchard icon indicating copy to clipboard operation
orchard copied to clipboard

xref navigation of Clojure methods

Open simon-katz opened this issue 6 years ago • 13 comments

(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:

  • After M-. shows a multimethod, another command can be invoked repeatedly to navigate to each of the methods.
  • Something that lists all the methods for a multimethod and supports navigation to a chosen method (perhaps a sequence to cycle through in the minibuffer, perhaps an "inspector" buffer) .

simon-katz avatar Mar 30 '18 14:03 simon-katz

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

bbatsov avatar Apr 02 '18 05:04 bbatsov

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

rymndhng avatar Apr 06 '18 09:04 rymndhng

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

simon-katz avatar Apr 06 '18 13:04 simon-katz

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.

expez avatar Nov 01 '18 08:11 expez

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] avatar May 08 '19 16:05 stale[bot]

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

stale[bot] avatar Jun 07 '19 17:06 stale[bot]

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.

simon-katz avatar Oct 29 '19 15:10 simon-katz

It only works within the current project, though.

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

expez avatar Oct 29 '19 16:10 expez

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.

bbatsov avatar Oct 29 '19 16:10 bbatsov

Does Orchard support this?

scimetfoo avatar Dec 11 '20 18:12 scimetfoo

Not yet.

bbatsov avatar Dec 11 '20 18:12 bbatsov

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

scimetfoo avatar Dec 12 '20 10:12 scimetfoo

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 😄

vemv avatar Aug 21 '23 03:08 vemv