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

Variable substitution stopped working in version 1.7

Open davidmneto opened this issue 3 years ago • 9 comments

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

  • Operating System: Ubuntu 20.04
  • CMaketools Version: 1.7.3

davidmneto avatar Jun 02 '21 15:06 davidmneto

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

bobbrow avatar Jun 04 '21 20:06 bobbrow

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

davidmneto avatar Jun 07 '21 09:06 davidmneto

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

bobbrow avatar Jun 07 '21 16:06 bobbrow

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.

andreeis avatar Jun 08 '21 16:06 andreeis

Hwo to fix?

lygstate avatar Nov 25 '21 05:11 lygstate

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.

ToBoMi avatar Nov 30 '22 15:11 ToBoMi

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

bobbrow avatar Nov 30 '22 16:11 bobbrow

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}

ToBoMi avatar Nov 30 '22 16:11 ToBoMi

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.

bobbrow avatar Nov 30 '22 16:11 bobbrow