-
Notifications
You must be signed in to change notification settings - Fork 237
Use public InternalHost from origin runspace #874
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
TylerLeonhardt
merged 7 commits into
PowerShell:master
from
SeeminglyScience:use-origin-runspace-host
Mar 22, 2019
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7c3d38b
Use public InternalHost from origin runspace
SeeminglyScience 24e6489
Fix up RawUI.ReadKey
SeeminglyScience ee1636e
Pass $Host in the start up script
SeeminglyScience 696bd81
Address feedback
SeeminglyScience acf0090
Address feedback and also add doc comments
SeeminglyScience 871ff55
Make progress cache thread safe
SeeminglyScience b1f4781
Added comment about null
SeeminglyScience File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -32,6 +32,7 @@ public abstract class EditorServicesPSHostUserInterface : | |
{ | ||
#region Private Fields | ||
|
||
private readonly HashSet<ProgressKey> currentProgressMessages = new HashSet<ProgressKey>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thread safety pls 😄 ConcurrentBag There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed to using |
||
private PromptHandler activePromptHandler; | ||
private PSHostRawUserInterface rawUserInterface; | ||
private CancellationTokenSource commandLoopCancellationToken; | ||
|
@@ -83,6 +84,11 @@ public abstract class EditorServicesPSHostUserInterface : | |
/// </summary> | ||
protected ILogger Logger { get; private set; } | ||
|
||
/// <summary> | ||
/// Gets a value indicating whether writing progress is supported. | ||
/// </summary> | ||
internal protected virtual bool SupportsWriteProgress => false; | ||
|
||
#endregion | ||
|
||
#region Constructors | ||
|
@@ -582,17 +588,74 @@ public override void WriteErrorLine(string value) | |
} | ||
|
||
/// <summary> | ||
/// | ||
/// Invoked by <see cref="Cmdlet.WriteProgress(ProgressRecord)" /> to display a progress record. | ||
/// </summary> | ||
/// <param name="sourceId"></param> | ||
/// <param name="record"></param> | ||
public override void WriteProgress( | ||
/// <param name="sourceId"> | ||
/// Unique identifier of the source of the record. An int64 is used because typically, | ||
/// the 'this' pointer of the command from whence the record is originating is used, and | ||
/// that may be from a remote Runspace on a 64-bit machine. | ||
/// </param> | ||
/// <param name="record"> | ||
/// The record being reported to the host. | ||
/// </param> | ||
public sealed override void WriteProgress( | ||
long sourceId, | ||
ProgressRecord record) | ||
{ | ||
this.UpdateProgress( | ||
sourceId, | ||
ProgressDetails.Create(record)); | ||
// Maintain old behavior if this isn't overridden. | ||
if (!this.SupportsWriteProgress) | ||
{ | ||
this.UpdateProgress(sourceId, ProgressDetails.Create(record)); | ||
return; | ||
} | ||
|
||
// Keep a list of progress records we write so we can automatically | ||
// clean them up after the pipeline ends. | ||
if (record.RecordType == ProgressRecordType.Completed) | ||
{ | ||
this.currentProgressMessages.Remove(new ProgressKey(sourceId, record)); | ||
} | ||
else | ||
{ | ||
this.currentProgressMessages.Add(new ProgressKey(sourceId, record)); | ||
} | ||
|
||
this.WriteProgressImpl(sourceId, record); | ||
} | ||
|
||
/// <summary> | ||
/// Invoked by <see cref="Cmdlet.WriteProgress(ProgressRecord)" /> to display a progress record. | ||
/// </summary> | ||
/// <param name="sourceId"> | ||
/// Unique identifier of the source of the record. An int64 is used because typically, | ||
/// the 'this' pointer of the command from whence the record is originating is used, and | ||
/// that may be from a remote Runspace on a 64-bit machine. | ||
/// </param> | ||
/// <param name="record"> | ||
/// The record being reported to the host. | ||
/// </param> | ||
protected virtual void WriteProgressImpl(long sourceId, ProgressRecord record) | ||
{ | ||
} | ||
|
||
internal void ClearProgress() | ||
{ | ||
const string nonEmptyString = "noop"; | ||
if (!this.SupportsWriteProgress) | ||
{ | ||
return; | ||
} | ||
|
||
foreach (ProgressKey key in this.currentProgressMessages) | ||
{ | ||
// This constructor throws if the activity description is empty even | ||
// with completed records. | ||
var record = new ProgressRecord(key.ActivityId, nonEmptyString, nonEmptyString); | ||
SeeminglyScience marked this conversation as resolved.
Show resolved
Hide resolved
|
||
record.RecordType = ProgressRecordType.Completed; | ||
this.WriteProgressImpl(key.SourceId, record); | ||
} | ||
|
||
this.currentProgressMessages.Clear(); | ||
} | ||
|
||
#endregion | ||
|
@@ -917,6 +980,8 @@ private void PowerShellContext_ExecutionStatusChanged(object sender, ExecutionSt | |
// The command loop should only be manipulated if it's already started | ||
if (eventArgs.ExecutionStatus == ExecutionStatus.Aborted) | ||
{ | ||
this.ClearProgress(); | ||
|
||
// When aborted, cancel any lingering prompts | ||
if (this.activePromptHandler != null) | ||
{ | ||
|
@@ -932,6 +997,8 @@ private void PowerShellContext_ExecutionStatusChanged(object sender, ExecutionSt | |
// the display of the prompt | ||
if (eventArgs.ExecutionStatus != ExecutionStatus.Running) | ||
{ | ||
this.ClearProgress(); | ||
|
||
// Execution has completed, start the input prompt | ||
this.ShowCommandPrompt(); | ||
StartCommandLoop(); | ||
|
@@ -948,11 +1015,48 @@ private void PowerShellContext_ExecutionStatusChanged(object sender, ExecutionSt | |
(eventArgs.ExecutionStatus == ExecutionStatus.Failed || | ||
eventArgs.HadErrors)) | ||
{ | ||
this.ClearProgress(); | ||
this.WriteOutput(string.Empty, true); | ||
var unusedTask = this.WritePromptStringToHostAsync(CancellationToken.None); | ||
} | ||
} | ||
|
||
#endregion | ||
|
||
private readonly struct ProgressKey : IEquatable<ProgressKey> | ||
{ | ||
internal readonly long SourceId; | ||
|
||
internal readonly int ActivityId; | ||
|
||
internal readonly int ParentActivityId; | ||
|
||
internal ProgressKey(long sourceId, ProgressRecord record) | ||
{ | ||
SourceId = sourceId; | ||
ActivityId = record.ActivityId; | ||
ParentActivityId = record.ParentActivityId; | ||
} | ||
|
||
public bool Equals(ProgressKey other) | ||
{ | ||
return SourceId == other.SourceId | ||
&& ActivityId == other.ActivityId | ||
&& ParentActivityId == other.ParentActivityId; | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
// Algorithm from https://stackoverflow.com/questions/1646807/quick-and-simple-hash-code-combinations | ||
unchecked | ||
{ | ||
int hash = 17; | ||
hash = hash * 31 + SourceId.GetHashCode(); | ||
hash = hash * 31 + ActivityId.GetHashCode(); | ||
hash = hash * 31 + ParentActivityId.GetHashCode(); | ||
return hash; | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.