How to get IntelliSense to reliably work in Visual Studio 2008

后端 未结 12 1557
暗喜
暗喜 2020-12-08 04:13

Does anyone know how to get IntelliSense to work reliably when working in C/C++ projects? It seems to work for about 1 in 10 files. Visual Studio 2005 seems to be a lot bett

相关标签:
12条回答
  • 2020-12-08 04:38

    I have recently studied Intellisense in VS2008, as I'm developing a rather large C++ numerical linear algebra library where templates and such are used extensively. Intellisense stopped working shortly into the project and I sort of gave up, but now it became really annoying without it so I set to investigate. This is what I found out:

    Assuming there is a file(s), containing code that "breaks" Intellisense,

    • if header files that break Intellisense are in the project, but are not #included, it still works in the rest of the files
    • if they are included, but no type declared inside is used, it still works
    • if they are included and a type declared inside is used, it might still work a bit (no Intellisense for members, no Intellisense after occurrence of given type, but at least global names and argument info before)
    • if Intellisense is broken in one .cpp file, it can still work in the others where the problematic code is not included or used (but i imagine if it crashes bad, it will get disabled for the whole project, although that did not happen to me)
    • Intellisense seems to be updated after successful compilation (sometimes not before)
    • putting broken code inside any of #if 0, /* .. */ or // seems to put Intellisense at ease

    From the C++ features I used, actually only a few break Intellisense:

    • comparison with '>' or '>=' in template parameter (e.g. static_assert<(size > 0)>)
      • not solved by using double parentheses (static_assert<((size > 0))> does not help)
      • solved by using '<' or '<=' instead (static_assert<0 < size> works)
      • solved by storing the value in enum and using that to specialize the template
    • explicit function template specialization disables argument info (e.g. function<type>(args))
      • probably unable to solve (maybe wrap in a macro), but I can live with it being broken
    • instantiation of template member type, such as Matrix::MakeMatrixType<3, 3>::Result r;
      • kind of hard to figure out exactly why this happens (likely because of use of Eigen)
      • workaround by moving such code in a separate .cpp where IS won't work (not always possible)

    It would seem that some of those problems are due to some "simplified" parsing, which is less strong than a proper C++ parser. With the above information at hand, a "reliable" method of making Intellisense work in an existing code:

    1. Set up an empty project (a console app), create Main.cpp with dummy void main() {} in it.
    2. Include one of your broken header files, and math.h
    3. Build (it must compile, in order for Intellisense to update reliably)
    4. Test whether Intellisense is working by typing e.g. sin( and seeing if argument help pops up. Sometimes, this would work, but member help wouldn't - so try that as well.
    5. Make an instance of something in the header file, build, see if that manages to kill IS.
    6. Remove code from the culprit file and go to step 3
    7. After finding and fixing problematic code, put back code removed in step 5, try again
    8. After making a whole class work well, make an instance of the next class, and so on ...

    I found it easy this way to pinpoint locations of code that made problems (I realize that this might be unfeasible for really large projects, in my case only a single file out of 97 made problems). Note that 'Build' here refers to compiling, the linking stage does not need to finish, so unresolved externals are ok, the IS should update regardless.

    Another method of updating IS (other than building) is to save everything, close workspace, delete .ncb file and reopen it. Then wait for 'Updating Intellisense ... (N)' to disappear from the status bar (N counts towards zero, if it doesn't go all the way, it kind of shows progress where problems occurred). I found this rather tedious.

    0 讨论(0)
  • 2020-12-08 04:40

    @John Richardson / @Jonathan Holland

    My includes are setup correctly, no problems there. I've also tried the NCB rebuild several times but it never fixes it 100%.

    I have a feeling it may be to do with forward declarations of classes. e.g. to reduce the complexity of includes in header files we normally do something like:

    class MyPredeclared;
    
    class SomeOtherClass
    {
    private:
        MyPredeclared* m_pPointer;
    }
    

    I wonder if that screws it up? Any other ideas? It definitely gets worse the larger your project gets.

    0 讨论(0)
  • 2020-12-08 04:42

    I've also realized than Intellisense is sometime 'lost', on some big project. Why? No idea.

    This is why we have bought Visual Assist (from Tomato software) and disabled Intellisense by deleting the dll feacp.dll in the Visual studio subdirectory (C:\Program Files\Microsoft Visual Studio 8\VC\vcpackages)

    This is not a solution, just a workaround.

    0 讨论(0)
  • 2020-12-08 04:43

    I don't use VS2008 for C++, only VB & C#, but I find that when intellisense stops working (true for VS2003/2005/2008) it's because something in the project/file is broken - usually a bad reference or code.

    VB and C# have much better intellisense support due to the ability to reflect on the referenced assemblies to build the intellisense tree.

    C++ has to walk the include files for function prototypes, and if the paths are not correct it will not find all the prototype headers.

    0 讨论(0)
  • 2020-12-08 04:49

    About this problem i've notice something interesting (on Visual Studio 2010): to solve this problem i've changed #include sintax in my header files, before was (old project done with VS 2005 and reopened using VS 2010):

    #include <myfile.h> 
    

    and i fix this with:

    #include "myfile.h"
    

    After intellisense start working correctly! I hope this can help!

    0 讨论(0)
  • 2020-12-08 04:50

    It looks like there's hope on the horizon for those of us unable to obtain Visual Assist:

    Rebuilding Intellisense

    0 讨论(0)
提交回复
热议问题