Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
dacut opened this issue Jun 5, 2019 · 6 comments · Fixed by #5413
Assignees
Labels
Feature: Configuration An issue related to configuring the extension or IntelliSense Feature Request fixed Check the Milestone for the release in which the fix is or will be available. Language Service quick fix
Milestone

Comments

@dacut
Copy link

dacut commented Jun 5, 2019

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

@dacut dacut changed the title Check settings in settings.json in addition to c_cpp_properties.json? Check for includePath conflicts in settings.json vs. c_cpp_properties.json? Jun 5, 2019
@sean-mcmanus
Copy link
Contributor

You can pull in the C_Cpp.default.includePath settings via using ${default} in your c_cpp_properties.json includePath.

@bobbrow @michelleangela It seems like we should auto-add the ${default} for newly created c_cpp_properties.json?

@sean-mcmanus sean-mcmanus added Feature Request Feature: Configuration An issue related to configuring the extension or IntelliSense Language Service labels Jun 5, 2019
@vakokako
Copy link

vakokako commented Jun 8, 2019

@sean-mcmanus Yes, that'd be super helpful!

@jxramos
Copy link

jxramos commented Oct 9, 2019

@sean-mcmanus , would this be the correct syntax to adopt?

{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [ ${default},
            ],
            "defines": [],
            "macFrameworkPath": [
                "/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks"
            ],
            "compilerPath": "/usr/bin/clang",
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 4
}

@sean-mcmanus
Copy link
Contributor

@jxramos ${default} needs to be "${default}".

@bobbrow bobbrow changed the title Check for includePath conflicts in settings.json vs. c_cpp_properties.json? Automatically add "${default}" when generating c_cpp_properties.json and a C_Cpp.default.* property is set Mar 27, 2020
@bobbrow bobbrow modified the milestones: Backlog, 1.0 Mar 27, 2020
@bobbrow bobbrow modified the milestones: 0.28.0, 0.29.0 May 1, 2020
@bobbrow bobbrow reopened this Jul 7, 2020
@bobbrow bobbrow added the fixed Check the Milestone for the release in which the fix is or will be available. label Jul 7, 2020
@sean-mcmanus
Copy link
Contributor

With 0.29.0, we add ${default} to includePath automatically if C_Cpp.default.includePath is set. Is that sufficient to close this issue?

@dacut
Copy link
Author

dacut commented Jul 16, 2020

I would think so.

@github-actions github-actions bot locked and limited conversation to collaborators Oct 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Feature: Configuration An issue related to configuring the extension or IntelliSense Feature Request fixed Check the Milestone for the release in which the fix is or will be available. Language Service quick fix
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants