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

Getting VS Kit Environment fails silently when VS instance not found

Open SimonBoorer opened this issue 1 year ago • 1 comments

Brief Issue Summary

I've been using the CMake Tools extension with the Visual Studio generator for some time without issue. I swapped to using Ninja and was struggling with it using the wrong compiler. After enabling debug logging I found that this was because the environment variables from vcvaralls.bat were not being applied. I had to debug the vscode-cmake-tools extension to work out that the reason why was that at some point my VS Install instance ID had changed so my cmake-tools-kits.json was outdated. Running Scan for Kit updated the instance ID which fixed the issue.

It would be good if there were some kind of warning or error message when the VS instance was not found, and perhaps a suggestion to re-scan for kits:

export async function getVSKitEnvironment(kit: Kit): Promise<Environment | null> {
    const requested = await getVSInstallForKit(kit);
    if (!requested) {
        return null;
    }

    return varsForVSInstallation(requested, kit.visualStudioArchitecture!, kit.preferredGenerator?.platform);
}

async function getVSInstallForKit(kit: Kit): Promise<VSInstallation | undefined> {
    if (process.platform !== "win32") {
        return undefined;
    }

    console.assert(kit.visualStudio);
    console.assert(kit.visualStudioArchitecture);

    const installs = await vsInstallations();
    const match = (inst: VSInstallation) =>
        // old Kit format
        (legacyKitVSName(inst) === kit.visualStudio) ||
        // new Kit format
        (kitVSName(inst) === kit.visualStudio) ||
        // Clang for VS kit format
        (!!kit.compilers && kit.name.indexOf("Clang") >= 0 && kit.name.indexOf(vsDisplayName(inst)) >= 0);

    return installs.find(match);
}

CMake Tools Diagnostics

No response

Debug Log

No response

Additional Information

No response

SimonBoorer avatar Mar 10 '24 11:03 SimonBoorer

@SimonBoorer This is definitely something that would be nice. I will add this to our backlog. THanks.

gcampbell-msft avatar Mar 13 '24 14:03 gcampbell-msft

Closing, fixed in #3775

gcampbell-msft avatar Jun 24 '24 15:06 gcampbell-msft