Includepath vs code linux

Customizing default settings

You can override the default values for properties set in c_cpp_properties.json .

Visual Studio Code settings

The following C_Cpp.default.* settings map to each of the properties in a configuration block of c_cpp_properties.json . Namely:

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 

These settings have all of the benefits of VS Code settings, meaning that they can have default, «User», «Workspace», and «Folder» values. So you can set a global value for C_Cpp.default.cppStandard in your «User» settings and have it apply to all of the folders you open. If any one folder needs a different value, you can override the value by adding a «Folder» or «Workspace» value.

This property of VS Code settings allows you to configure each of your workspaces independently — making the c_cpp_properties.json file optional.

Updated c_cpp_properties.json syntax

A special variable has been added to the accepted syntax of c_cpp_properties.json that will instruct the extension to insert the value from the VS Code settings mentioned above. If you set the value of any setting in c_cpp_properties.json to «$» it will instruct the extension to read the VS Code default setting for that property and insert it. For example:

"configurations": [   "name": "Win32", "includePath": [ "additional/paths", "$"  ], "defines": [ "$"  ], "macFrameworkPath": [ "$", "additional/paths"  ], "forcedInclude": [ "$", "additional/paths"  ], "compileCommands": "$", "browse":  "limitSymbolsToIncludedHeaders": true, "databaseFilename": "$", "path": [ "$", "additional/paths"  ]  >, "intelliSenseMode": "$", "cStandard": "$", "cppStandard": "$", "compilerPath": "$"  > ], 

Note that for the properties that accept string[], the syntax proposed above allows you to augment the VS Code setting with additional values, thus allowing you to have common paths listed in the VS Code settings and configuration-specific settings in c_cpp_properties.json .

If a property is missing from c_cpp_properties.json , the extension will use the value in the VS Code setting. If a developer assigns values to all of the settings that apply for a given folder, then c_cpp_properties.json could be removed from the .vscode folder as it will no longer be needed.

For in-depth information about the c_cpp_properties.json settings file, See c_cpp_properties.json reference.

System includes

A new setting will be added that allows you specify the system include path separate from the folder’s include path. If this setting has a value, then the system include path the extension gets from the compiler specified in the compilerPath setting will not be added to the path array that the extension uses for IntelliSense. We may want to provide a VS Code command to populate this value from the compiler’s default for users who are interested in using it in case they want to make some modifications to the defaults.

C_Cpp.default.systemIncludePath : string[] 

System include path/defines resolution strategies

The extension determines the system includePath and defines to send to the IntelliSense engine in the following manner:

  1. If compileCommands has a valid value and the file open in the editor is in the database, use the compile command in the database entry to determine the include path and defines.
    • The system include path and defines are determined using the following logic (in order):
      1. If systemIncludePath has a value, use it (continue to the next step to search for system defines).
      2. If compilerPath is valid, query it.
      3. Interpret the first argument in the command as the compiler and attempt to query it.
      4. If compilerPath is «», use an empty array for system include path and defines.
      5. If compilerPath is undefined, look for a compiler on the system and query it.
      • The system include path and defines are determined using the following logic (in order):
        1. If systemIncludePath has a value, use it (continue to the next step to search for system defines).
        2. If compilerPath is valid, query it.
        3. If compilerPath is «», use an empty array for system include path and defines (they are assumed to be in the includePath and defines for the current config already).
        4. If compilerPath is undefined, look for a compiler on the system and query it.

      System includes should not be added to the includePath or browse.path variables. If the extension detects any system include paths in the includePath property it will silently remove them so that it can ensure system include paths are added last and in the correct order (this is especially important for GCC/Clang).

      Enhanced semantic colorization

      When IntelliSense is enabled, the Visual Studio Code C/C++ extension supports semantic colorization. See Enhanced colorization for more details about setting colors for classes, functions, variables and so on.

      Extension logging

      If you are experiencing a problem with the extension that we can’t diagnose based on information in your issue report, we might ask you to enable logging and send us your logs. See C/C++ extension logging for information about how to collect logs.

      Источник

      Visual Studio Code: How to configure includePath for better IntelliSense results

      I am a complete beginner to using Visual Studio Code and I have no clue what I am doing. I’ve searched around (maybe not enough), but I can’t find just a simple explanation for someone like me on how to configure the c_cpp_properties.json file that I am redirected to whenever I click on the yellow light bulb next to a line that is underlined with a green squiggle. Lightbulb example c_cpp_properties.json I just want to know what to put in the .json to make IntelliSense work properly.

      3 Answers 3

      From the official documentation of the C/C++ extension:

      Configuring includePath for better IntelliSense results

      If you’re seeing the following message when opening a folder in Visual Studio Code, it means the C++ IntelliSense engine needs additional information about the paths in which your include files are located.

      Configure includePath for better IntelliSense

      Where are the include paths defined?

      The include paths are defined in the «includePath» setting in a file called c_cpp_properties.json located in the .vscode directory in the opened folder.

      You can create or open this file by either using the «C/Cpp: Edit Configurations» command in the command palette or by selecting «Edit «includePath» setting» in the light bulb menu (see the screenshot below). The quickest way to locate a light bulb is to scroll to the top of the source file and click on any green squiggle that shows up under a #include statement.

      lightbulb menu

      When a folder is opened, the extension attempts to locate your system headers based on your operating system, but it does not know about any other libraries that your project depends on. You can hover over the green squiggles or open the Problems window to understand which headers the IntelliSense engine is unable to open — sometimes it’s the dependent headers that can’t be located.

      include error message

      How can I specify the include paths?

      You can specify the remaining paths using one of the techniques described below.

      1. Use compile_commands.json file to supply includePaths and defines information The extension can get the information for «includePath» and «defines» from a compile_commands.json file, which can be auto-generated by many build systems such as CMake and Ninja. Look for the section where your current configuration is defined (by default there’s one configuration per operating system, such as «Win32 or «Mac»), and set the «compileCommands» property in c_cpp_properties.json to the full path to your compile_commands.json file and the extension will use that instead of the «includes» and «defines» properties for IntelliSense. use compileCommands setting
      2. Use the light bulb suggestions to auto-resolve includePath The first thing to try is to leverage the light bulb path suggestions to auto-resolve the include paths. When you open a folder, the extension will recursively search for potential include paths that match the header files your code is using based on the paths set by the «browse.path» setting in c_cpp_properties.json. Click on the green squiggles under #include statements and you’ll see a light bulb offering suggestions of paths that will allow IntelliSense to resolve the included file. lightbulb suggestionsIf you don’t see path suggestions in the light bulb, try adding the root folder where the headers are likely located in to the «browse.path» setting in c_cpp_properties.json. This allows the extension to recursively search in these folders and offer more suggestions in the light bulb as the search process goes on.
      3. Manually add include paths If none of the above fully resolves the paths, you could manually specify the paths to the headers that your project depends on in the c_cpp_properties.json file. Look for the section where your current configuration is defined (by default there’s one configuration per OS, such as «Win32 or «Mac»), and add your paths in the «includePath» setting and defines in the «defines» setting. For example, the following screenshot shows a snippet of the file specifying path for the Mac configuration. Also, for MinGW, as the documentation of the extension explains you may ask gcc/g++ to list its own include files:

      c_cpp_properties file snippet

Verify the include paths are correctly resolved

There are two ways to verify that the include paths are correctly resolved:

  1. The green squiggles in the source file are no longer showing
  2. Error messages are cleared in the Problems window

This indicates that the IntelliSense engine has got the include paths resolved so you can start enjoying the full IntelliSense for your C or C++ code for the current translation unit. Note that you may still see errors on other files if they belong to a different translation unit that requires additional include paths to be configured.

Источник

Читайте также:  Google chrome linux amd64
Оцените статью
Adblock
detector