Skip to content

Commit bd602e5

Browse files
committed
Reset progress messages at end of REPL
This seems to work. We needed to hold onto processed progress records, and then at the end of the REPL mark each as completed and re-write it (which uses the underlying host and effectively clears it).
1 parent 640eac8 commit bd602e5

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/PowerShellEditorServices/Services/PowerShell/Host/EditorServicesConsolePSHostUserInterface.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ internal class EditorServicesConsolePSHostUserInterface : PSHostUserInterface
2222

2323
private readonly PSHostUserInterface _consoleHostUI;
2424

25+
private readonly HashSet<(long, ProgressRecord)> _currentProgressRecords = new();
26+
2527
public EditorServicesConsolePSHostUserInterface(
2628
ILoggerFactory loggerFactory,
2729
IReadLineProvider readLineProvider,
@@ -103,7 +105,30 @@ public override PSCredential PromptForCredential(string caption, string message,
103105

104106
public override void WriteLine(string value) => _underlyingHostUI.WriteLine(value);
105107

106-
public override void WriteProgress(long sourceId, ProgressRecord record) => _underlyingHostUI.WriteProgress(sourceId, record);
108+
public override void WriteProgress(long sourceId, ProgressRecord record)
109+
{
110+
if (record.RecordType == ProgressRecordType.Completed)
111+
{
112+
_currentProgressRecords.Remove((sourceId, record));
113+
}
114+
else
115+
{
116+
_currentProgressRecords.Add((sourceId, record));
117+
}
118+
_underlyingHostUI.WriteProgress(sourceId, record);
119+
}
120+
121+
public void ResetProgress()
122+
{
123+
// Mark all processed progress records as completed.
124+
foreach ((long id, ProgressRecord record) in _currentProgressRecords)
125+
{
126+
record.RecordType = ProgressRecordType.Completed;
127+
_underlyingHostUI.WriteProgress(id, record);
128+
_currentProgressRecords.Clear();
129+
}
130+
// TODO: Maybe send the OSC sequence to turn off progress indicator.
131+
}
107132

108133
public override void WriteVerboseLine(string message) => _underlyingHostUI.WriteVerboseLine(message);
109134

src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,14 @@ private void DoOneRepl(CancellationToken cancellationToken)
662662
UI.WriteErrorLine($"An error occurred while running the REPL loop:{Environment.NewLine}{e}");
663663
_logger.LogError(e, "An error occurred while running the REPL loop");
664664
}
665+
finally
666+
{
667+
// After the REPL we need to complete all progress records.
668+
if (UI is EditorServicesConsolePSHostUserInterface ui)
669+
{
670+
ui.ResetProgress();
671+
}
672+
}
665673
}
666674

667675
private string GetPrompt(CancellationToken cancellationToken)

0 commit comments

Comments
 (0)