Catatan
Akses ke halaman ini memerlukan otorisasi. Anda dapat mencoba masuk atau mengubah direktori.
Akses ke halaman ini memerlukan otorisasi. Anda dapat mencoba mengubah direktori.
Dalam beberapa kasus, Anda mungkin perlu mengonfigurasi proyek C++ Anda secara manual agar IntelliSense berfungsi dengan baik. 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. IDE Visual Studio membantu Anda mengidentifikasi dan memperbaiki masalah 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.
Periksa Daftar Kesalahan
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. Untuk melihat semua kesalahan IntelliSense untuk file sumber saat ini bersama dengan semua file header yang disertakan, pilih Build + IntelliSense di menu dropdown:
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.
Pastikan jalur #include sudah benar
Proyek 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. Klik kanan pada simpul proyek di Penjelajah Solusi dan pastikan bahwa semua jalur #include benar untuk konfigurasi dan platform saat ini. Jika jalur identik di semua konfigurasi dan platform, Anda dapat memilih Semua konfigurasi dan Semua platform lalu memverifikasi bahwa jalur sudah benar.
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.
Proyek 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. Pastikan bahwa jalur sudah benar untuk setiap konfigurasi yang ditentukan dalam file.
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.
Masalah pengurai tag
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.
Ada dua cara umum di mana masalah ini bermanifestasi di 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. Untuk informasi selengkapnya, lihat Hint Files.
Tag parser errors appear in the Error List window.
Memvalidasi pengaturan proyek dengan pembuatan log diagnostik
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. Berikut adalah contoh output:
[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.
Tentang Pembangunan IntelliSense
Visual Studio menggunakan pengkompilasi C++ khusus untuk membuat dan memelihara database yang mendukung semua fitur IntelliSense. Agar database IntelliSense tetap sinkron dengan kode, Visual Studio secara otomatis meluncurkan build khusus IntelliSense sebagai tugas latar belakang sebagai respons terhadap perubahan tertentu yang dibuat dalam pengaturan proyek atau file sumber.
Namun, dalam beberapa kasus Visual Studio mungkin tidak memperbarui database IntelliSense secara tepat waktu. 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. You can force a rescan of all files in a solution by right-clicking on the project node in Solution Explorer and choosing Rescan Solution.
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. Di Visual Studio 2017 versi 15.6 dan yang lebih baru, kesalahan build khusus IntelliSense dicatat di jendela Output. Untuk melihatnya, atur Tampilkan output dari menjadi Solusi:
Pesan kesalahan mungkin menginstruksikan Anda untuk mengaktifkan pelacakan waktu desain:
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. Informasi dalam artikel ini relevan untuk proyek C++.