microsoft / microsoft/vscode-cmake-tools

Compile definitions are not detected by Intellisense

Open
#3,216 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Feature: cpptools integration
Dominant language
TypeScript
Stars
1.7k
Forks
546
Avg merge
2d 16h
Merged PRs (30d)
32

Description

Brief Issue Summary

I defined SING_PLATFORM_APPLE and use it like this:

#ifndef SING_PLATFORM_APPLE
    #error Sing only supports Apple platforms
#endif

Code works with no problems.

Intellisense should grey out the block since preprocessor will never reach that line.
But it's not. Also VSCode adds squiggly line under that #error directive, which is a good feature if Intellisense worked correctly.

My CMakeLists.txt below:

add_library(sing SHARED src/Application.cpp)
target_include_directories(sing PRIVATE "${PROJECT_SOURCE_DIR}/include/sing")

if(APPLE)
    target_compile_definitions(sing PRIVATE SING_PLATFORM_APPLE)
endif()
CMake Tools Diagnostics
{
  "os": "darwin",
  "vscodeVersion": "1.79.2",
  "cmtVersion": "1.14.33",
  "configurations": [
    {
      "folder": "/Users/derin/Projects/Learning/sing",
      "cmakeVersion": "3.26.4",
      "configured": true,
      "generator": "Ninja",
      "usesPresets": false,
      "compilers": {
        "C": "/usr/bin/clang",
        "CXX": "/usr/bin/clang++"
      }
    }
  ],
  "cpptoolsIntegration": {
    "isReady": true,
    "hasCodeModel": true,
    "activeBuildType": "Debug",
    "buildTypesSeen": [
      "Debug"
    ],
    "requests": [
      "file:///Users/derin/Projects/Learning/sing/include/sing/Core.h"
    ],
    "responses": [],
    "partialMatches": [],
    "targetCount": 2,
    "executablesCount": 1,
    "librariesCount": 1,
    "targets": [
      {
        "name": "sandbox",
        "type": "EXECUTABLE"
      },
      {
        "name": "sing",
        "type": "SHARED_LIBRARY"
      }
    ]
  },
  "settings": [
    {
      "communicationMode": "automatic",
      "useCMakePresets": "auto",
      "configureOnOpen": false
    }
  ]
}
Debug Log
[main] Building folder: sing 
[main] Saving open files before configure/build
[build] Starting build
[driver] Start build all
[proc] Executing command: /opt/homebrew/bin/cmake --build /Users/derin/Projects/Learning/sing/build --config Debug --target all --
[proc]   with environment: {"ANDROID_HOME":"/Users/derin/Library/Android/sdk","COMMAND_MODE":"unix2003","HOME":"/Users/derin","HOMEBREW_CELLAR":"/opt/homebrew/Cellar","HOMEBREW_PREFIX":"/opt/homebrew","HOMEBREW_REPOSITORY":"/opt/homebrew","INFOPATH":"/opt/homebrew/share/info:","LOGNAME":"derin","MANPATH":"/Users/derin/.nvm/versions/node/v16.15.1/share/man:/opt/homebrew/share/man::","MallocNanoZone":"0","NVM_BIN":"/Users/derin/.nvm/versions/node/v16.15.1/bin","NVM_CD_FLAGS":"-q","NVM_DIR":"/Users/derin/.nvm","NVM_INC":"/Users/derin/.nvm/versions/node/v16.15.1/include/node","OLDPWD":"/","ORIGINAL_XDG_CURRENT_DESKTOP":"undefined","PATH":"/Users/derin/.nvm/versions/node/v16.15.1/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/share/dotnet:~/.dotnet/tools:/Library/Apple/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Users/derin/.cargo/bin:/Users/derin/Library/Application Support/JetBrains/Toolbox/scripts:/Users/derin/development/flutter/bin:/Users/derin/Library/Android/sdk/cmdline-tools:/Users/derin/.pub-cache/bin:/Users/derin/Applications/Julia-1.8.app/Contents/Resources/julia/bin","PROMPT":"[%*] (%n) %~ %% ","PWD":"/","SHELL":"/bin/zsh","SHLVL":"0","SSH_AUTH_SOCK":"/private/tmp/com.apple.launchd.SVFVm6QU9Z/Listeners","TMPDIR":"/var/folders/0v/g7t56xl933v5_2m7ntkr_ktw0000gn/T/","USER":"derin","VSCODE_AMD_ENTRYPOINT":"vs/workbench/api/node/extensionHostProcess","VSCODE_CODE_CACHE_PATH":"/Users/derin/Library/Application Support/Code/CachedData/695af097c7bd098fbf017ce3ac85e09bbc5dda06","VSCODE_CRASH_REPORTER_PROCESS_TYPE":"extensionHost","VSCODE_CWD":"/","VSCODE_HANDLES_UNCAUGHT_ERRORS":"true","VSCODE_IPC_HOOK":"/Users/derin/Library/Application Support/Code/1.79-main.sock","VSCODE_NLS_CONFIG":"{\"locale\":\"en-gb\",\"osLocale\":\"en-gb\",\"availableLanguages\":{},\"_languagePackSupport\":true}","VSCODE_PID":"840","XPC_FLAGS":"0x0","XPC_SERVICE_NAME":"application.com.microsoft.VSCode.18722886.18722892","_":"/Applications/Visual Studio Code.app/Contents/MacOS/Electron","__CFBundleIdentifier":"com.microsoft.VSCode","__CF_USER_TEXT_ENCODING":"0x1F5:0x0:0x2","ELECTRON_RUN_AS_NODE":"1","VSCODE_L10N_BUNDLE_LOCATION":"","APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL":"1","NINJA_STATUS":"[%s/%t %p :: %e] "}
[build] ninja: no work to do.
[driver] Build completed: 00:00:00.049
[cmakefileapi-parser] Read reply folder: /Users/derin/Projects/Learning/sing/build/.cmake/api/v1/reply
[cmakefileapi-parser] Found index files: ["cache-v2-88feed7812447a669c19.json","cmakeFiles-v1-401ca402ac870d3dfe72.json","codemodel-v2-d15d2ebdca757724d43c.json","directory-.-Debug-f5ebdc15457944623624.json","directory-apps.sandbox-Debug-9ed6ceb98e8e81bbbb11.json","index-2023-06-21T04-51-11-0776.json","target-sandbox-Debug-11d90892905e1f15895e.json","target-sing-Debug-5429c7baae0aa883f32c.json","toolchains-v1-5e618a28b507f347811e.json"]
[cache] Reading CMake cache file /Users/derin/Projects/Learning/sing/build/CMakeCache.txt
[cache] Parsing CMake cache string
[build] Build finished with exit code 0
[extension] [4899] cmake.build finished (returned 0)
Additional Information

My folder structure (if it helps)

.gitignore
CMakeLists.txt
[apps]
    └── [sandbox]
        ├── CMakeLists.txt
        └── main.cpp
[include]
    ├── Sing.h
    └── [sing]
        ├── Application.h
        └── Core.h
[src]
    └── Application.cpp

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the project’s CMakeLists.txt and include/sing/Core.h, then reproduce the configuration on macOS using the reported VS Code, CMake Tools, and Ninja versions. Trace how target_compile_definitions from the CMake code model are passed to IntelliSense; done means SING_PLATFORM_APPLE is recognized and the guarded block is greyed out without a spurious #error squiggle.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake, cpp, vscode
Domain
build-system, developer-experience, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.