Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xref navigation of Clojure methods #180

Open
simon-katz opened this issue Mar 30, 2018 · 13 comments
Open

xref navigation of Clojure methods #180

simon-katz opened this issue Mar 30, 2018 · 13 comments
Labels

Comments

@simon-katz
Copy link

(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) .
@bbatsov
Copy link
Member

bbatsov commented Apr 2, 2018

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

@rymndhng
Copy link

rymndhng commented Apr 6, 2018

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
Copy link
Author

simon-katz commented Apr 6, 2018

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
Copy link
Member

expez commented Nov 1, 2018

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
Copy link

stale bot commented May 8, 2019

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
Copy link

stale bot commented Jun 7, 2019

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

@stale stale bot closed this as completed Jun 7, 2019
@simon-katz
Copy link
Author

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.

@bbatsov bbatsov reopened this Oct 29, 2019
@bbatsov bbatsov added the help wanted Extra attention is needed label Oct 29, 2019
@expez
Copy link
Member

expez commented Oct 29, 2019

It only works within the current project, though.

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

@bbatsov
Copy link
Member

bbatsov commented Oct 29, 2019

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
Copy link

Does Orchard support this?

@bbatsov
Copy link
Member

bbatsov commented Dec 11, 2020

Not yet.

@scimetfoo
Copy link

scimetfoo commented Dec 12, 2020

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

@vemv vemv transferred this issue from clojure-emacs/cider Aug 21, 2023
@vemv
Copy link
Member

vemv commented Aug 21, 2023

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 vemv changed the title Navigation of Clojure methods xref navigation of Clojure methods Sep 2, 2023
@vemv vemv removed the help wanted Extra attention is needed label Sep 19, 2023
@vemv vemv added the xref label Oct 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants