自定义默认设置
你可以覆盖 c_cpp_properties.json
中设置的属性的默认值。
vscode 设置
C_Cpp.default.includePath : string[]
C_Cpp.default.defines : string[]
C_Cpp.default.compileCommands : string
C_Cpp.default.macFrameworkPath : string[]
C_Cpp.default.forcedInclude : string[]
C_Cpp.default.intelliSenseMode : string
C_Cpp.default.compilerPath : string
C_Cpp.default.compilerArgs : string[]
C_Cpp.default.configurationProvider : string
C_Cpp.default.customConfigurationVariables : object | null
C_Cpp.default.cStandard : c89 | c99 | c11 | c17
C_Cpp.default.cppStandard : c++98 | c++03 | c++11 | c++14 | c++17 | c++20 | c++23
C_Cpp.default.enableConfigurationSquiggles : boolean
C_Cpp.default.mergeConfigurations : boolean
C_Cpp.default.systemIncludePath : string[]
C_Cpp.default.windowsSdkVersion : string
C_Cpp.default.browse.path : string[]
C_Cpp.default.browse.defines : string[]
C_Cpp.default.browse.dotConfig : string
C_Cpp.default.browse.databaseFilename : string
C_Cpp.default.browse.limitSymbolsToIncludedHeaders : boolean
这些设置具有 VS Code 设置的所有优点,这意味着它们可以具有默认值、"用户"、"工作区" 和 "文件夹" 值。因此,你可以在 "用户" 设置中为 C_Cpp.default.cppStandard
设置一个全局值,并使其应用于你打开的所有文件夹。如果任何一个文件夹需要不同的值,你可以通过添加 "文件夹" 或 "工作区" 值来覆盖该值。
VS Code 设置的这一特性允许你独立配置每个工作区,从而使 c_cpp_properties.json
文件成为可选项。
更新的 c_cpp_properties.json
语法
在 c_cpp_properties.json
的接受语法中新增了一个特殊变量,用于指示扩展从上述 VS Code 设置中插入值。如果你将 c_cpp_properties.json
中的任何设置的值设置为 ${default}
,它会指示扩展读取该属性的 VS Code 默认设置并插入。例如:
"configurations": [
{
"name": "Win32",
"includePath": [
"additional/paths",
"${default}"
],
"defines": [
"${default}"
],
"macFrameworkPath": [
"${default}",
"additional/paths"
],
"forcedInclude": [
"${default}",
"additional/paths"
],
"compileCommands": "${default}",
"browse": {
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": "${default}",
"path": [
"${default}",
"additional/paths"
]
},
"intelliSenseMode": "${default}",
"cStandard": "${default}",
"cppStandard": "${default}",
"compilerPath": "${default}"
}
],
请注意,对于接受 string[]
的属性,上述语法允许你在 VS Code 设置的基础上添加额外的值,从而允许你在 VS Code 设置中列出通用路径,并在 c_cpp_properties.json
中设置特定于配置的路径。
如果 c_cpp_properties.json
中缺少某个属性,扩展将使用 VS Code 设置中的值。如果开发人员为某个文件夹的所有适用设置分配了值,那么可以将 c_cpp_properties.json
从 .vscode
文件夹中移除,因为它将不再需要。
有关 c_cpp_properties.json
设置文件的详细信息,请参见 c_cpp_properties.json 参考。
系统包含
将新增一个设置,允许你将系统包含路径与文件夹的包含路径分开指定。如果该设置有值,则扩展从 compilerPath
设置中指定的编译器获得的系统包含路径将不会添加到扩展用于 IntelliSense 的路径数组中。如果用户希望使用编译器的默认值,并对默认值进行一些修改,我们可能会提供一个 VS Code 命令来填充此值。
- C_Cpp.default.systemIncludePath :
string[]
系统包含路径/定义解析策略
扩展以以下方式确定要发送到 IntelliSense 引擎的系统 includePath
和定义:
- 如果
compileCommands
有有效值且编辑器中打开的文件在数据库中,使用数据库条目中的编译命令来确定包含路径和定义。 - 使用以下逻辑(按顺序)确定系统包含路径和定义:
- 如果
systemIncludePath
有值,则使用它(继续到下一步以搜索系统定义)。 - 如果
compilerPath
有效,查询它。 - 解释命令中的第一个参数作为编译器并尝试查询它。
- 如果
compilerPath
为""
,使用空数组作为系统包含路径和定义。 - 如果
compilerPath
未定义,查找系统上的编译器并查询它。 - 如果
compileCommands
无效或当前文件未列在数据库中,使用配置中的includePath
和定义属性进行 IntelliSense。
- 如果
系统包含路径和定义的确定使用以下逻辑(按顺序):
- 如果
systemIncludePath
有值,则使用它(继续到下一步以搜索系统定义)。 - 如果
compilerPath
有效,查询它。 - 如果
compilerPath
为""
,使用空数组作为系统包含路径和定义(它们已经被认为在当前配置的includePath
和定义中)。 - 如果
compilerPath
未定义,查找系统上的编译器并查询它。
系统包含不应添加到 includePath
或 browse.path
变量中。如果扩展在 includePath
属性中检测到任何系统包含路径,它会静默地将其移除,以确保系统包含路径最后添加且顺序正确(这对于 GCC/Clang 特别重要)。
增强的语义着色
启用 IntelliSense 时,Visual Studio Code C/C++ 扩展支持语义着色。有关为类、函数、变量等设置颜色的更多详细信息,请参见 增强的着色。
扩展日志记录
如果你遇到扩展无法仅凭你的问题报告中的信息诊断的问题,我们可能会要求你启用日志记录并向我们发送日志。有关如何收集日志的信息,请参见 C/C++ 扩展日志记录。