Skip to content

Automatically add "${default}" when generating c_cpp_properties.json and a C_Cpp.default.* property is set #3733

@dacut

Description

@dacut

Type: LanguageService

This is coming from a new C/C++ user of VSCode (I've coded in C/C++ for a long time, and in VSCode for other languages for a couple years now), but I found this unintuitive (= spent an hour pulling my hair out). Some of it is definitely confusion over where pieces of VSCode live and what belongs to whom, but it's just from installing the "C/C++ extension" to do C/C++ development.

Describe the bug

  • OS and Version: Ubuntu 18.04.2 (Kernel 4.15.0-1038-oem)
  • VS Code Version: 1.35.0-insider, commit 8a737015d
  • C/C++ Extension Version: 0.23.1
  • Other extensions you installed (and if the issue persists after disabling them):
    • Docker 0.6.2
    • GitLens 9.8.1
    • Go 0.10.2,
    • Python 2019.5.18426
    • Remote - Containers 0.59.0
    • Remote - SSH 0.42.0
    • Remote - SSH: Editing Configuration Files 0.42.0
    • Remote - SSH: Explorer 0.42.0
    • Remote - WSL 0.38.0
    • Remote Development 0.15.0
    • Rust (rls) 0.6.1
    • Terraform 1.3.11
    • YAML 0.4.1
  • A clear and concise description of what the bug is.
    Intellisense does not examine/respect/yell at silly users who update the C_Cpp.default.includePath setting in settings.json in a way that conflicts with includePath in c_cpp_properties.json.

To Reproduce

  1. Create a file that includes something from a non-default include path:
    #include <gtk/gtk.h>
    
  2. Intellisense squiggle-highlights this: cannot open source file "gtk/gtk.h"
  3. Create a default c_cpp_properties.json file (accidentally) by invoking the UI. I got there through a tooltip in the lower-right corner, but this is displayed inconsistently; to consistently get there, invoked the command C/C++: Edit configurations (UI).
  4. Place the wrong directory into the "Include path" section: /usr/include.
  5. Close the UI. (And being a newbie, immediately forget the command to reinvoke this dialog window.)
  6. Intellisense again squiggle-highlights this: cannot open source file "gtk/gtk.h"
    a. Realize your mistake, and that the correct command to get the include directories for GTK is pkg-config --cflags-only-I gtk+-3.0 | xargs -n 1 echo | sed -e 's/^-I//' | sort | uniq.
    b. Sadly, this bit of arcane knowledge will not win any bar bets.
  7. Click on "Quick Fix..." -- get "No code actions available."
  8. Note that "Problems" output states: #include errors detected. Please update your includePath. Squiggles are disabled for this translation unit.
  9. User/interface error starts here. Go to File > Preferences > Settings. Select the folder settings. Search for includePath.
  10. Note that the results are "C_Cpp > Default: Include Path" and "C_Cpp > Default: System Include Path". Both require direct editing in settings.json.
    a. Note the lack of mention of c_cpp_properties.json.
  11. Hover to the left of "C_Cpp > Default: Include Path" to get the gear icon. Click on "Copy Setting ID".
  12. Click on "Edit in settings.json".
  13. Add into settings.json:
    {
        "C_Cpp.default.includePath": [
            "/usr/include/atk-1.0",
            "/usr/include/at-spi-2.0",
            "/usr/include/at-spi2-atk/2.0",
            "/usr/include/cairo",
            "/usr/include/dbus-1.0",
            "/usr/include/freetype2",
            "/usr/include/gdk-pixbuf-2.0",
            "/usr/include/gio-unix-2.0/",
            "/usr/include/glib-2.0",
            "/usr/include/gtk-3.0",
            "/usr/include/harfbuzz",
            "/usr/include/libpng16",
            "/usr/include/pango-1.0",
            "/usr/include/pixman-1",
            "/usr/lib/x86_64-linux-gnu/dbus-1.0/include",
            "/usr/lib/x86_64-linux-gnu/glib-2.0/include"
        ],
        "C_Cpp.default.intelliSenseMode": "gcc-x64"
    }
    
  14. Continue to get errors saying cannot open source file "gtk/gtk.h"

Expected behavior

Intellisense settings aren't so far removed from VSCode-native integration. That could be abolishing the separate c_cpp_properties.json file so it's all managed through the VSCode native settings dialog, automagically merging the two, etc.

Less preferred, but still would've saved me time: yelling at the user when folder-based settings.json/C_Cpp.default.includePath and c_cpp_properties.json/configurations.includePath are both set/conflict and settings.json is being ignored.

Screenshots

Additional context

Metadata

Metadata

Assignees

Labels

Feature RequestFeature: ConfigurationAn issue related to configuring the extension or IntelliSenseLanguage ServicefixedCheck the Milestone for the release in which the fix is or will be available.quick fix

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions