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

Possibility to find references #75

Open
ilyaguy opened this issue Mar 5, 2018 · 8 comments
Open

Possibility to find references #75

ilyaguy opened this issue Mar 5, 2018 · 8 comments

Comments

@ilyaguy
Copy link
Contributor

ilyaguy commented Mar 5, 2018

Is there any possibility to find references to symbol at point?
For example, I want to search "all child of the class".

@tam5
Copy link

tam5 commented Jul 13, 2018

@xcwen any ideas on how to implement this?

I know some other simple implementations of this would just do a grep for things that match the symbol name, though that usually has a number of false positives.

Maybe we could start with that and then narrow that list by using ac-php-find-symbol-at-point on each result and checking if it in fact should be considered a match.

Seems like there might be a better way, but maybe this could work? Thoughts?

(Actually, that alone wouldn't solve the use case mentioned above, but maybe the idea could be extend further for that)

Another possibility is to try and use cscope.

@ilyaguy
Copy link
Contributor Author

ilyaguy commented Jul 25, 2018

I solved this functionality.

  1. Added this code to the ~/.emacs/init.el (or ~/.emacs)
(require 'semantic/symref/grep)
(add-to-list 'semantic-symref-filepattern-alist  '(php-mode "*.php" "*.tpl"))
  1. Added (semantic-mode) to php-mode-hook.
  2. Then use xref-find-references when I want to search symbol at point.
    Default binding is M-?.

@tam5
Copy link

tam5 commented Jul 26, 2018

@ilyaguy thanks for your solution. I'm going to try it out for a few days.

At a first glance, it seems like its definitely useful and better than just a raw search, but it does have a bunch of shortcomings.

  1. I get some false positives and it seems like its just doing a search for the name of the symbol at point. It even matched the word in strings, though I can't seem to figure out what it considers a match vs not. I haven't used semantic nor xref before though, so possibly there is something I can do to tweak it?
  2. I assume related to 1, but it seems pretty slow.
  3. Also because 1 & 2 it doesn't seem like it would be a reliable way of determining child/parent hierarchy for classes and methods.

@ilyaguy
Copy link
Contributor Author

ilyaguy commented Jul 26, 2018

@tam5 yes, it is just grep over TAGS file. So, it has some false positives. But it is faster than grep -rni over the whole project.

xref may use different backends for search, but at this moment I don't know how to customise it or how to write new backend.

@ilyaguy
Copy link
Contributor Author

ilyaguy commented Jul 26, 2018

@tam5 I've found https://github.com/dedi/gxref
And it works much better than default one.
It finds correct references to token (classname, method, property, etc..) and ignores comments, strings and other such things.
But it uses own tags system. So, now I have in my project 3 different tags:

  1. from ctags
  2. from global tags
  3. from ac-php
    And only ac-php tags are updated automatically.

@cyrialize
Copy link

@ilyaguy You can try out ggtags: https://github.com/leoliu/ggtags

The installation method recommends installing an older version of GNU Global and ctags - I've written up instructions but haven't merged them in yet. The instructions are available on the read me of my .emacs.d: https://github.com/jonnycyr/.emacs.d

@cmatzenbach
Copy link

cmatzenbach commented Oct 22, 2018

@jonnycyr So are the gtags better than the php tags generated through the suggestions in this packages README? Also, do you need both GNU global and ctags? I thought ctags was just for c/c++ so you would need GNU global and something to generate php tags (or does ctags do that?)
Also, I checkout out your setup and was surprised to see you using lsp-php. The company completions are unusably slow (I commented on this ticket about it here ). Do you just work on small projects, or how on earth did you get it to be usable?

We need lsp and the different implementations to be finished to we can put the world of tags behind us

@cyrialize
Copy link

@cmatzenbach The ggtags package just gives you the ability to jump to variables, see occurrences of variables, etc. ac-php let’s you jump to function definitions but not variable definitions (yet).

I haven’t used ggtags in a while actually, but I believe ctags helps with php generation, I’m not quite sure.

Also, what I linked is now my old configuration. My newer one is here: https://github.com/jonnycyr/.emacs.d

I used to use lsp-php, but I stopped because of what you said - it’s really slow. It might be worth checking out eglot. I’ve been trying to use it in my spare time but I’ve run into difficulties trying to install it (I use straight.el instead of the default package manager, that may be why).

I also used to use ggtags. I was running into lagging issues so I stopped. I haven’t had time to try and fix it since then. I believe this package is the best to develop php in, I haven’t really felt the need for lsp. Then again, I haven’t used it much, so I don’t know what I’m missing.

I’d recommend checking out friends of Emacs php development, I think they’re just Emacs-php on GitHub. There’s a ton of packages being developed, phpactor (I believe) acts like lsp.

I apologize for the lack of links, I’m on mobile!

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

5 participants