Add support for Visual Studio 2022 (#588)

This required splitting things into separate VSIXes per guidance here:

https://docs.microsoft.com/en-us/visualstudio/extensibility/migration/update-visual-studio-extension?view=vs-2022
This commit is contained in:
Nick Guerrera 2021-06-22 09:20:39 -07:00 коммит произвёл GitHub
Родитель fec91682a8
Коммит ff086dd933
15 изменённых файлов: 290 добавлений и 102 удалений

Просмотреть файл

@ -1,30 +0,0 @@
<Project>
<Import Project="$(VSToolsPath)\VSSDK\Microsoft.VsSDK.targets"
Condition="'$(VSToolsPath)' != '' and '$(MSBuildRuntimeType)' != 'Core'" />
<!--
VS SDK does not currently support building with dotnet build.
-->
<Target Name="WarnAboutDotnetBuildAndVsix"
Condition="'$(MSBuildRuntimeType)' == 'Core'"
AfterTargets="AfterBuild">
<Message
Importance="High"
Text="VSIX packaging skipped: not supported by `dotnet build`, use Visual Studio `msbuild` to package VSIX." />
</Target>
<!--
Stash debug source directory so deployed debug vsix can use it to find
and adl-server under development in source tree.
-->
<Target Name="WriteDebugSourceDirectory"
Condition="'$(Configuration)' == 'Debug'"
BeforeTargets="BeforeBuild">
<WriteLinesToFile File="$(IntermediateOutputPath)DebugSourceDirectory.txt"
Lines="$(MSBuildThisFileDirectory)"
WriteOnlyWhenDifferent="true"
Overwrite="true" />
</Target>
<Target Name="GetVersionForVsixManifest" Returns="$(Version)" />
</Project>

Просмотреть файл

@ -1,10 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project>
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<DebugType>Embedded</DebugType>
<EmbedAllSources>true</EmbedAllSources>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<EnableDefaultNoneItems>false</EnableDefaultNoneItems>
<LangVersion>Latest</LangVersion>
<Nullable>Enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
@ -12,24 +11,22 @@
<Features>strict</Features>
<!-- Official build will pass in the real version from package.json, see scripts/build.js -->
<Version>42.42.42</Version>
<!-- Deployment enabled dynamically in targets if building in visual studio -->
<DeployExtension>false</DeployExtension>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<DeployExtension>false</DeployExtension>
<TargetVsixContainer>$(AssemblyName).vsix</TargetVsixContainer>
<TargetVsixContainer>$(MSBuildThisFileDirectory)$(AssemblyName).vsix</TargetVsixContainer>
</PropertyGroup>
<ItemGroup Condition="'$(Configuration)' == 'Debug'">
<Content Include="$(IntermediateOutputPath)DebugSourceDirectory.txt" Link="DebugSourceDirectory.txt" Visible="False" />
</ItemGroup>
<ItemGroup>
<Content Include="LICENSE" Visible="False"/>
<Content Include="*.pkgdef" />
<Content Include="node_modules/adl-vscode/dist/adl.tmLanguage" Link="TextMate/adl.tmLanguage" />
<Compile Include="$(MSBuildThisFileDirectory)src/**/*.cs" LinkBase="src" />
<Content Include="$(MSBuildThisFileDirectory)LICENSE" />
<Content Include="$(MSBuildThisFileDirectory)*.pkgdef" />
<Content Include="$(MSBuildThisFileDirectory)node_modules/adl-vscode/dist/adl.tmLanguage" Link="TextMate/adl.tmLanguage" />
<Content Update="@(Content)" IncludeInVSIX="true" CopyToOutputDirectory="PreserveNewest" />
<None Include="*.vsixmanifest" />
<None Include="Properties\*.json" />
<Reference Include="System.ComponentModel.Composition" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" />
<PackageReference Include="Microsoft.VisualStudio.SDK" Version="16.0.206" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.VSSDK.BuildTools" Version="16.10.23" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2" />
</ItemGroup>
</Project>

Просмотреть файл

@ -0,0 +1,40 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31202.260
MinimumVisualStudioVersion = 16.0.31202.260
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Adl.VS2019", "VS2019\Microsoft.Adl.VS2019.csproj", "{3B3CF7E4-5B54-47EA-8BE3-60D8F806C69E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Adl.VS2022", "VS2022\Microsoft.Adl.VS2022.csproj", "{C7566715-9191-4D95-B673-4E569800CE32}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{128D9265-5E6B-4C7E-889E-15EE684BEFD6}"
ProjectSection(SolutionItems) = preProject
scripts\build.js = scripts\build.js
Directory.Build.rsp = Directory.Build.rsp
Microsoft.Adl.VS.props = Microsoft.Adl.VS.props
Microsoft.Adl.VS.targets = Microsoft.Adl.VS.targets
nuget.config = nuget.config
package.json = package.json
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3B3CF7E4-5B54-47EA-8BE3-60D8F806C69E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3B3CF7E4-5B54-47EA-8BE3-60D8F806C69E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3B3CF7E4-5B54-47EA-8BE3-60D8F806C69E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3B3CF7E4-5B54-47EA-8BE3-60D8F806C69E}.Release|Any CPU.Build.0 = Release|Any CPU
{C7566715-9191-4D95-B673-4E569800CE32}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C7566715-9191-4D95-B673-4E569800CE32}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C7566715-9191-4D95-B673-4E569800CE32}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C7566715-9191-4D95-B673-4E569800CE32}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {1DFC3838-4459-4321-B2A1-D473D4654597}
EndGlobalSection
EndGlobal

Просмотреть файл

@ -0,0 +1,58 @@
<Project>
<Import
Project="$(VSToolsPath)\VSSDK\Microsoft.VsSDK.targets"
Condition="'$(VSToolsPath)' != '' and '$(MSBuildRuntimeType)' != 'Core'"
/>
<!--
Deploy the appropriate extension when building in visual studio to support F5
-->
<PropertyGroup Condition="'$(BuildingInsideVisualStudio)' == 'true'
and $([MSBuild]::VersionGreaterThanOrEquals($(VisualStudioVersion), $(VisualStudioMinVersionInclusive)))
and $([MSBuild]::VersionLessThan($(VisualStudioVersion), $(VisualStudioMaxVersionExclusive)))">
<DeployExtension>true</DeployExtension>
</PropertyGroup>
<!--
VS SDK does not currently support building with dotnet build.
-->
<Target
Name="WarnAboutDotnetBuildAndVsix"
Condition="'$(MSBuildRuntimeType)' == 'Core'"
AfterTargets="AfterBuild"
>
<Message
Importance="High"
Text="VSIX packaging skipped: not supported by `dotnet build`, use Visual Studio `msbuild` to package VSIX."
/>
</Target>
<!--
Stash debug source directory so deployed debug vsix can use it to find
and adl-server under development in source tree.
-->
<Target
Name="WriteDebugSourceDirectory"
Condition="'$(Configuration)' == 'Debug'"
BeforeTargets="BeforeBuild"
>
<WriteLinesToFile
File="$(IntermediateOutputPath)DebugSourceDirectory.txt"
Lines="$(MSBuildThisFileDirectory)"
WriteOnlyWhenDifferent="true"
Overwrite="true"
/>
</Target>
<Target
Name="LogVsixDeployment"
BeforeTargets="DeployVsixExtensionFiles"
Condition="'$(DeployExtension)' == 'true'"
>
<Message Importance="High" Text="$(TargetVsixContainer) -> $(VsixDeploymentPath)" />
</Target>
<Target Name="GetPackageVersionForVsixManifest" Returns="$(Version)" />
<Target Name="GetVSVersionRangeForVsixManifest" Returns="$(VSVersionRange)" />
</Project>

Просмотреть файл

@ -1,25 +0,0 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31202.260
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Adl.VisualStudio", "Microsoft.Adl.VisualStudio.csproj", "{E56D4BDB-4A17-4BBB-81C1-258FBA49979F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E56D4BDB-4A17-4BBB-81C1-258FBA49979F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E56D4BDB-4A17-4BBB-81C1-258FBA49979F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E56D4BDB-4A17-4BBB-81C1-258FBA49979F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E56D4BDB-4A17-4BBB-81C1-258FBA49979F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {1DFC3838-4459-4321-B2A1-D473D4654597}
EndGlobalSection
EndGlobal

Просмотреть файл

@ -0,0 +1,15 @@
<Project>
<Import Sdk="Microsoft.NET.Sdk" Project="Sdk.props" />
<Import Project="../Microsoft.Adl.VS.props" />
<PropertyGroup>
<DefineConstants>$(DefineConstants);VS2019</DefineConstants>
<VisualStudioMinVersionInclusive>16.0</VisualStudioMinVersionInclusive>
<VisualStudioMaxVersionExclusive>17.0</VisualStudioMaxVersionExclusive>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.SDK" Version="16.0.206" ExcludeAssets="Runtime" />
<PackageReference Include="Microsoft.VSSDK.BuildTools" Version="16.9.1050" PrivateAssets="All" />
</ItemGroup>
<Import Sdk="Microsoft.NET.Sdk" Project="Sdk.targets" />
<Import Project="../Microsoft.Adl.VS.targets" />
</Project>

Просмотреть файл

@ -1,9 +1,9 @@
{
"profiles": {
"Microsoft.Adl.VisualStudio": {
"Visual Studio Extension": {
"commandName": "Executable",
"executablePath": "$(DevEnvDir)devenv.exe",
"commandLineArgs": "/rootSuffix Exp ../../../adl-samples/petstore",
"commandLineArgs": "/rootSuffix Exp ../../../../adl-samples/petstore",
"environmentVariables": {
"ADL_SERVER_NODE_OPTIONS": "--nolazy --inspect=4242",
"ADL_DEVELOPMENT_MODE": "true"

Просмотреть файл

@ -1,14 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="88b9492f-c019-492c-8aeb-f325a7e4cf23" Version="|%CurrentProject%;GetVersionForVsixManifest|" Language="en-US" Publisher="Microsoft" />
<Identity Id="88b9492f-c019-492c-8aeb-f325a7e4cf23" Version="|%CurrentProject%;GetPackageVersionForVsixManifest|" Language="en-US" Publisher="Microsoft" />
<DisplayName>ADL Language Support</DisplayName>
<Description>ADL Language Support for Visual Studio</Description>
<Description>ADL Language Support for Visual Studio 2019</Description>
<MoreInfo>https://github.com/azure/adl</MoreInfo>
<License>LICENSE</License>
</Metadata>
<Installation>
<InstallationTarget Id="Microsoft.VisualStudio.Community" Version="[16.0,)" />
<InstallationTarget Id="Microsoft.VisualStudio.Community" Version="[16.0,17.0)" />
</Installation>
<Dependencies>
<Dependency Id="Microsoft.Framework.NDP" DisplayName="Microsoft .NET Framework" d:Source="Manual" Version="[4.7.2,)" />
@ -19,6 +19,6 @@
<Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project" Path="|%CurrentProject%|" />
</Assets>
<Prerequisites>
<Prerequisite Id="Microsoft.VisualStudio.Component.CoreEditor" Version="[16.0,)" DisplayName="Visual Studio core editor" />
<Prerequisite Id="Microsoft.VisualStudio.Component.CoreEditor" Version="[16.0,17.0)" DisplayName="Visual Studio core editor" />
</Prerequisites>
</PackageManifest>

Просмотреть файл

@ -0,0 +1,15 @@
<Project>
<Import Sdk="Microsoft.NET.Sdk" Project="Sdk.props" />
<Import Project="../Microsoft.Adl.VS.props" />
<PropertyGroup>
<DefineConstants>$(DefineConstants);VS2022</DefineConstants>
<VisualStudioMinVersionInclusive>17.0</VisualStudioMinVersionInclusive>
<VisualStudioMaxVersionExclusive>18.0</VisualStudioMaxVersionExclusive>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.SDK" Version="17.0.0-previews-1-31410-273" ExcludeAssets="Runtime" />
<PackageReference Include="Microsoft.VSSDK.BuildTools" Version="17.0.1619-preview1" PrivateAssets="All" />
</ItemGroup>
<Import Sdk="Microsoft.NET.Sdk" Project="Sdk.targets" />
<Import Project="../Microsoft.Adl.VS.targets" />
</Project>

Просмотреть файл

@ -0,0 +1,9 @@
{
"profiles": {
"N/A": {
"commandName": "Executable",
"executablePath": "cmd.exe",
"commandLineArgs": "/c echo Use Microsoft.Adl.VS2019 project to launch, even when using VS 2022."
}
}
}

Просмотреть файл

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="88b9492f-c019-492c-8aeb-f325a7e4cf23" Version="|%CurrentProject%;GetPackageVersionForVsixManifest|" Language="en-US" Publisher="Microsoft" />
<DisplayName>ADL Language Support</DisplayName>
<Description>ADL Language Support for Visual Studio 2022</Description>
<MoreInfo>https://github.com/azure/adl</MoreInfo>
<License>LICENSE</License>
</Metadata>
<Installation>
<InstallationTarget Id="Microsoft.VisualStudio.Community" Version="[17.0,18.0)">
<ProductArchitecture>amd64</ProductArchitecture>
</InstallationTarget>
</Installation>
<Dependencies>
<Dependency Id="Microsoft.Framework.NDP" DisplayName="Microsoft .NET Framework" d:Source="Manual" Version="[4.7.2,)" />
</Dependencies>
<Assets>
<Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="File" Path="adl.pkgdef" />
<Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="Project" Path="|%CurrentProject%;PkgdefProjectOutputGroup|" />
<Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project" Path="|%CurrentProject%|" />
</Assets>
<Prerequisites>
<Prerequisite Id="Microsoft.VisualStudio.Component.CoreEditor" Version="[17.0,18.0)" DisplayName="Visual Studio core editor" />
</Prerequisites>
</PackageManifest>

Просмотреть файл

@ -21,7 +21,8 @@
"node": ">=14.0.0"
},
"files": [
"Microsoft.Adl.VisualStudio.vsix"
"Microsoft.Adl.VS2019.vsix",
"Microsoft.Adl.VS2022.vsix"
],
"scripts": {
"build": "node scripts/build.js"

Просмотреть файл

@ -65,6 +65,6 @@ if (process.argv[2] === "--restore") {
msbuildArgs.push("/restore");
}
msbuildArgs.push(join(dir, "Microsoft.Adl.VisualStudio.csproj"));
msbuildArgs.push(join(dir, "Microsoft.Adl.VS.sln"));
proc = run(msbuild, msbuildArgs, { throwOnNonZeroExit: false });
process.exit(proc.status ?? 1);

Просмотреть файл

@ -51,7 +51,7 @@ namespace Microsoft.Adl.VisualStudio {
_outputWindow = window;
}
public async Task<Connection> ActivateAsync(CancellationToken token) {
public async Task<Connection?> ActivateAsync(CancellationToken token) {
await Task.Yield();
var options = Environment.GetEnvironmentVariable("ADL_SERVER_NODE_OPTIONS");

Просмотреть файл

@ -1,8 +1,8 @@
import { spawnSync, SpawnSyncOptions } from "child_process";
import { spawnSync, SpawnSyncOptionsWithStringEncoding } from "child_process";
import { mkdtemp, readdir, rmdir } from "fs/promises";
import mkdirp from "mkdirp";
import os from "os";
import path, { join, resolve } from "path";
import { basename, join, resolve } from "path";
import url from "url";
import yargs from "yargs";
import { CompilerOptions } from "../compiler/options.js";
@ -140,7 +140,7 @@ async function getCompilerOptions(): Promise<CompilerOptions> {
}
async function generateClient(options: CompilerOptions) {
const clientPath = path.resolve(args["output-path"], "client");
const clientPath = resolve(args["output-path"], "client");
const autoRestBin = process.platform === "win32" ? "autorest.cmd" : "autorest";
const autoRestPath = new url.URL(`../../node_modules/.bin/${autoRestBin}`, import.meta.url);
@ -168,9 +168,9 @@ async function generateClient(options: CompilerOptions) {
}
}
async function installVsix(pkg: string, install: (vsixPath: string) => void) {
async function installVsix(pkg: string, install: (vsixPaths: string[]) => void) {
// download npm package to temporary directory
const temp = await mkdtemp(path.join(os.tmpdir(), "adl"));
const temp = await mkdtemp(join(os.tmpdir(), "adl"));
const npmArgs = ["install"];
// hide npm output unless --debug was passed to adl
@ -183,24 +183,32 @@ async function installVsix(pkg: string, install: (vsixPath: string) => void) {
// to pass --prefix even though we're using cwd as otherwise, npm might
// find a package.json file in a parent directory and install to that
// directory.
npmArgs.push("--prefix", ".", pkg);
npmArgs.push("--prefix", ".");
// To debug with a locally built package rather than pulling from npm,
// specify the full path to the packed .tgz using ADL_DEBUG_VSIX_TGZ
// environment variable.
npmArgs.push(process.env.ADL_DEBUG_VSIX_TGZ ?? pkg);
run("npm", npmArgs, { cwd: temp });
// locate .vsix
const dir = path.join(temp, "node_modules", pkg);
const dir = join(temp, "node_modules", pkg);
const files = await readdir(dir);
let vsix: string | undefined;
let vsixPaths: string[] = [];
for (const file of files) {
if (file.endsWith(".vsix")) {
vsix = path.join(dir, file);
break;
vsixPaths.push(join(dir, file));
}
}
compilerAssert(vsix, `Installed ${pkg} from npm, but didn't find its .vsix file.`);
compilerAssert(
vsixPaths.length > 0,
`Installed ${pkg} from npm, but didn't find any .vsix files in it.`
);
// install extension
install(vsix);
install(vsixPaths);
// delete temporary directory
await rmdir(temp, { recursive: true });
@ -214,8 +222,8 @@ async function runCode(codeArgs: string[]) {
}
async function installVSCodeExtension() {
await installVsix("adl-vscode", (vsix) => {
runCode(["--install-extension", vsix]);
await installVsix("adl-vscode", (vsixPaths) => {
runCode(["--install-extension", vsixPaths[0]]);
});
}
@ -224,28 +232,94 @@ async function uninstallVSCodeExtension() {
}
function getVsixInstallerPath(): string {
return getVSInstallerPath(
"resources/app/ServiceHub/Services/Microsoft.VisualStudio.Setup.Service/VSIXInstaller.exe"
);
}
function getVSWherePath(): string {
return getVSInstallerPath("vswhere.exe");
}
function getVSInstallerPath(relativePath: string) {
if (process.platform !== "win32") {
console.error("error: Visual Studio extension is not supported on non-Windows");
console.error("error: Visual Studio extension is not supported on non-Windows.");
process.exit(1);
}
return join(
process.env["ProgramFiles(x86)"] ?? "",
"Microsoft Visual Studio/Installer/resources/app/ServiceHub/Services/Microsoft.VisualStudio.Setup.Service",
"VSIXInstaller.exe"
"Microsoft Visual Studio/Installer",
relativePath
);
}
function isVSInstalled(versionRange: string) {
const vswhere = getVSWherePath();
const proc = run(vswhere, ["-property", "instanceid", "-prerelease", "-version", versionRange], {
stdio: [null, "pipe", "inherit"],
allowNotFound: true,
});
return proc.status === 0 && proc.stdout;
}
const VSIX_ALREADY_INSTALLED = 1001;
const VSIX_NOT_INSTALLED = 1002;
const VSIX_USER_CANCELED = 2005;
async function installVSExtension() {
const vsixInstaller = getVsixInstallerPath();
await installVsix("@azure-tools/adl-vs", (vsix) => {
run(vsixInstaller, [vsix]);
const versionMap = new Map([
[
"Microsoft.Adl.VS2019.vsix",
{
friendlyVersion: "2019",
versionRange: "[16.0, 17.0)",
installed: false,
},
],
[
"Microsoft.Adl.VS2022.vsix",
{
friendlyVersion: "2022",
versionRange: "[17.0, 18.0)",
installed: false,
},
],
]);
let vsFound = false;
for (const entry of versionMap.values()) {
if (isVSInstalled(entry.versionRange)) {
vsFound = entry.installed = true;
}
}
if (!vsFound) {
console.error("error: No compatible version of Visual Studio found.");
process.exit(1);
}
await installVsix("@azure-tools/adl-vs", (vsixPaths) => {
for (const vsix of vsixPaths) {
const vsixFilename = basename(vsix);
const entry = versionMap.get(vsixFilename);
compilerAssert(entry, "Unexpected vsix filename:" + vsix);
if (entry.installed) {
console.log(`Installing extension for Visual Studio ${entry?.friendlyVersion}...`);
run(vsixInstaller, [vsix], {
allowedExitCodes: [VSIX_ALREADY_INSTALLED, VSIX_USER_CANCELED],
});
}
}
});
}
async function uninstallVSExtension() {
const vsixInstaller = getVsixInstallerPath();
run(vsixInstaller, ["/uninstall:88b9492f-c019-492c-8aeb-f325a7e4cf23"]);
run(vsixInstaller, ["/uninstall:88b9492f-c019-492c-8aeb-f325a7e4cf23"], {
allowedExitCodes: [VSIX_NOT_INSTALLED, VSIX_USER_CANCELED],
});
}
/**
@ -274,8 +348,10 @@ async function printInfo() {
// ENOENT checking and handles spaces poorly in some cases.
const isCmdOnWindows = ["code", "code-insiders", "npm"];
interface RunOptions extends SpawnSyncOptions {
interface RunOptions extends Partial<SpawnSyncOptionsWithStringEncoding> {
extraEnv?: NodeJS.ProcessEnv;
allowNotFound?: boolean;
allowedExitCodes?: number[];
}
function run(command: string, commandArgs: string[], options?: RunOptions) {
@ -293,18 +369,24 @@ function run(command: string, commandArgs: string[], options?: RunOptions) {
};
}
const baseCommandName = path.basename(command);
const baseCommandName = basename(command);
if (process.platform === "win32" && isCmdOnWindows.includes(command)) {
command += ".cmd";
}
const proc = spawnSync(command, commandArgs, {
const finalOptions: SpawnSyncOptionsWithStringEncoding = {
encoding: "utf-8",
stdio: "inherit",
...(options ?? {}),
});
};
const proc = spawnSync(command, commandArgs, finalOptions);
if (args.debug) {
console.log(proc);
}
if (proc.error) {
if ((proc.error as any).code === "ENOENT") {
if ((proc.error as any).code === "ENOENT" && !options?.allowNotFound) {
console.error(`error: Command '${baseCommandName}' not found.`);
if (args.debug) {
console.log(proc.error.stack);
@ -315,7 +397,7 @@ function run(command: string, commandArgs: string[], options?: RunOptions) {
}
}
if (proc.status !== 0) {
if (proc.status !== 0 && !options?.allowedExitCodes?.includes(proc.status ?? 0)) {
console.error(
`error: Command '${baseCommandName} ${commandArgs.join(" ")}' failed with exit code ${
proc.status