Skip to content

Add integrated console support via custom host implementation #368

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 20 commits into from
Mar 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,7 @@
"taskName": "Build",
"suppressTaskName": true,
"isBuildCommand": true,
"args": [ "Invoke-Build BuildHost" ]
},
{
"taskName": "Full Build",
"suppressTaskName": true,
"args": [ "Invoke-Build" ]
"args": [ "Invoke-Build Build" ]
},
{
"taskName": "Test",
Expand Down
21 changes: 8 additions & 13 deletions PowerShellEditorServices.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ if ($PSVersionTable.PSEdition -ne "Core") {
Add-Type -Assembly System.IO.Compression.FileSystem
}

task SetupDotNet -Before Restore, Clean, Build, BuildHost, Test, TestPowerShellApi, PackageNuGet {
task SetupDotNet -Before Restore, Clean, Build, Test, TestPowerShellApi, PackageNuGet {

# Fetch the SDK version from global.json
$requiredSdkVersion = "1.0.0-rc4-004771"

$needsInstall = $true
Expand Down Expand Up @@ -92,7 +91,7 @@ function NeedsRestore($rootPath) {
return ($projectAssets -eq $null) -or ((Get-ChildItem $rootPath).Length -gt $projectAssets.Length)
}

task Restore -If { "Restore" -in $BuildTask -or (NeedsRestore(".\src")) -or (NeedsRestore(".\test")) } -Before Clean, Build, BuildHost, Test {
task Restore -If { "Restore" -in $BuildTask -or (NeedsRestore(".\src")) -or (NeedsRestore(".\test")) } -Before Clean, Build, Test {
exec { & $script:dotnetExe restore }
}

Expand Down Expand Up @@ -136,17 +135,13 @@ task TestPowerShellApi -If { !$script:IsUnix } {
exec { & $script:dotnetExe restore .\src\PowerShellEditorServices\PowerShellEditorServices.csproj }
}

task BuildHost {
exec { & $script:dotnetExe build -c $Configuration .\src\PowerShellEditorServices.Host\PowerShellEditorServices.Host.csproj $script:TargetFrameworksParam }
}

task Build {
exec { & $script:dotnetExe build -c $Configuration .\PowerShellEditorServices.sln $script:TargetFrameworksParam }
exec { & $script:dotnetExe build -c $Configuration .\src\PowerShellEditorServices.Host\PowerShellEditorServices.Host.csproj $script:TargetFrameworksParam }
}

function UploadTestLogs {
if ($script:IsCIBuild) {
$testLogsPath = "$PSScriptRoot/test/PowerShellEditorServices.Test.Host/bin/$Configuration/net451/logs"
$testLogsPath = "$PSScriptRoot/test/PowerShellEditorServices.Test.Host/bin/$Configuration/net452/logs"
$testLogsZipPath = "$PSScriptRoot/TestLogs.zip"

if (Test-Path $testLogsPath) {
Expand All @@ -163,9 +158,9 @@ function UploadTestLogs {
}

task Test -If { !$script:IsUnix } {
exec { & $script:dotnetExe test -c $Configuration -f net451 .\test\PowerShellEditorServices.Test\PowerShellEditorServices.Test.csproj }
exec { & $script:dotnetExe test -c $Configuration -f net451 .\test\PowerShellEditorServices.Test.Protocol\PowerShellEditorServices.Test.Protocol.csproj }
exec { & $script:dotnetExe test -c $Configuration -f net451 .\test\PowerShellEditorServices.Test.Host\PowerShellEditorServices.Test.Host.csproj }
exec { & $script:dotnetExe test -c $Configuration -f net452 .\test\PowerShellEditorServices.Test\PowerShellEditorServices.Test.csproj }
exec { & $script:dotnetExe test -c $Configuration -f net452 .\test\PowerShellEditorServices.Test.Protocol\PowerShellEditorServices.Test.Protocol.csproj }
exec { & $script:dotnetExe test -c $Configuration -f net452 .\test\PowerShellEditorServices.Test.Host\PowerShellEditorServices.Test.Host.csproj }
}

task CITest (job Test -Safe), {
Expand All @@ -177,7 +172,7 @@ task CITest (job Test -Safe), {
}
}

task LayoutModule -After Build, BuildHost {
task LayoutModule -After Build {
New-Item -Force $PSScriptRoot\module\PowerShellEditorServices\bin\ -Type Directory | Out-Null
New-Item -Force $PSScriptRoot\module\PowerShellEditorServices\bin\Desktop -Type Directory | Out-Null
New-Item -Force $PSScriptRoot\module\PowerShellEditorServices\bin\Core -Type Directory | Out-Null
Expand Down
17 changes: 15 additions & 2 deletions module/PowerShellEditorServices/PowerShellEditorServices.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ function Start-EditorServicesHost {
[ValidateSet("Normal", "Verbose", "Error")]
$LogLevel = "Normal",

[switch]
$EnableConsoleRepl,

[string]
$DebugServiceOnly,

[switch]
$WaitForDebugger
)
Expand All @@ -58,6 +64,7 @@ function Start-EditorServicesHost {
New-Object Microsoft.PowerShell.EditorServices.Host.EditorServicesHost @(
$hostDetails,
$BundledModulesPath,
$EnableConsoleRepl.IsPresent,
$WaitForDebugger.IsPresent)

# Build the profile paths using the root paths of the current $profile variable
Expand All @@ -67,8 +74,14 @@ function Start-EditorServicesHost {
[System.IO.Path]::GetDirectoryName($profile.CurrentUserAllHosts));

$editorServicesHost.StartLogging($LogPath, $LogLevel);
$editorServicesHost.StartLanguageService($LanguageServicePort, $profilePaths);
$editorServicesHost.StartDebugService($DebugServicePort, $profilePaths);

if ($DebugServiceOnly.IsPresent) {
$editorServicesHost.StartDebugService($DebugServicePort, $profilePaths, $false);
}
else {
$editorServicesHost.StartLanguageService($LanguageServicePort, $profilePaths);
$editorServicesHost.StartDebugService($DebugServicePort, $profilePaths, $true);
}
}
catch {
Write-Error "PowerShell Editor Services host initialization failed, terminating."
Expand Down
53 changes: 40 additions & 13 deletions src/PowerShellEditorServices.Host/EditorServicesHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class EditorServicesHost
{
#region Private Fields

private bool enableConsoleRepl;
private HostDetails hostDetails;
private string bundledModulesPath;
private DebugAdapter debugAdapter;
Expand Down Expand Up @@ -58,11 +59,13 @@ public class EditorServicesHost
public EditorServicesHost(
HostDetails hostDetails,
string bundledModulesPath,
bool enableConsoleRepl,
bool waitForDebugger)
{
Validate.IsNotNull(nameof(hostDetails), hostDetails);

this.hostDetails = hostDetails;
this.enableConsoleRepl = enableConsoleRepl;
this.bundledModulesPath = bundledModulesPath;

#if DEBUG
Expand Down Expand Up @@ -143,6 +146,7 @@ public void StartLanguageService(int languageServicePort, ProfilePaths profilePa
new LanguageServer(
hostDetails,
profilePaths,
this.enableConsoleRepl,
new TcpSocketServerChannel(languageServicePort));

this.languageServer.Start().Wait();
Expand All @@ -158,23 +162,46 @@ public void StartLanguageService(int languageServicePort, ProfilePaths profilePa
/// Starts the debug service with the specified TCP socket port.
/// </summary>
/// <param name="debugServicePort">The port number for the debug service.</param>
public void StartDebugService(int debugServicePort, ProfilePaths profilePaths)
public void StartDebugService(
int debugServicePort,
ProfilePaths profilePaths,
bool useExistingSession)
{
this.debugAdapter =
new DebugAdapter(
hostDetails,
profilePaths,
new TcpSocketServerChannel(debugServicePort),
this.languageServer?.EditorOperations);
if (this.enableConsoleRepl && useExistingSession)
{
this.debugAdapter =
new DebugAdapter(
this.languageServer.EditorSession,
new TcpSocketServerChannel(debugServicePort));
}
else
{
this.debugAdapter =
new DebugAdapter(
hostDetails,
profilePaths,
new TcpSocketServerChannel(debugServicePort),
this.languageServer?.EditorOperations);
}

this.debugAdapter.SessionEnded +=
(obj, args) =>
{
Logger.Write(
LogLevel.Normal,
"Previous debug session ended, restarting debug service...");

this.StartDebugService(debugServicePort, profilePaths);
// Only restart if we're reusing the existing session
// or if we're not using the console REPL, otherwise
// the process should terminate
if (useExistingSession)
{
Logger.Write(
LogLevel.Normal,
"Previous debug session ended, restarting debug service...");

this.StartDebugService(debugServicePort, profilePaths, true);
}
else if (!this.enableConsoleRepl)
{
this.StartDebugService(debugServicePort, profilePaths, false);
}
};

this.debugAdapter.Start().Wait();
Expand Down Expand Up @@ -222,7 +249,7 @@ public void WaitForCompletion()

#if !CoreCLR
static void CurrentDomain_UnhandledException(
object sender,
object sender,
UnhandledExceptionEventArgs e)
{
// Log the exception
Expand Down
Loading