Use local build of adl-server when debugging VS extension

This commit is contained in:
Nick Guerrera 2021-04-01 16:33:53 -07:00
Родитель 7b0b01ac99
Коммит 9db0568a45
4 изменённых файлов: 59 добавлений и 3 удалений

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

@ -9,3 +9,8 @@ charset = utf-8
[*.cs]
csharp_new_line_before_open_brace = none
csharp_new_line_before_catch = false
csharp_new_line_before_else = false
csharp_new_line_before_finally = false
csharp_new_line_before_members_in_anonymous_types = false
csharp_new_line_before_members_in_object_initializers = false

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

@ -4,17 +4,18 @@
<TargetFramework>net472</TargetFramework>
<DebugType>Embedded</DebugType>
<EmbedAllSources>true</EmbedAllSources>
<StartAction>Program</StartAction>
<StartProgram>$(DevEnvDir)devenv.exe</StartProgram>
<StartArguments>/rootsuffix Exp</StartArguments>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<DeployExtension Condition="'$(Configuration)' != 'Debug'">false</DeployExtension>
<EnableDefaultNoneItems>false</EnableDefaultNoneItems>
<LangVersion>Latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<Content Include="LICENSE" />
<Content Include="adl.pkgdef" />
<Content Include="node_modules/adl-vscode/dist/adl.tmLanguage" Link="TextMate/adl.tmLanguage" />
<Content Include="$(IntermediateOutputPath)DebugSourceDirectory.txt" Link="DebugSourceDirectory.txt" Condition="'$(Configuration)' == 'Debug'"/>
<Content Update="@(Content)" IncludeInVSIX="true" CopyToOutputDirectory="PreserveNewest" />
<None Include="*;Properties\*" Exclude="@(Content);*.sln" />
<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" />
@ -25,4 +26,7 @@
<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>
<Target Name="WriteDebugSourceDirectory" Condition="'$(Configuration)' == 'Debug'" BeforeTargets="BeforeBuild">
<WriteLinesToFile File="$(IntermediateOutputPath)DebugSourceDirectory.txt" Lines="$(MSBuildThisFileDirectory)" WriteOnlyWhenDifferent="true" Overwrite="true" />
</Target>
</Project>

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

@ -0,0 +1,13 @@
{
"profiles": {
"Microsoft.Adl.VisualStudio": {
"commandName": "Executable",
"executablePath": "devenv.exe",
"commandLineArgs": "/rootSuffix Exp",
"environmentVariables": {
"ADL_SERVER_NODE_OPTIONS": "--nolazy --inspect=4242",
"ADL_DEVELOPMENT_MODE": "true"
}
}
}
}

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

@ -2,6 +2,8 @@ using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
@ -42,15 +44,29 @@ namespace Microsoft.Adl.VisualStudio {
public async Task<Connection> ActivateAsync(CancellationToken token) {
await Task.Yield();
var options = Environment.GetEnvironmentVariable("ADL_SERVER_NODE_OPTIONS");
var info = new ProcessStartInfo {
// Use adl-server on PATH in production
FileName = "adl-server.cmd",
Arguments = "--stdio",
RedirectStandardInput = true,
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true,
Environment = { new("NODE_OPTIONS", options) },
};
#if DEBUG
// Use local build of adl-server in development (lauched from F5 in VS)
if (InDevelopmentMode()) {
var module = GetDevelopmentAdlServerPath();
info.FileName = "node.exe";
info.Arguments = $"{options} {module} {info.Arguments}";
// --nolazy isn't supported by NODE_OPTIONS so we pass these via CLI instead
info.Environment.Remove("NODE_OPTIONS");
}
#endif
var process = Process.Start(info);
return new Connection(process.StandardOutput.BaseStream, process.StandardInput.BaseStream);
}
@ -66,5 +82,23 @@ namespace Microsoft.Adl.VisualStudio {
public Task OnServerInitializedAsync() {
return Task.CompletedTask;
}
#if DEBUG
static bool InDevelopmentMode() {
return string.Equals(
Environment.GetEnvironmentVariable("ADL_DEVELOPMENT_MODE"),
"true",
StringComparison.OrdinalIgnoreCase);
}
static string GetDevelopmentAdlServerPath() {
// Even when debugging, we get deployed to an extension folder outside the source
// tree, so we stash the source directory in a file in debug builds so we can use it
// to run adl-server against the live developer build in the source tree.
var thisDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var srcDir = File.ReadAllText(Path.Combine(thisDir, "DebugSourceDirectory.txt")).Trim();
return Path.GetFullPath(Path.Combine(srcDir, "../adl/cmd/adl-server.js"));
}
#endif
}
}