自定义默认设置
您可以覆盖在 c_cpp_properties.json
中设置的属性的默认值。
Visual Studio Code 设置
以下 C_Cpp.default.*
设置映射到 c_cpp_properties.json
的配置块中的每个属性。即
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 设置中的值。如果开发人员为给定文件夹的所有适用设置分配了值,则可以从 .vscode 文件夹中删除 c_cpp_properties.json
,因为它将不再需要。
有关 c_cpp_properties.json 设置文件的深入信息,请参阅c_cpp_properties.json 参考。
系统包含目录
将添加一个新设置,允许您指定与文件夹的包含目录分开的系统包含目录。如果此设置具有值,则扩展从 compilerPath
设置中指定的编译器获得的系统包含目录将不会添加到扩展用于 IntelliSense 的路径数组中。我们可能希望提供一个 VS Code 命令,以便从编译器的默认值填充此值,以供有兴趣使用它的用户在想要对默认值进行一些修改时使用。
C_Cpp.default.systemIncludePath : string[]
系统包含目录/定义解析策略
扩展程序通过以下方式确定系统 includePath 和 defines 并将其发送到 IntelliSense 引擎
-
如果
compileCommands
具有有效值,并且编辑器中打开的文件在数据库中,请使用数据库条目中的编译命令来确定包含目录和定义。- 系统包含目录和定义使用以下逻辑确定(按顺序)
- 如果
systemIncludePath
具有值,请使用它(继续下一步搜索系统定义)。 - 如果
compilerPath
有效,请查询它。 - 将命令中的第一个参数解释为编译器,并尝试查询它。
- 如果
compilerPath
为“”,则对系统包含目录和定义使用空数组。 - 如果
compilerPath
未定义,请在系统上查找编译器并查询它。
- 如果
- 系统包含目录和定义使用以下逻辑确定(按顺序)
-
如果
compileCommands
无效或当前文件未在数据库中列出,请对 IntelliSense 使用配置中的includePath
和defines
属性。- 系统包含目录和定义使用以下逻辑确定(按顺序)
- 如果
systemIncludePath
具有值,请使用它(继续下一步搜索系统定义)。 - 如果
compilerPath
有效,请查询它。 - 如果
compilerPath
为“”,则对系统包含目录和定义使用空数组(假定它们已在当前配置的includePath
和defines
中)。 - 如果
compilerPath
未定义,请在系统上查找编译器并查询它。
- 如果
- 系统包含目录和定义使用以下逻辑确定(按顺序)
系统包含目录不应添加到 includePath
或 browse.path
变量中。如果扩展检测到 includePath
属性中有任何系统包含目录路径,它将静默删除它们,以便它可以确保系统包含目录路径最后添加并按正确的顺序添加(这对于 GCC/Clang 尤其重要)。
增强的语义着色
启用 IntelliSense 后,Visual Studio Code C/C++ 扩展支持语义着色。有关设置类、函数、变量等颜色的更多详细信息,请参阅增强的着色。
扩展日志记录
如果您在使用扩展时遇到问题,而我们无法根据您的问题报告中的信息进行诊断,我们可能会要求您启用日志记录并将日志发送给我们。有关如何收集日志的信息,请参阅C/C++ 扩展日志记录。