Sublime Forum

"Goto Definition" finds every matching instance in project

#1

Hello,
I have a large c++ project (with lots of inheritance) which I would like to navigate using the “Goto Definition” feature in Sublime Text 3. However, when I try to use this feature every matching instances of the function/variable I have selected is found instead of just the definition. For instance in the simple example below if i click “Goto Definition” on the function RunOnce, I can jump between all 3 locations where the function name is used. Ideal I want to just jump the the actual definition of the function. This presents an issue when I try to go to the definition of a function in a particular derived class, and ALL the other derived classes definitions appear as well.

Has anyone encountered this problem before?

Thanks in advance!

// ----------------------------------------------------------------------------------

class classA
{
public:
classA();
~classA();

auto Run(int number_of_runs) -> int;

private:

auto RunOnce() -> int;

int a;

};

// ----------------------------------------------------------------------------------
#include “classA.h”

classA::classA(){};
classA::~classA(){};

auto classA::Run(int number_of_runs) -> int
{
return RunOnce();
};

auto classA::RunOnce() -> int
{
return a;
};
// ----------------------------------------------------------------------------------

0 Likes

#2

This is basically what the goto definition feature was designed to do. It doesn’t have any semantic knowledge of your code, it’s just indexing symbols. Basically like a much smarter ctags. Honestly, I find that simplicity to be extremely valuable, since semantic tooling often gets definition linkage wrong. It can be a little annoying for names that are used prolifically throughout the codebase, but in practice less than one would think.

0 Likes

Mouse-over gives wrong methods (but same method name) from other classes
#3

Ah okay! So it is working as it is suppose to.

Can you recommend a package that performs a “semantic” search of the symbols?

Thanks!

Nicholi.

0 Likes

#4

Looks like clang supports the LSP (https://langserver.org), which means you can use the LSP package for Sublime and get some semantic features (probably including error highlighting) within Sublime this way.

0 Likes

#5

Thank you for the help and the suggestion!

0 Likes