I need a little help with the Go-to-declaration functionality


#1

I have freshly started using Atom, and currently i am running into issues with going to function declarations.

Firstly, the Go to declaration option, which pops up when right-clicking inside a document, doesn’t work (it doesn’t do anything at all). In addition to that, it seems to not actually be “smart” about the context of where i’ve right-clicked. Compared to Sublime text, it would only offer its Goto definition option if i right-click on an actual function call, or a class name. Atom on the other hand, always offers its Go to declaration option in the context dropdown menu.

And secondly i have a question about jumping to function declarations when searching. Coming from Sublime text, when searching with Ctrl+P after a class name, i could then add @functionName to jump to that function declaration right away after clicking Enter. I’ve tried a couple of characters in Atom, but none seem to have that functionality. It is the equivalent of invoking Ctrl+R after already having the file open, but faster if you could specify it in the search bar already. Does that functionality exist?


#2

Firstly, the Go to declaration option, which pops up when right-clicking inside a document, doesn’t work (it doesn’t do anything at all).

Which ide package are you using (I’m assuming you’re using the Atom IDE functionality)? Also, can you share a test file that demonstrates the behavior?

In addition to that, it seems to not actually be “smart” about the context of where i’ve right-clicked. Compared to Sublime text, it would only offer its Goto definition option if i right-click on an actual function call, or a class name. Atom on the other hand, always offers its Go to declaration option in the context dropdown menu.

That seems like good feedback, I believe an enhancement request would go in:

And secondly i have a question about jumping to function declarations when searching. Coming from Sublime text, when searching with Ctrl+P after a class name, i could then add @functionName to jump to that function declaration right away after clicking Enter. I’ve tried a couple of characters in Atom, but none seem to have that functionality. It is the equivalent of invoking Ctrl+R after already having the file open, but faster if you could specify it in the search bar already. Does that functionality exist?

Do you mean symbols navigation but from find and replace?


#3

Which ide package are you using (I’m assuming you’re using the Atom IDE functionality)? Also, can you share a test file that demonstrates the behavior?

Yes, Atom IDE.

As for a test file, I’ve tried it with 2 simple files just now, and it still doesn’t work.

Contents of first file:

<?php

function hello() {
	return 'Hello';
}

Contents of second file:

<?php

print hello();

It recognises the syntax correctly, because it says PHP in the bottom right in the status bar. But right-clicking on the call of hello() in the second file, then selecting “Go to declaration” does nothing.

Actually copying the code from Atom didn’t work just now when I was going to paste it here… Is Atom not well supported on Linux perhaps? Because I’m running this on Ubuntu.

Do you mean symbols navigation but from find and replace?

No, not Find and replace, but the thing that pops up on Ctrl+P. Apparently it’s called “Fuzzy finder”.

So what Sublime would allow you to do from there is jump to a specific function declaration in a file from there. So let’s say there’s a Core.php file in your project:

  • So Ctrl+P, enter Core, press Enter, you end up in your Core.php file with the cursor at the beginning of the file.
  • Then Ctrl+P, enter Core@render, press Enter, you end up in the Core.php file, but scrolled down to, and with the cursor on, the declaration of function render().

#4

Hello.

That is probably the default non IDE version being listed there.

From my understanding there are two steps… have Atom IDE and have the language service.

Perhaps additionally look here:

If I am aiming in the wrong direction, please could you include a screen capture so that others can have a visual clue of what you configuration look like.

Regards.


#5

Firstly, the Go to declaration option

Oh sorry, I just re-read your initial message - Go to Declaration isn’t an Atom IDE function, it’s from https://github.com/atom/symbols-view. Hyperclick should work for you though - in your second file, click on hello() and then run Hyperclick: Confirm Cursor (or you can ctrl-click on Linux) and that should take you to the definition in your first file.

No, not Find and replace, but the thing that pops up on Ctrl+P. Apparently it’s called “Fuzzy finder”.

So what Sublime would allow you to do from there is jump to a specific function declaration in a file from there. So let’s say there’s a Core.php file in your project:

Ahhh gotcha, thanks for clarifying - this isn’t possible with core Atom, there’s an existing feature request for this here however:

There may be a community package that offers some of this functionality but I’m not familiar with any myself.