Go to Declaration


#1

Hi,

I’m new to Atom. Though I’m like some features I wonder about a very basic function for a source code editor: “Go to Declaration”.
I tried different packages: the built-in “symbols view”, “goto”, “goto-definition”, none did anything.
I’m not even talking about symbols defined in other files in a project, it even doesn’t work for symbols defined in the same source file.
I looked around and find some discussions about this function, but none pointed me to a solution.

Some facts:
Atom 1.29.0
WIN7
Currently I’m using Atom for C-langugae

Any help would be appreciated.

Christian


#2

Tried the same on another computer, running Ubuntu 18.04.
Here I edit PHP.
The effect is the same.
With “goto-definition” and “hyperclick” I can cmd + click symbols, but I always get the message: “No definition found”. Even for e.g. variables that are declared in the same file.
Seems like I have to kind of “index” my project first. Any idea how to solve that? Thanks!


#3

Do you have an example file I can try out? If you an specific repro steps for the example, that would be helpful too.


#4

Hi Robert,
1st of all: thank you very much for trying to help!

Actually I used finally a very simple file for testing.
Since I’m new to this discussion forum I have a -hopefully not too stupid - question: how can I send you the file? :thinking:
I can’t find an attachment function.

Actually I’m not sure about your 2nd sentence. Could you rephrase it?


#5

how can I send you the file?

It sounds like it’s small enough to be pasted here. Please make sure you wrap it with ``` to ensure it’s formatted correctly (check the preview before posting). If the file is ever too large, the issue can normally be isolated to a small chunk of text anyway.

Actually I’m not sure about your 2nd sentence

He’s asking for a list of instructions to follow, so he can reproduce the issue too. Try to provide the exact steps you take, and what you expect / actually happens.


#6

Ok, I understand.
Here is the pretty simple test file I’m using:

float global_testvariable_2;


void Test()
{
    // Declaration Of Local Variables
    int Testvariable_1;

    Testvariable_1 = 5;
    globale_testvariable_2 = 1.0;
}

I have installed Atom and the package atom-ide-ui.
When I place the cursor (or highlight the complete name) in one of the variables and do right click / Go to Declaration I expect the cursor to jump to the variable’s declaration (in the same file).
Instead nothing happens.
When I ctrl / clicked the 1st time on a symbol a blue message window is shown top right, explaining that: Hyperclick (jump to definition) is using control + click. Besides that nothing happened on ctrl / click.

I installed in addition the package ide-cpp.
Here I’m not sure which package to use, in the description of the package it’s “extremely experimental” nature is mentioned.
I also installed LLVM, since this package needs a file called clangd.exe.
With this package installed all occurrence of a symbol are highlighted when I place the cursor in a symbol.
Neither right click / Go to Declaration nor ctrl / click produces any results.
After searching around I installed 3, 4 other packages, but none gave the intended result.

Hope this is the information you guys requested.


#7

Had a chance to try a few things out:

Go To Declaration is a function of the Symbols View package which requires using ctags to generate a tags file first (https://flight-manual.atom.io/using-atom/sections/moving-in-atom/#navigating-by-symbols). atom-ide-ui and ide language packages uses hyperclick.

Using your example file, I generated a tags file by running ctags * in the directory with the example file. After restarting Atom, Go To Declaration worked with the global_testvariable_2 global (after fixing the spelling, it has an extra e).

About ide-cpp, it might just not support hyperclick right now since it’s in early development. Maybe you can try https://atom.io/packages/ide-clangd?


#8

Thank you very much, I used ctags and something changed.
Now I get all the files’s symbol with Ctrl +R and all project’s symbols with Ctrl + Shift + R. If I click on one of the listed symbols, the cursor jumps to its decleration.
Also a basic auto-completion works.
But Go to Decleration does still not work :roll_eyes:.
I tried ide-clangd, too.

Any additional idea what I can try?


#9

But Go to Decleration does still not work :roll_eyes:.

Hmm, does that not work with your example after generating the tags file? I just tried with the global global_testvariable_2 and it worked.

I did find that local variables need an additional flag though (Go to Declaration didn’t work initially for Testvariable_1) with ctags --c-types=+l *.

I tried ide-clangd, too.

I haven’t tried that package myself (I think I had issues with clangd on my computer) so I don’t know what the issue is there but you could open an issue on the package repository?


#10

Hi again,

I guess I found (at least one of) the issue(s) I had.
I tripped over this post: https://github.com/atom/symbols-view/issues/108

Instead of calling ctags from where it is located with a path to my source files, I did it the other way round and called ctags with the path to its location from the source root directory.
Now I can navigate to declarations inside and outside a file.
For that even no additional package is needed, it works with the packages provided by atom-ide-ui.

What I still miss is the Ctrl + click working as Go To Definition,

Maybe someone has a hint for that problem?

And I have 2 practical questions:

  • Do have to run ctags all the time when I add a new symbol?
    Or is there a way to have that done “automatic”?

  • When searching in the complete project (Ctrl + Shift + F) it also looks through the tags-file.
    On the one hand it’s confusing, since the tags-file has of course all symbols, so it will always find something.
    On the other hand it takes time to search through this (usually big) file.
    Of course I can always specify to look only in certain file types (*.c, *.h, *.xml), but it is not very convenient.
    Is there another way to exclude the tags-file from a search?


#11

Hmmm, worked fine for my little test setup with 3 small c-files and 2 h-files.
But it fails with a much bigger (real) project.
But it seems to be an issue with ctags (or how I use it). But I guess I have to figure that out on my own.

Anyhow, I’m not sure about your (rsese) advice to use ctags with options --c-types=+l * .
I can not find the option --c-types, neither in the --help output of ctags nor in the man-page.
Are you sure that is what you used?


#12

Just to mention up front, I haven’t personally used ctags, I’ve been testing things out and searching around. But yes, my understanding is that you would need to continually run ctags and there are different articles around that talk about ways of automating that (e.g. https://tbaggery.com/2011/08/08/effortless-ctags-with-git.html if you’re working on a Git project). Also, I haven’t tried it out, but this package mentions auto-updating a files tag data on save: https://atom.io/packages/atom-ctags

Yes, you can add a filename to Settings > Core > Ignored Names and it will be ignored in find and replace and other functionality (see the setting description).

Ahhh sorry, I don’t remember where I found that reference (and can’t find it now) I should have linked it above. I just remember testing it and finding that Go To Declaration didn’t work with the local variable initially but then did after I tried that option.


#13

I think I found the main issue I still had.
I used the --languages=C option for ctags, since there are a lot of other files in my project (*.py, *.xml).
What I didn’t know is, that for “C” ctags does not tag *.h-files, hence I was missing a lot of definitions.
I changed to --languages=C++ and now *.h-files are tagged, too.

It’s true, atom-ctags offers a menu entry to rebuild the tags-file and it also does it automatically from time to time (I can easily follow it, since my anti-virus software fires a warning each time ctag runs :confused:).

Ignored Names works fine, too.

The only missing thing is now ctrl-click to go to definitions, but I guess sooner or later I will find out how to activate that.

So far I consider this as “solved”.
Thank you for your help (specifically to rsese)!