Skip to content

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

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

Closed
stardiviner opened this issue Sep 2, 2016 · 25 comments

Comments

@stardiviner
Copy link
Contributor

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

grammati commented Sep 2, 2016

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

@grammati Thanks.

@timvisher
Copy link

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

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

@stardiviner stardiviner reopened this Sep 2, 2016
@bbatsov
Copy link
Member

bbatsov commented Sep 2, 2016

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

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

bbatsov commented Sep 2, 2016

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

bbatsov commented Sep 3, 2016

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

@sanjayl
Copy link
Contributor

sanjayl commented Sep 4, 2016

Will take a look at it

@ckoparkar
Copy link

ckoparkar commented Sep 4, 2016 via email

@johngit22
Copy link

Thanks !

On Sun, Sep 4, 2016 at 6:52 AM, Chaitanya Koparkar <[email protected]

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
#1840 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ADFz2XEZMczlC33SSuV1vmrP7rqf2Vi0ks5qmqL0gaJpZM4Jzi0S
.

John Boyd

@bbatsov
Copy link
Member

bbatsov commented Sep 15, 2016

@sanjayl Thanks for tackling this!

@bbatsov
Copy link
Member

bbatsov commented Mar 2, 2017

@sanjayl any news on this?

@sanjayl
Copy link
Contributor

sanjayl commented Mar 3, 2017

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

bbatsov commented Mar 4, 2017

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

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

@bbatsov
Copy link
Member

bbatsov commented Oct 15, 2017

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

bkruczyk commented Oct 22, 2017

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

expez commented Oct 22, 2017

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

@ailisp
Copy link

ailisp commented Dec 5, 2017

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

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

bbatsov commented Dec 5, 2017

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

ailisp commented Dec 6, 2017

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

gerdint commented Jul 3, 2018

1+ for having this!

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

@harold
Copy link
Contributor

harold commented Jan 24, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests