microsoft / vscode-cmake-tools

CMake integration in Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=vector-of-bool.cmake-tools
MIT License
1.47k stars 454 forks source link

cmake c project IntelliSense not work #3460

Open WittonBell opened 11 months ago

WittonBell commented 11 months ago

Brief Issue Summary

env: VSCode: 1.84.2 C/C++: v1.18.5 cmake tools: v1.16.31 gcc: 13.2.0 clang: 17.0.4

reproduce step:

  1. create any cmake project with c language.

  2. create main.c:

    #include <stdio.h>
    #ifdef _WIN32
    #include <windows.h>
    #endif
    int main()
    {
    #ifdef _WIN32
    SetConsoleOutputCP(65001);
    #endif
    return 0;
    }
  3. create CMakeLists.txt:

    cmake_minimum_required(VERSION 3.20.0)
    project(t VERSION 0.1.0)
    aux_source_directory(. SRC)
    add_executable(t ${SRC})
    set(CPACK_PROJECT_NAME ${PROJECT_NAME})
    set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
  4. create CMakePresets.json:

    {
    "version": 3,
    "configurePresets": [
    {
      "name": "gcc-base",
      "hidden": true,
      "generator": "Ninja",
      "binaryDir": "${sourceDir}/out/build/${presetName}",
      "installDir": "${sourceDir}/out/install/${presetName}",
      "environment": {
        "PATH": "G:/msys64/mingw64/bin/;$penv{path}"
      },
      "cacheVariables": {
        "CMAKE_C_COMPILER": "gcc.exe",
        "CMAKE_CXX_COMPILER": "g++.exe"
      },
      "condition": {
        "type": "equals",
        "lhs": "${hostSystemName}",
        "rhs": "Windows"
      },
      "vendor": {
        "microsoft.com/VisualStudioSettings/CMake/1.0": {
          "intelliSenseMode": "linux-gcc-x64"
        }
      }
    },
    {
      "name": "clang-base",
      "hidden": true,
      "generator": "Ninja",
      "binaryDir": "${sourceDir}/out/build/${presetName}",
      "installDir": "${sourceDir}/out/install/${presetName}",
      "environment": {
        "PATH": "G:/msys64/mingw64/bin/;$penv{path}"
      },
      "cacheVariables": {
        "CMAKE_C_COMPILER": "clang.exe",
        "CMAKE_CXX_COMPILER": "clang++.exe"
      },
      "condition": {
        "type": "equals",
        "lhs": "${hostSystemName}",
        "rhs": "Windows"
      },
      "vendor": {
        "microsoft.com/VisualStudioSettings/CMake/1.0": {
          "intelliSenseMode": "windows-clang-x64",
          "intelliSenseOptions": {
            "useCompilerDefaults": true
          }
        }
      }
    },
    {
      "name": "gcc-debug",
      "displayName": "gcc Debug",
      "inherits": "gcc-base",
      "architecture": {
        "value": "x64",
        "strategy": "external"
      },
      "cacheVariables": {
        "CMAKE_BUILD_TYPE": "Debug"
      }
    },
    {
      "name": "clang-debug",
      "displayName": "clang Debug",
      "inherits": "clang-base",
      "architecture": {
        "value": "x64",
        "strategy": "external"
      },
      "cacheVariables": {
        "CMAKE_BUILD_TYPE": "Debug"
      }
    }
    }
  5. select preset clang Debug, and build

  6. press F12 on function SetConsoleOutputCP, can not jump to define. image

if rename main.c to main.cpp or select preset gcc Debug, the IntelliSense work fine.

CMake Tools Diagnostics

No response

Debug Log

No response

Additional Information

No response

snehara99 commented 11 months ago

Hi @WittonBell thanks for creating this issue. We'll add it to the backlog and investigate it as soon as we have the capacity!

gcampbell-msft commented 10 months ago

@WittonBell I just followed your repro steps and I was able to press F12 and jump to the define, could you confirm that this issue no longer reproduces?

I've marked this as completed but will wait for confirmation from you before fully closing the issue. Thanks!

WittonBell commented 10 months ago

@gcampbell-msft It's still exist this issue. Please see the gif:

intelliSense

Thanks.

github-actions[bot] commented 9 months ago

This issue is now marked as 'stale' due to there being no activity on it for the past 30 days and being labelled 'more info needed'. Unless the 'stale' label is removed or the issue is commented on, this will be closed in 7 days. If you would like to make this issue exempt from getting stale, please remove the 'more info needed' and 'stale' labels or add the 'stale-exempt' label

github-actions[bot] commented 9 months ago

This issue is now closed due to there being no activity on it for the past 7 days since being marked as 'stale'.

WittonBell commented 9 months ago

@gcampbell-msft @snehara99 this issue is still exist! env: OS: win10 22H2 MinGW clang 17.0.6 MinGW gcc 13.2.0 vscode version: 1.85.2 cmake version: 3.28.1 c/c++ plugin version 1.18.5 cmake tools plugin version: v1.16.32

gcampbell-msft commented 9 months ago

@WittonBell Thanks for pinging, looking again at your gif, it seems like the CMake extension is providing intellisense. Could you set the C_Cpp.default.configurationProvider setting in VS Code to ms-vscode.cmake-tools?

Please let us know if this fixes your issue!

WittonBell commented 9 months ago

@gcampbell-msft I use the following c_cpp_properties.json configuration:

{
    "configurations": [
        {
            "name": "MinGW",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE",
                "_WIN32"
            ],
            "windowsSdkVersion": "10.0.22621.0",
            "compilerPath": "G:/msys64/mingw64/bin/clang++.exe",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "windows-clang-x64",
            "configurationProvider": "ms-vscode.cmake-tools"
        }
    ],
    "version": 4
}

It cannot fix this issue. And I try to use "intelliSenseMode": "clang-x64", also exist this issue.

Thanks!

gcampbell-msft commented 9 months ago

@WittonBell Is there a reason you can't use the CMake Tools extension to provide IntelliSense?

WittonBell commented 9 months ago

@WittonBell Is there a reason you can't use the CMake Tools extension to provide IntelliSense?

@gcampbell-msft Is there a log to know which configurationProvider it is using? It should be using CMake Tools extension, because I change main.c to main.cpp, it work normally. Have you reproduced this issue?

gcampbell-msft commented 9 months ago

@WittonBell You can set the configuration provider by modifying the setting C_Cpp.default.configurationProvider, in the VS Code settings.

WittonBell commented 9 months ago

@gcampbell-msft I use the configuration in settings.json of VSCode:

"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
"C_Cpp.default.intelliSenseMode": "clang-x64",

also exist this issue. Need you to check and fix it. Thanks!

gcampbell-msft commented 9 months ago

Got it. With this in mind, I'll re-open the issue. Thanks!

GEOEGII555 commented 6 months ago

Intellisense breaks for me too. It doesn't suggest any variable (even in the same function) anymore.

Except that it's broken in C++ (cpp) files, and partially works in C.

C++ example: https://github.com/microsoft/vscode-cmake-tools/assets/57674559/a9f34a7a-3959-4a33-9f17-0472e8769655

C example: https://github.com/microsoft/vscode-cmake-tools/assets/57674559/d93bf4c4-63ed-4af2-8abe-6fe64519ce82

Yingzi1234 commented 6 months ago

@WittonBell We are currently trying to reproduce your issue, but we are experiencing the following problem. May I ask what is the value of your Preset setting? 3460

WittonBell commented 6 months ago

@Yingzi1234 我提的issue中复现步骤有详细说明,第5步中提到选择clang Debug,简单来说,这个问题就是在使用Clang编译器时,CMake创建的C项目,智能提示不能正常工作。

另外,我看你发的GIF中的问题,应该是没有让VSCode使用预设配置吧?可以看看VSCode的设置。 image

Yingzi1234 commented 6 months ago

@WittonBell According to the information you provided, we only reproduced this issue once and we can't reproduce this issue anymore, we put the details below, could you confirm the reproduction steps for us? Thank you!

Repro steps:

  1. Create a folder on desktop and open it by VScode
  2. Create the main.c and CMakeLists.txt and CMakePresets.json files, and paste the above into them
  3. Click F1 to configure it and then build it
  4. Open the main.c file and hove over the code SetConsoleOutputCP and click F12

Expected result: It should jump to the definition

Actual result: It doesn't jump to definitions. And when I rename ‘main.c’ to ‘main.cpp’ and then rename it to ‘main.c’ this issue no longer reproduces. 3460 issue

WittonBell commented 6 months ago

@Yingzi1234 明显你这个跳转是有问题的,使用MinGW,不应该跳转到MS的SDK中去。你可以仔细看一下我前面给出的信息,还可以看一下我前面给出的GIF