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 450 forks source link

Variable substitution stopped working in version 1.7 #1914

Open davidmneto opened 3 years ago

davidmneto commented 3 years ago

Brief Issue Summary

I am having an issue similar to the one described in https://github.com/microsoft/vscode-cmake-tools/issues/1526. I am trying to set the cmake.sourceDirectory using the variable ${buildKit} as follows:

"cmake.sourceDirectory": "${workspaceFolder}/project_1/${buildKit}",

I cannot configure the cmake project and I receive the error shown below.

I was able to later solve this by installing the previous version of cmaketools version. 1.6.0, and the substitution worked fine. I believe something broke in the transition to 1.7

CMake Tools Log

[expand] Invalid variable reference ${buildKit} in string: ${workspaceFolder}/project_1/${buildKit}
[rollbar] "sourceDirectory" is not a directory {"sourceDirectory":"/workspaces/copateneida/project_1/${buildKit}"}

Platform and Versions

bobbrow commented 3 years ago

Are you using CMakePresets.json to configure your project? Or are you using Kits and Variants?

davidmneto commented 3 years ago

I believe I am using kits. I have configured the kits in a separate cmake-kits.json file. And I am setting the cmake.sourceDirectory in the settings.json

bobbrow commented 3 years ago

I see what happened. This commit disabled using certain variables in cmake.sourceDirectory. @andreeis can explain further. Is there a way we can make this work again?

https://github.com/microsoft/vscode-cmake-tools/blob/c1f11cb574bfb049e07d452e31ea950c6bba0533/src/extension.ts#L437-L438

andreeis commented 3 years ago

Yes I can fix this. The original mistake on my part was that I was focused on scenarios where we want to identify if a project is or not a CMake project and that needs to happen before that annoying popup that we had about setting a kit. So I thought any kit information that is missing shouldn't block our analysis of having or not having a CMakeLists.txt (via "cmake.sourceDirectory"). But I didn't realize that if we do have a kit set then we need to expand any variables kit related. Quick fix.

lygstate commented 2 years ago

Hwo to fix?

ToBoMi commented 1 year ago

I try to use ${activeConfigurePresetName} in .vscode/settings.json and it is not getting evaluated. ${workspaceFolder} expansion works.

I use it as an argument to the clangd startup and it passes the non evaluated string ${activeConfigurePresetName} to the clangd call. Is this behavior related to this issue? I use CMakePresets.

bobbrow commented 1 year ago

@ToBoMi we support that feature, but your syntax is incorrect which is why it's not substituting it properly. Try ${command:cmake.activeConfigurePresetName}. (variable substitution documentation)

ToBoMi commented 1 year ago

Already tried that and many variations after reading the docs. None of them worked. Here is the current output:

This:

    "clangd.arguments": [
        "--compile-commands-dir=${workspaceFolder}/${command:cmake.activeConfigurePresetName}",
    ]

leads to the following clangd call (I replaced some things with [...] in the workspace folder)

I[17:29:29.866] argv[1]: --compile-commands-dir=c:\Users\[...]\swdev\[...]/${command:cmake.activeConfigurePresetName}
bobbrow commented 1 year ago

We don't own the clangd.arguments setting. If that extension doesn't support command variable expansion, then you'll need to open an issue in that extension's repository to ask for the feature. VS Code does not do substitution on settings automatically. The extensions have to process it.