vscode-cmake-tools icon indicating copy to clipboard operation
vscode-cmake-tools copied to clipboard

cmake c project IntelliSense not work

Open WittonBell opened this issue 1 year ago • 18 comments

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;
}
  1. 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})
  1. 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"
      }
    }
}
  1. select preset clang Debug, and build
  2. 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

WittonBell avatar Nov 21 '23 14:11 WittonBell

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

snehara99 avatar Nov 28 '23 17:11 snehara99

@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!

gcampbell-msft avatar Dec 20 '23 18:12 gcampbell-msft

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

intelliSense

Thanks.

WittonBell avatar Dec 21 '23 03:12 WittonBell

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] avatar Jan 20 '24 07:01 github-actions[bot]

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

github-actions[bot] avatar Jan 27 '24 07:01 github-actions[bot]

@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

WittonBell avatar Jan 29 '24 09:01 WittonBell

@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!

gcampbell-msft avatar Jan 29 '24 14:01 gcampbell-msft

@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!

WittonBell avatar Jan 30 '24 01:01 WittonBell

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

gcampbell-msft avatar Jan 30 '24 14:01 gcampbell-msft

@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?

WittonBell avatar Jan 31 '24 04:01 WittonBell

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

gcampbell-msft avatar Jan 31 '24 14:01 gcampbell-msft

@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!

WittonBell avatar Feb 01 '24 04:02 WittonBell

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

gcampbell-msft avatar Feb 01 '24 15:02 gcampbell-msft

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

GEOEGII555 avatar Apr 23 '24 07:04 GEOEGII555

@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

Yingzi1234 avatar Apr 24 '24 10:04 Yingzi1234

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

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

WittonBell avatar Apr 25 '24 02:04 WittonBell

@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

Yingzi1234 avatar Apr 25 '24 07:04 Yingzi1234

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

WittonBell avatar Apr 25 '24 10:04 WittonBell