Uwaga
Dostęp do tej strony wymaga autoryzacji. Może spróbować zalogować się lub zmienić katalogi.
Dostęp do tej strony wymaga autoryzacji. Możesz spróbować zmienić katalogi.
W niektórych przypadkach może być konieczne ręczne skonfigurowanie projektu C++, aby funkcja IntelliSense działała prawidłowo. For MSBuild projects (based on .vcxproj
files), you can adjust settings in project properties. For non-MSBuild projects, you adjust settings in the CppProperties.json
file in the root directory of the project. In some cases, you might need to create a hint file to help IntelliSense understand macro definitions. Środowisko IDE programu Visual Studio ułatwia identyfikowanie i rozwiązywanie problemów z funkcją IntelliSense.
Single-file IntelliSense
When you open a file that isn't included in a project, Visual Studio provides some IntelliSense support, but by default no error squiggles are shown. If the Navigation Bar says Miscellaneous Files, then that probably explains why you don't see error squiggles under incorrect code, or why a preprocessor macro isn't defined.
Sprawdzanie listy błędów
If a file isn't open in single-file mode, and IntelliSense isn't working correctly, the first place to check is the Error List window. Aby wyświetlić wszystkie błędy funkcji IntelliSense dla bieżącego pliku źródłowego wraz ze wszystkimi dołączonymi plikami nagłówka, wybierz pozycję Build + IntelliSense na liście rozwijanej:
IntelliSense produces a maximum of 1,000 errors. If there are more than 1,000 errors in the header files included by a source file, then the source file shows only a single error squiggle at the very start of the source file.
Upewnij się, że ścieżki #include są poprawne
Projekty MSBuild
If you run your builds outside of the Visual Studio IDE, and your builds are succeeding but IntelliSense is incorrect, it's possible that your command line is out of sync with the project settings for one or more configurations. Kliknij prawym przyciskiem myszy węzeł projektu w eksploratorze rozwiązań i upewnij się, że wszystkie ścieżki #include są poprawne dla bieżącej konfiguracji i platformy. Jeśli ścieżki są identyczne we wszystkich konfiguracjach i platformach, możesz wybrać Wszystkie konfiguracje i Wszystkie platformy, a następnie sprawdzić, czy ścieżki są poprawne.
To see the current values for build macros such as VC_IncludePath, select the Include Directories dropdown. Then choose <Edit> and select the Macros button.
Projekty Makefile
For Makefile projects that are based on the NMake project template, choose NMake under Configuration Properties, and then choose Include search path in the IntelliSense category:
CMake projects
For CMake projects, make sure that #include paths are specified correctly for all configurations in CMakeLists.txt
. Other project types might require a CppProperties.json
file. For more information, see Configure code navigation with CppProperties.json. Upewnij się, że ścieżki są poprawne dla każdej konfiguracji zdefiniowanej w pliku.
If there's a syntax error in the CppProperties.json
file, IntelliSense in the affected files is incorrect. Visual Studio displays the error in the Output Window.
Problemy z analizatorem tagów
The tag parser is a fuzzy C++ parser that's used for browsing and navigation. It's fast but doesn't attempt to completely comprehend every code construct.
For example, it doesn't evaluate preprocessor macros, and therefore it might incorrectly parse code that makes heavy use of them. When the Tag Parser encounters an unfamiliar code construct, it might skip that entire region of code.
Istnieją dwa typowe sposoby manifestów tego problemu w programie Visual Studio:
The IDE offers to create a function definition for a function that is already defined.
If the navigation bar shows an innermost macro, then the current function definition was skipped:
The code snippet shows a macro definition for do_if that is used inside of the function main. The tag parser doesn't understand the macro, so instead of the navigation dropdown showing that the name of the current function is main, it shows the name of the macro: do_if.
To fix these kinds of problems, add a file named cpp.hint
to the root of your solution directory. Aby uzyskać więcej informacji, zobacz Hint Files.
Tag parser errors appear in the Error List window.
Weryfikowanie ustawień projektu przy użyciu rejestrowania diagnostycznego
To check whether the IntelliSense compiler is using correct compiler options, including Include Paths and Preprocessor macros, turn on Diagnostic Logging of IntelliSense command lines in Tools > Options > Text Editor > C/C++ > Advanced > Diagnostic Logging. Set Enable Logging to True, Logging Level to 5 (most verbose), and Logging Filter to 8 (IntelliSense logging).
The Output Window now shows the command lines that are passed to the IntelliSense compiler. Oto przykładowe dane wyjściowe:
[IntelliSense] Configuration Name: Debug|Win32
[IntelliSense] Toolset IntelliSense Identifier:
[IntelliSense] command line options:
/c
/I.
/IC:\Repo\Includes
/DWIN32
/DDEBUG
/D_DEBUG
/Zc:wchar_t-
/Zc:forScope
/Yustdafx.h
This information might help you understand why IntelliSense is providing inaccurate information. For example, if your project's Include directory contains $(MyVariable)\Include
, and the diagnostic log shows /I\Include
as an Include path, it means that $(MyVariable)
wasn't evaluated, and was removed from the final include path.
Informacje o kompilacji funkcji IntelliSense
Program Visual Studio używa dedykowanego kompilatora języka C++, aby utworzyć i obsługiwać bazę danych, która obsługuje wszystkie funkcje funkcji IntelliSense. Aby zachować synchronizację bazy danych IntelliSense z kodem, program Visual Studio automatycznie uruchamia kompilacje tylko intelliSense jako zadania w tle w odpowiedzi na pewne zmiany wprowadzone w ustawieniach projektu lub plikach źródłowych.
Jednak w niektórych przypadkach program Visual Studio może nie zaktualizować bazy danych IntelliSense w odpowiednim czasie. For example, when you run a git pull
or git checkout
command, Visual Studio might take up to an hour to detect changes in the files. Możesz wymusić ponowne skanowanie wszystkich plików w rozwiązaniu, klikając prawym przyciskiem myszy węzeł projektu w eksploratorze rozwiązań i wybierając pozycję Ponownie skanuj rozwiązanie.
Troubleshoot IntelliSense build failures
An IntelliSense build doesn't produce binaries, but it can still fail. One possible cause for failure is custom .props
or .targets
files. In Visual Studio 2017 version 15.6 and later, IntelliSense-only build errors are logged to the Output window. Aby je wyświetlić, ustaw opcję Pokaż dane wyjściowe z na Rozwiązanie:
Komunikat o błędzie może zalecić włączenie śledzenia czasu projektowania.
error: Designtime build failed for project 'E:\src\MyProject\MyProject.vcxproj',
configuration 'Debug|x64'. IntelliSense might be unavailable.
Set environment variable TRACEDESIGNTIME=true and restart
Visual Studio to investigate.
If you set the environment variable TRACEDESIGNTIME
to true and restart Visual Studio, you see a log file in the %TEMP%
directory, which might help diagnose the build failure.
To learn more about TRACEDESIGNTIME
environment variable, see Roslyn and Design-time builds. Informacje w tych artykułach są istotne dla projektów języka C++.