Skip to content

Add Start-EditorServices script from vscode-powershell repo #639

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Mar 22, 2018
50 changes: 17 additions & 33 deletions test/PowerShellEditorServices.Test.Host/ServerTestsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Diagnostics;
using System.IO;
using System.Text;
Copy link
Contributor

@rkeithhill rkeithhill Mar 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add this right before this line:

#if CoreCLR
using System.Reflection;
#endif

Without this, my build within VS 2017 fails with:

Severity	Code	Description	Project	File	Line	Suppression State
Error	CS1061	'Type' does not contain a definition for 'GetTypeInfo' and no extension method 'GetTypeInfo' accepting a first argument of type 'Type' could be found (are you missing a using directive or an assembly reference?)	PowerShellEditorServices.Test.Host(netcoreapp2.0)	C:\Users\Keith\GitHub\rkeithhill\PowerShellEditorServices\test\PowerShellEditorServices.Test.Host\ServerTestsBase.cs	42	Active

using System.Threading;
using System.Threading.Tasks;

namespace Microsoft.PowerShell.EditorServices.Test.Host
Expand All @@ -35,12 +36,15 @@ protected async Task<Tuple<int, int>> LaunchService(
string scriptPath = Path.Combine(modulePath, "Start-EditorServices.ps1");

#if CoreCLR
string assemblyPath = this.GetType().GetTypeInfo().Assembly.Location;
FileVersionInfo fileVersionInfo =
FileVersionInfo.GetVersionInfo(this.GetType().GetTypeInfo().Assembly.Location);
FileVersionInfo.GetVersionInfo(assemblyPath);
#else
string assemblyPath = this.GetType().Assembly.Location;
FileVersionInfo fileVersionInfo =
FileVersionInfo.GetVersionInfo(this.GetType().Assembly.Location);
FileVersionInfo.GetVersionInfo(assemblyPath);
#endif
string sessionPath = Path.Combine(Path.GetDirectoryName(assemblyPath), "session.json");

string editorServicesModuleVersion =
string.Format(
Expand All @@ -59,7 +63,7 @@ protected async Task<Tuple<int, int>> LaunchService(
"-BundledModulesPath \\\"" + modulePath + "\\\" " +
"-LogLevel \"Verbose\" " +
"-LogPath \"" + logPath + "\" " +
"-SessionDetailsPath \".\\sessionDetails\" " +
"-SessionDetailsPath \"" + sessionPath + "\" " +
"-FeatureFlags @() " +
"-AdditionalModules @() ",
editorServicesModuleVersion);
Expand Down Expand Up @@ -98,40 +102,20 @@ protected async Task<Tuple<int, int>> LaunchService(
this.serviceProcess.Start();

// Wait for the server to finish initializing
Task<string> stdoutTask = this.serviceProcess.StandardOutput.ReadLineAsync();
Task<string> stderrTask = this.serviceProcess.StandardError.ReadLineAsync();
Task<string> completedRead = await Task.WhenAny<string>(stdoutTask, stderrTask);

if (completedRead == stdoutTask)
while(!File.Exists(sessionPath))
{
JObject result = JObject.Parse(completedRead.Result);
if (result["status"].Value<string>() == "started")
{
return new Tuple<int, int>(
result["languageServicePort"].Value<int>(),
result["debugServicePort"].Value<int>());
}

return null;
Thread.Sleep(100);
}
else
{
// Must have read an error? Keep reading from error stream
string errorString = completedRead.Result;
Task<string> errorRead = this.serviceProcess.StandardError.ReadToEndAsync();

// Lets give the read operation 5 seconds to complete. Ideally, it shouldn't
// take that long at all, but just in case...
if (errorRead.Wait(5000))
{
if (!string.IsNullOrEmpty(errorRead.Result))
{
errorString += errorRead.Result + Environment.NewLine;
}
}

throw new Exception("Could not launch powershell.exe:\r\n\r\n" + errorString);
JObject result = JObject.Parse(File.ReadAllText(sessionPath));
if (result["status"].Value<string>() == "started")
{
return new Tuple<int, int>(
result["languageServicePort"].Value<int>(),
result["debugServicePort"].Value<int>());
}

return null;
}

protected void KillService()
Expand Down