Skip to content

Filter go to definition results based on active CMake project configuration #13711

Open
@briankendall

Description

@briankendall

Brief Issue Summary

I have a CMake Tools / cpptools project that's utilizing configure presets to allow building for different targets. In my project are some symbols that are defined multiple times, once for each target. If I right click on one of those symbols and pick "Go to Definition", a box opens up asking me which symbol I want to go to, even though only one of those files is actually currently configured to be compiled. This can get annoying as I try to follow symbols around -- I think it should automatically know which one I want to follow based on the current configuration preset.

I've attached a zip file containing a minimal example of this issue. If you expand the zip and open symbol-demo in VSCode, set it to use either configuration preset, and then right click on platform_name on line 6 of main.c and pick "Go to Definition", it will query for the definition in either platform1.c or platform2.c, even though only one of those files will ever be configured to be compiled.

I'm not sure if this is a bug or intended behavior, and if it's a bug whether it's an issue with CMake Tools or cpptools, but I figured this is the logical place to start.

symbol-demo.zip

CMake Tools Diagnostics

{
  "os": "darwin",
  "vscodeVersion": "1.101.0",
  "cmtVersion": "1.20.53",
  "configurations": [
    {
      "folder": "/Users/username/Desktop/symbol-demo",
      "cmakeVersion": "3.31.3",
      "configured": true,
      "generator": "Unix Makefiles",
      "usesPresets": true,
      "compilers": {
        "C": "/Applications/Xcode-14.3.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc"
      }
    }
  ],
  "cpptoolsIntegration": {
    "isReady": true,
    "hasCodeModel": true,
    "activeBuildType": "",
    "buildTypesSeen": [
      ""
    ],
    "requests": [
      "file:///Users/username/Desktop/symbol-demo/main.c",
      "file:///Users/username/Desktop/symbol-demo/platform1.c"
    ],
    "responses": [
      {
        "uri": "file:///Users/username/Desktop/symbol-demo/main.c",
        "configuration": {
          "includePath": [],
          "defines": [],
          "compilerPath": "/applications/xcode-14.3.1.app/contents/developer/toolchains/xcodedefault.xctoolchain/usr/bin/cc",
          "compilerArgs": [],
          "compilerFragments": [
            " -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk"
          ]
        }
      },
      {
        "uri": "file:///Users/username/Desktop/symbol-demo/platform1.c",
        "configuration": {
          "includePath": [],
          "defines": [],
          "compilerPath": "/applications/xcode-14.3.1.app/contents/developer/toolchains/xcodedefault.xctoolchain/usr/bin/cc",
          "compilerArgs": [],
          "compilerFragments": [
            " -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk"
          ]
        }
      }
    ],
    "partialMatches": [],
    "targetCount": 1,
    "executablesCount": 1,
    "librariesCount": 0,
    "targets": [
      {
        "name": "symbol_demo",
        "type": "EXECUTABLE"
      }
    ]
  },
  "settings": [
    {
      "communicationMode": "automatic",
      "useCMakePresets": "auto",
      "configureOnOpen": true
    }
  ]
}

Debug Log

Configure:
[main] Configuring project: symbol-demo 
[main] Saving open files before configure/build
[driver] Start configure 
[driver] Running pre-configure checks and steps
[cmakefileapi-driver] Configuring using preset
[cmakefileapi-driver] Invoking CMake /opt/local/bin/cmake with arguments ["-DPLATFORM_NAME=platform1","-S/Users/username/Desktop/symbol-demo","-B/Users/username/Desktop/symbol-demo/out/build/platform1"]
[proc] Executing command: /opt/local/bin/cmake -DPLATFORM_NAME=platform1 -S/Users/username/Desktop/symbol-demo -B/Users/username/Desktop/symbol-demo/out/build/platform1
[proc]   with environment: [redacted]
[cmake] -- Configuring done (0.0s)
[cmake] -- Generating done (0.0s)
[cmake] -- Build files have been written to: /Users/username/Desktop/symbol-demo/out/build/platform1
[cmakefileapi-parser] Read reply folder: /Users/username/Desktop/symbol-demo/out/build/platform1/.cmake/api/v1/reply
[cmakefileapi-parser] Found index files: ["cache-v2-8fa3956c785132dde167.json","cmakeFiles-v1-fe1bf9891ff6be181776.json","codemodel-v2-8982237f9622d9423818.json","directory-.-f5ebdc15457944623624.json","index-2025-06-17T00-54-00-0052.json","target-symbol_demo-fd4730cf5d600f8bb4e4.json","toolchains-v1-2928f2eaa272260a2590.json"]
[cache] Reading CMake cache file /Users/username/Desktop/symbol-demo/out/build/platform1/CMakeCache.txt
[cache] Parsing CMake cache string
[extension] [1644] cmake.configure finished (returned 0)
[cache] Reading CMake cache file /Users/username/Desktop/symbol-demo/out/build/platform1/CMakeCache.txt
[cache] Parsing CMake cache string

Build:
[main] Building folder: /Users/username/Desktop/symbol-demo/out/build/platform1 
[main] Saving open files before configure/build
[build] Starting build
[driver] Start build 
[proc] Executing command: /opt/local/bin/cmake --build /Users/username/Desktop/symbol-demo/out/build/platform1 --parallel 18 --
[proc]   with environment: [redacted]
[build] [100%] Built target symbol_demo
[driver] Build completed: 00:00:00.287
[cmakefileapi-parser] Read reply folder: /Users/username/Desktop/symbol-demo/out/build/platform1/.cmake/api/v1/reply
[cmakefileapi-parser] Found index files: ["cache-v2-8fa3956c785132dde167.json","cmakeFiles-v1-fe1bf9891ff6be181776.json","codemodel-v2-8982237f9622d9423818.json","directory-.-f5ebdc15457944623624.json","index-2025-06-17T00-54-00-0052.json","target-symbol_demo-fd4730cf5d600f8bb4e4.json","toolchains-v1-2928f2eaa272260a2590.json"]
[cache] Reading CMake cache file /Users/username/Desktop/symbol-demo/out/build/platform1/CMakeCache.txt
[cache] Parsing CMake cache string
[build] Build finished with exit code 0
[cache] Reading CMake cache file /Users/username/Desktop/symbol-demo/out/build/platform1/CMakeCache.txt
[extension] [7053] cmake.build finished (returned 0)
[cache] Parsing CMake cache string

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions