microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.41k stars 1.52k forks source link

Configuration detection wrong #4693

Closed tschoonj closed 4 years ago

tschoonj commented 4 years ago

Type: LanguageService

Describe the bug

To Reproduce I have the following c_cpp_properties.json file:

{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "${workspaceFolder}/**",
                "/usr/local/opt/glib/include/glib-2.0",
                "/usr/local/opt/glib/lib/glib-2.0/include/",
                "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/libxml2",
                "/usr/local/include/xraylib",
                "/usr/local/opt/libsoup/include/libsoup-2.4",
                "/usr/local/opt/gtk+3/include/gtk-3.0",
                "/usr/local/opt/pango/include/pango-1.0",
                "/usr/local/opt/harfbuzz/include/harfbuzz",
                "/usr/local/opt/cairo/include/cairo/",
                "/usr/local/opt/gdk-pixbuf/include/gdk-pixbuf-2.0",
                "/usr/local/opt/atk/include/atk-1.0/",
                "/usr/local/opt/gtkmm-plplot/include/gtkmm-plplot-2.0",
                "/usr/local/opt/gtkmm-plplot/lib/gtkmm-plplot-2.0/include/",
                "/usr/local/opt/gtkmm3/include/gtkmm-3.0",
                "/usr/local/opt/gtkmm3/lib/gtkmm-3.0/include",
                "/usr/local/opt/gtkmm3/lib/gdkmm-3.0/include",
                "/usr/local/opt/pangomm/include/pangomm-1.4",
                "/usr/local/opt/pangomm/lib/pangomm-1.4/include",
                "/usr/local/opt/glibmm/include/glibmm-2.4",
                "/usr/local/opt/glibmm/lib/glibmm-2.4/include",
                "/usr/local/opt/json-glib/include/json-glib-1.0",
                "/usr/local/opt/hdf5/include"
            ],
            "defines": [],
            "macFrameworkPath": [
                "/System/Library/Frameworks",
                "/Library/Frameworks"
            ],
            "compilerPath": "/usr/local/opt/llvm/bin/clang",
            "cppStandard": "c++11"
        },
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "/usr/include/glib-2.0",
                "/usr/lib64/glib-2.0/include",
                "/usr/include/libxml2",
                "/dls_sw/apps/xraylib/3.99.0-gcc8/7/include/xraylib",
                "/usr/include/libsoup-2.4",
                "/dls_sw/apps/hdf5/1.10.3/include",
                "/usr/include/gtk-3.0/",
                "/dls_sw/apps/gtkmm-plplot/2.3/7/include",
                "/usr/include/pango-1.0",
                "/dls_sw/apps/gtkmm-plplot/2.3/7/lib/gtkmm-plplot-2.0/include/",
                "/usr/lib64/gtkmm-3.0/include/",
                "/usr/include/cairo",
                "/usr/lib64/gdkmm-3.0/include/",
                "/usr/include/json-glib-1.0/",
                "/usr/include/gdk-pixbuf-2.0",
                "/usr/lib64/pangomm-1.4/include/",
                "/usr/include/atk-1.0",
                "/usr/lib64/glibmm-2.4/include/",
                "/dls_sw/apps/cuda/9.2/include"
            ],
            "defines": [],
            "compilerPath": "/dls_sw/apps/gcc/8.3.0/7/bin/gcc",
            "cStandard": "c99",
            "cppStandard": "c++11",
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 4
}

Expected behavior That the system would be properly recognized as Linux and the corresponding configuration used. I cannot seem to find a way either to force it to use Linux either...

Screenshots

Additional context

Thanks for looking into this.

Colengms commented 4 years ago

Hi @tschoonj . The C/C++ Extension does not auto-detect the appropriate configuration to use. You need to select a configuration either by clicking on the configuration at the bottom of the VS Code window (while a C/C++ file is in focus), or using the C/C++: Select a Configuration... command.

tschoonj commented 4 years ago

Thank you for the hint: this works indeed.

I am surprised that there is no auto-detection going on, since the documentation appears to say otherwise:

name A friendly name that identifies a configuration. Linux, Mac, and Win32 are special identifiers for configurations that will be autoselected on those platforms. The status bar in VS Code will show you which configuration is active. You can also click on the label in the status bar to change the active configuration.

Colengms commented 4 years ago

Hi @tschoonj . I stand corrected. I did not know this feature existed. :) We'll take a look.

sean-mcmanus commented 4 years ago

I seem to recall (from a long time ago) the auto-config detection doesn't work if there are less than 3 configs, so adding a 3rd "windows" config that is unused might fix it.

bobbrow commented 4 years ago

The 3 config thing was from a while ago, I just tried this and didn't reproduce the incorrect config selection. But we only auto-config the first time you open a folder or if you make changes to the config that remove the currently selected config. Otherwise we will continue to use the previously selected config.

If you are still having a problem with this, let us know. I will close the issue for now.