-
Notifications
You must be signed in to change notification settings - Fork 8.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show only latest VS, VC prompts by default (#11326)
## Summary of the Pull Request Similar to `vswhere -latest`, show only the latest Visual Studio command prompts / developer PowerShell. This was tested by deleting the local package state and testing against fresh state with both VS2019 and VS2022 Preview installed, and indeed VS2022 Preview (both cmd and powershell) show. The other profiles were generated but hidden by default. ## References Modification of PR #7774 ## PR Checklist * [x] Closes #11307 * [x] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA * [x] Tests added/passed * [ ] Documentation updated. If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/terminal) and link it here: #xxx * [ ] Schema updated. * [x] I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #xxx ## Detailed Description of the Pull Request / Additional comments The sort algorithm is the same basic algorithm I used in https://github.com/microsoft/vswhere. It sorts first by installation version with a secondary sort based on the install date in case the installation versions are the same. ## Validation Steps Performed With both VS2019 and VS2022 Preview installed, I made sure the initial state was expected, and tried different combinations of hiding and unhiding generated entries, and restarted Terminal to make sure my settings "stuck".
- Loading branch information
Showing
17 changed files
with
372 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ DTDs | |
DWINRT | ||
enablewttlogging | ||
Intelli | ||
IVisual | ||
LKG | ||
LOCKFILE | ||
Lxss | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 0 additions & 36 deletions
36
src/cascadia/TerminalSettingsModel/BaseVisualStudioGenerator.cpp
This file was deleted.
Oops, something went wrong.
35 changes: 0 additions & 35 deletions
35
src/cascadia/TerminalSettingsModel/BaseVisualStudioGenerator.h
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
#include "pch.h" | ||
#include "DynamicProfileUtils.h" | ||
#include "VcDevCmdGenerator.h" | ||
|
||
using namespace winrt::Microsoft::Terminal::Settings::Model; | ||
|
||
void VcDevCmdGenerator::GenerateProfiles(const VsSetupConfiguration::VsSetupInstance& instance, bool hidden, std::vector<winrt::com_ptr<implementation::Profile>>& profiles) const | ||
{ | ||
try | ||
{ | ||
const std::filesystem::path root{ GetVcCmdScriptDirectory(instance) }; | ||
if (!std::filesystem::exists(root)) | ||
{ | ||
return; | ||
} | ||
|
||
// x64 environments only installed on 64-bit machines. | ||
#ifdef _WIN64 | ||
const auto vcvars64 = root / L"vcvars64.bat"; | ||
if (std::filesystem::exists(vcvars64)) | ||
{ | ||
auto profile = CreateProfile(instance, L"x64", vcvars64, hidden); | ||
profiles.emplace_back(std::move(profile)); | ||
|
||
// Only the VC environment for the matching architecture should be shown by default. | ||
hidden = true; | ||
} | ||
|
||
const auto vcvarsamd64_x86 = root / L"vcvarsamd64_x86.bat"; | ||
if (std::filesystem::exists(vcvarsamd64_x86)) | ||
{ | ||
auto profile = CreateProfile(instance, L"x64_x86", vcvarsamd64_x86, true); | ||
profiles.emplace_back(std::move(profile)); | ||
} | ||
|
||
const auto vcvarsx86_amd64 = root / L"vcvarsx86_amd64.bat"; | ||
if (std::filesystem::exists(vcvarsx86_amd64)) | ||
{ | ||
auto profile = CreateProfile(instance, L"x86_x64", vcvarsx86_amd64, true); | ||
profiles.emplace_back(std::move(profile)); | ||
} | ||
#endif // _WIN64 | ||
|
||
const auto vcvars32 = root / L"vcvars32.bat"; | ||
if (std::filesystem::exists(vcvars32)) | ||
{ | ||
auto profile = CreateProfile(instance, L"x86", vcvars32, hidden); | ||
profiles.emplace_back(std::move(profile)); | ||
} | ||
} | ||
CATCH_LOG(); | ||
} | ||
|
||
winrt::com_ptr<implementation::Profile> VcDevCmdGenerator::CreateProfile(const VsSetupConfiguration::VsSetupInstance& instance, const std::wstring_view& prefix, const std::filesystem::path& path, bool hidden) const | ||
{ | ||
const auto seed = GetProfileGuidSeed(instance, path); | ||
const winrt::guid profileGuid{ ::Microsoft::Console::Utils::CreateV5Uuid(TERMINAL_PROFILE_NAMESPACE_GUID, gsl::as_bytes(gsl::make_span(seed))) }; | ||
|
||
auto profile = winrt::make_self<implementation::Profile>(profileGuid); | ||
profile->Name(winrt::hstring{ GetProfileName(instance, prefix) }); | ||
profile->Commandline(winrt::hstring{ GetProfileCommandLine(path) }); | ||
profile->StartingDirectory(winrt::hstring{ instance.GetInstallationPath() }); | ||
profile->Icon(winrt::hstring{ GetProfileIconPath() }); | ||
profile->Hidden(hidden); | ||
|
||
return profile; | ||
} | ||
|
||
std::wstring VcDevCmdGenerator::GetProfileGuidSeed(const VsSetupConfiguration::VsSetupInstance& instance, const std::filesystem::path& path) const | ||
{ | ||
return L"VsDevCmd" + instance.GetInstanceId() + path.native(); | ||
} | ||
|
||
std::wstring VcDevCmdGenerator::GetProfileName(const VsSetupConfiguration::VsSetupInstance& instance, const std::wstring_view& prefix) const | ||
{ | ||
std::wstring name{ prefix + L" Native Tools Command Prompt for VS " }; | ||
name.append(instance.GetProfileNameSuffix()); | ||
return name; | ||
} | ||
|
||
std::wstring VcDevCmdGenerator::GetProfileCommandLine(const std::filesystem::path& path) const | ||
{ | ||
std::wstring commandLine{ L"cmd.exe /k \"" + path.native() + L"\"" }; | ||
|
||
return commandLine; | ||
} | ||
|
||
std::wstring VcDevCmdGenerator::GetVcCmdScriptDirectory(const VsSetupConfiguration::VsSetupInstance& instance) const | ||
{ | ||
return instance.ResolvePath(L"VC\\Auxiliary\\Build\\"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/*++ | ||
Copyright (c) Microsoft Corporation | ||
Licensed under the MIT license. | ||
Module Name: | ||
- VcDevCmdGenerator | ||
Abstract: | ||
- Dynamic profile generator for Visual C++ development environments. | ||
Author(s): | ||
- Heath Stewart - September 2021 | ||
--*/ | ||
|
||
#pragma once | ||
#include "VisualStudioGenerator.h" | ||
#include "VsSetupConfiguration.h" | ||
|
||
namespace winrt::Microsoft::Terminal::Settings::Model | ||
{ | ||
class VcDevCmdGenerator final : public VisualStudioGenerator::IVisualStudioProfileGenerator | ||
{ | ||
public: | ||
void GenerateProfiles(const VsSetupConfiguration::VsSetupInstance& instance, bool hidden, std::vector<winrt::com_ptr<implementation::Profile>>& profiles) const override; | ||
|
||
private: | ||
winrt::com_ptr<implementation::Profile> CreateProfile(const VsSetupConfiguration::VsSetupInstance& instance, const std::wstring_view& prefix, const std::filesystem::path& path, bool hidden) const; | ||
|
||
std::wstring GetProfileIconPath() const | ||
{ | ||
return L"ms-appx:///ProfileIcons/{0caa0dad-35be-5f56-a8ff-afceeeaa6101}.png"; | ||
} | ||
|
||
std::wstring GetProfileGuidSeed(const VsSetupConfiguration::VsSetupInstance& instance, const std::filesystem::path& path) const; | ||
std::wstring GetProfileName(const VsSetupConfiguration::VsSetupInstance& instance, const std::wstring_view& prefix) const; | ||
std::wstring GetProfileCommandLine(const std::filesystem::path& path) const; | ||
std::wstring GetVcCmdScriptDirectory(const VsSetupConfiguration::VsSetupInstance& instance) const; | ||
}; | ||
}; |
36 changes: 36 additions & 0 deletions
36
src/cascadia/TerminalSettingsModel/VisualStudioGenerator.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
#include "pch.h" | ||
#include "DynamicProfileUtils.h" | ||
#include "VisualStudioGenerator.h" | ||
#include "VcDevCmdGenerator.h" | ||
#include "VsDevCmdGenerator.h" | ||
#include "VsDevShellGenerator.h" | ||
|
||
using namespace winrt::Microsoft::Terminal::Settings::Model; | ||
|
||
std::wstring_view VisualStudioGenerator::GetNamespace() const noexcept | ||
{ | ||
return std::wstring_view{ L"Windows.Terminal.VisualStudio" }; | ||
} | ||
|
||
void VisualStudioGenerator::GenerateProfiles(std::vector<winrt::com_ptr<implementation::Profile>>& profiles) const | ||
{ | ||
const auto instances = VsSetupConfiguration::QueryInstances(); | ||
|
||
VsDevCmdGenerator devCmdGenerator; | ||
VcDevCmdGenerator vcCmdGenerator; | ||
VsDevShellGenerator devShellGenerator; | ||
|
||
// Instances are ordered from latest to oldest. Hide all but the profiles for the latest instance. | ||
bool hidden = false; | ||
for (auto const& instance : instances) | ||
{ | ||
devCmdGenerator.GenerateProfiles(instance, hidden, profiles); | ||
vcCmdGenerator.GenerateProfiles(instance, hidden, profiles); | ||
devShellGenerator.GenerateProfiles(instance, hidden, profiles); | ||
|
||
hidden = true; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/cascadia/TerminalSettingsModel/VisualStudioGenerator.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/*++ | ||
Copyright (c) Microsoft Corporation | ||
Licensed under the MIT license. | ||
Module Name: | ||
- VisualStudioGenerator | ||
Abstract: | ||
- Generator for Visual Studio shell profiles. Actual profile generation is delegated | ||
to separate classes that encapsulate different logic for cmd- and powershell-based shells, | ||
as well as VC startup scripts specific to the current processor architecture. | ||
Author(s): | ||
- Charles Willis - October 2020 | ||
- Heath Stewart - September 2021 | ||
--*/ | ||
|
||
#pragma once | ||
|
||
#include "IDynamicProfileGenerator.h" | ||
#include "VsSetupConfiguration.h" | ||
|
||
namespace winrt::Microsoft::Terminal::Settings::Model | ||
{ | ||
class VisualStudioGenerator : public IDynamicProfileGenerator | ||
{ | ||
public: | ||
std::wstring_view GetNamespace() const noexcept override; | ||
void GenerateProfiles(std::vector<winrt::com_ptr<implementation::Profile>>& profiles) const override; | ||
|
||
class IVisualStudioProfileGenerator | ||
{ | ||
public: | ||
virtual void GenerateProfiles(const VsSetupConfiguration::VsSetupInstance& instance, bool hidden, std::vector<winrt::com_ptr<implementation::Profile>>& profiles) const = 0; | ||
}; | ||
}; | ||
}; |
Oops, something went wrong.