Sublime Forum

Autocomplete across files

#1

Hi, What are some good tricks to getting autocomplete and GoToDefinition working across files within the same project?
Sorry this is a newbie question, I just started evaluating sublime and I assume it is meant to allow cross-file operations.
Problem 1: Autocomplete in a *.cc file does not know about symbols in an included header file.
Problem 2: /Goto/GotoDefinition works OK if the symbol is in the same file but not elsewhere in the project.
Some guesses - tell me if these are good directions to troubleshoot:
Maybe sublime does not follow the include path for #include, but I also tried using just #include “foo.h” without any directory.
Maybe the code is too complex to parse because it uses C++ templates and stl. The color coding is odd, it seems to use green for functions but with templates only the destructors and some random members in the intializer list are green.
Below shows the general type of problem I have, but this simple example seems to work ok making me think there is something about my files or configuration.

Example:

//foo.h:
class Foo {
    Foo::Foo();
    int mSomeVariable;
};

void Bar() { 
    // Here sublime has autocomplete for mSomeVariable even though it is out of scope.
}

// foo.cc:
#include "foo.h"
Foo::Foo() 
    : mSomeVariable(0)   // Here sublime autocomplete has no knowledge of mSomeVariable
{ }

Sublime Text : build 3083, no packages
OS: Linux Mint
My project uses cmake.

0 Likes

#2

ad 1: github.com/alienhard/SublimeAllAutocomplete
ad 2: Drag the project folder containing all your source and header files into the side bar. Sublime Text then indexes all files and go to definition works across files. Optionally you might also want to take a look at github.com/SublimeText/CTags

0 Likes

#3

Hi Markus, thanks for your help. AllAutocomplete seems to be working as advertised, and I can control the list of open files. (I like the list on the sidebar next to the project folder tree.)
It is very helpful to know what to expect.

After I posted this question, I read about trying to reindex by closing all files and restarting. After I did that, F12 (GoToDefinition) seemed to work again across the entire project.

I installed the CTags sublime package. But Exuberant ctags has not been updated in years, and seems not able to parse my code.
It is easy to troubleshoot by looking at the generated file.
There has been some work to use libclang to parse the project so I might try that route.

Thanks,
– Eric

0 Likes