clojure-emacs / cider

The Clojure Interactive Development Environment that Rocks for Emacs
https://cider.mx
GNU General Public License v3.0
3.54k stars 645 forks source link

[feature request] add feature to find cross references for a function or var #1840

Closed stardiviner closed 5 years ago

stardiviner commented 8 years ago

I hope CIDER can add a feature to find all cross references for a function or var. For examples, list out all places which used a function or var. Common Lisp's SLIME has this function called slime-who-references. And Emacs Lisp has this function called xref-find-references [M-?].

grammati commented 8 years ago

I think clj-refactor's find-usages is what you are looking for: https://github.com/clojure-emacs/clj-refactor.el/wiki/cljr-find-usages

stardiviner commented 8 years ago

@grammati Thanks.

timvisher commented 8 years ago

Actually the SLIME feature finds actual calls to the function at point rather than just textual occurrences. If I'm reading the clj-refactor feature correctly, it's the later not the former.

Waaay back when cider was still hacked-SLIME, it did have this feature. I wish we had it still too. :)

stardiviner commented 8 years ago

@timvisher glad to hear this. I will re-open this feature request.

bbatsov commented 8 years ago

I want us to have something similar at CIDER itself eventually.

Waaay back when cider was still hacked-SLIME, it did have this feature. I wish we had it still too. :)

This was just a textual search, which is rather easy to add back. Doing something different that's not relying on an AST is a bit harder, but is definitely possible.

timvisher commented 8 years ago

@bbatsov Are you sure it was just a textual search? Did it at least try to filter for things that looked like calls? My memory (which is foggy) was that it really did search for references to the var or something.

bbatsov commented 8 years ago

This is the old implementation - https://github.com/technomancy/swank-clojure/blob/master/src/swank/commands/xref.clj

Everyone's welcome to port it to an nREPL middleware.

bbatsov commented 8 years ago

@sanjayl @cskksc Maybe one of you would be interested in porting this from SLIME? :-)

sanjayl commented 8 years ago

Will take a look at it

ckoparkar commented 8 years ago

@sanjayl Awesome! Let me know if I can help with anything.

johngit22 commented 8 years ago

Thanks !

On Sun, Sep 4, 2016 at 6:52 AM, Chaitanya Koparkar <notifications@github.com

wrote:

@sanjayl Awesome! Let me know if I can help with anything.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/clojure-emacs/cider/issues/1840#issuecomment-244596201, or mute the thread https://github.com/notifications/unsubscribe-auth/ADFz2XEZMczlC33SSuV1vmrP7rqf2Vi0ks5qmqL0gaJpZM4Jzi0S .

John Boyd

bbatsov commented 8 years ago

@sanjayl Thanks for tackling this!

bbatsov commented 7 years ago

@sanjayl any news on this?

sanjayl commented 7 years ago

Sorry, hit a wall and ran out of steam. I have the next few days off so I'll see what I can do on the clojure side of things, doubt I'll have time to work on the UI half.

bbatsov commented 7 years ago

Sorry, hit a wall and ran out of steam. I have the next few days off so I'll see what I can do on the clojure side of things, doubt I'll have time to work on the UI half.

One step at a time. I believe you'll be able to pretty much copy/paste the UI from SLIME or just leverage the new xref functionality from recent Emacsen.

bkruczyk commented 6 years ago

@bbatsov Is this still an issue? From what I can see nrepl has message handlar for finding a symbol.

bbatsov commented 6 years ago

@bkruczyk That's certainly not the case. Such functionality doesn't really belong in nREPL itself and will never be part of nREPL I guess. The only nREPL middleware that provides something like this is refactor-nrepl, but I don't like the approach taken there and I'd rather go with something that just relies on the state of the running application (similar to what swank-clojure did in the past).

bkruczyk commented 6 years ago

@bbatsov Just like you said, I was thinking of refactor-nrepl middleware (i.e. this).

What's wrong with it? Isn't it better than textual search from swank-clojure?

expez commented 6 years ago

@bkruczyk it has to evaluate all the code to understand it.

ailisp commented 6 years ago

@bkruczyk swank also need to load all common lisp code in slime repl before cross reference. But that's not a problem for cl, because there's a different workflow between cl and clj. CL programmers have habit to load all project files from slime-repl using (ql:quickload ...) or (asdf:load-system ...) before doing any development). In clojure, nrepl was launched from from shell and didn't load the whole project. Unless you load the whole system in repl, the cross reference is like doing so in python or ruby, which is quite inaccurate.

stardiviner commented 6 years ago

If so, then is it possible to provide two solution. use textual search by default. (As @ailisp upper said) And provide this load a whole project solution as an optional solution for users who want it like me. CIDER can provide two different keybinding for them.

bbatsov commented 6 years ago

@bkruczyk swank also need to load all common lisp code in slime repl before cross reference. But that's not a problem for cl, because there's a different workflow between cl and clj. CL programmers have habit to load all project files from slime-repl using (ql:quickload ...) or (asdf:load-system ...) before doing any development). In clojure, nrepl was launched from from shell and didn't load the whole project. Unless you load the whole system in repl, the cross reference is like doing so in python or ruby, which is quite inaccurate.

@ailisp We already have functionality to load the entire project if necessary, so that's not a big deal. I don't think swank-clojure was doing this for Clojure, and people were kind of OK with the feature, though, so I don't think that's a big deal.

@stardiviner The textual search is pretty much the same approach. It's not really related to loading everything or not. It's just a way to try to find call site for some functions.

ailisp commented 6 years ago

@stardiviner That's really a good idea. I prefer to use a same key binding to do semantic search first and if nothing found fall over to text search though. But this is trivial to do in init file after implement both options.

gerdint commented 6 years ago

1+ for having this!

Geiser implements this but I do believe it relies on the underlying Scheme for doing it accurately.

harold commented 1 year ago

Just discovered this today, and it's great! Thanks @bbatsov :bow: