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

Implement "jumping to declaration" on irony-server. #153

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

xuhdev
Copy link

@xuhdev xuhdev commented Dec 31, 2014

Jump to the declaration of the symbol on a specific location.

Usage: irony-server find-declaration file-path line col

Output: ("path-to-file-with-declaration" line col)

Besides it can jump to the definition of some symbols, such as macros, it's also useful to find out which header file contains declaration of a symbol.

@Sarcasm
Copy link
Owner

Sarcasm commented Jan 1, 2015

Here again I'm doubtful about the perfectness of this method.

What this returns for forward declaration?

If I have

class Foo; // in a header file

// later in a cpp file

void bar(Foo *f);

Looking for the declaration of Foo in the bar method will return what?

What happens if there are multiple forward declarations? Which one is picked?

What does is return on out-of-line definitions of methods? The docs says:

If the input cursor is a declaration or definition, it returns that declaration or definition unchanged.

If there was an Elisp part to this method to test the feature that would be great, I guess you are not too familiar with Elisp?

@xuhdev
Copy link
Author

xuhdev commented Jan 3, 2015

Yes it could take me quite a while to implement the elisp part, as I'm not too familiar with elisp. But we can use the server command line to test this feature any way.

I agree that this method is not perfect, but is useful in most cases to find out the prototype, or the header file which contains the prototype. If one really needs a perfect feature to jump to declaration, they can use rtags, which has a disadvantage of not working on Windows, and perhaps not working for a source file not managed by Makefile, Ninja, etc.

@Sarcasm
Copy link
Owner

Sarcasm commented Jan 5, 2015

Yes it could take me quite a while to implement the elisp part, as I'm not too familiar with elisp. But we can use the server command line to test this feature any way.

The thing is this is not the most useful feature to me. Sure I can certainly bind all the libclang functions into irony-server but libclang is well tested already, I don't need to test it more than that. What is needed is some well integrated logic into Emacs. I have a few already on my mind, so I'm not too keen to add an "un-perfect" feature, without the proper Elisp binding I'm sorry.

You said:

I agree that this method is not perfect, but is useful in most cases to find out the prototype, or the header file which contains the prototype.

This! This is a feature I would welcome into irony, to find the file pair to a file. We already have the compile options and what is left to do is to integrated with ff-find-other-file.

@ikirill
Copy link

ikirill commented Jan 9, 2015

Why is this using getCursorReferenced? Shouldn't this be getCursorDefinition? Its doc says that it maps cursor to the definition cursor of an entity (rather than any of a number of its declarations). For a function this is a bit useless, but for a class, isn't this what you want?

@Sarcasm
Copy link
Owner

Sarcasm commented Jan 9, 2015

It was first proposed to do this, see #152. I wasn't too fond of the gotchas that come with find-definition so find-declaration was proposed instead but I'm still not convinced enough.

@Sarcasm Sarcasm mentioned this pull request Jan 13, 2015
@xuhdev
Copy link
Author

xuhdev commented Jun 9, 2015

@Sarcasm If I add some Emacs integration, would you accept this PR, even as a temporary solution?

@Sarcasm
Copy link
Owner

Sarcasm commented Jun 9, 2015

It depends how it is implemented.

We surely could benefit from knowing the prototype under the function at point, as a side not the location could be provided and you could jump to it if you want to.

I think I can accept something like this.

FWIW, what I was waiting for in terms of source code indexer seems to be out in the wild now, http://www.kythe.io/, but it still requires a lot of work to setup and to interface in a useful way with Emacs. Sourcegraph is another contender, https://github.com/sourcegraph/emacs-sourcegraph-mode, but doesn't support C/C++ for now...

@wvxvw
Copy link

wvxvw commented Mar 3, 2016

Since I was also interested in the feature, and as of right now won't be able to contribute code, but just a suggestion: when using SLIME and wanting to go to the definition of symbol at point, SLIME would create a "slide-in" buffer and display suggestions to what one could possibly mean by "definition". Eg. say you point at a method. This could have implicit or explicit generic function definition along with a couple of concrete method definitions all applicable to the same symbol.

So, "jump to definition" wouldn't take you immediately to any one of those locations, but offer a list of choices. The ideal functionality for forward references and headers would be like that too: show the list of all things that may be relevant rather than try to guess. (Now I know that this adds complexity to implementation, but at least this solves the "how to do it" part...)

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

Successfully merging this pull request may close these issues.

4 participants