Skip to content

Commit

Permalink
Fix: OnOutputBatch.cs syntax highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
huntercfreeman committed May 3, 2024
1 parent 3b8683e commit 104f72c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 10 deletions.
24 changes: 18 additions & 6 deletions Source/Lib/Ide/Ide.RazorLib/Events/Models/OnOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Luthetus.TextEditor.RazorLib.Lexes.Models;
using Luthetus.TextEditor.RazorLib.TextEditors.Displays;
using Luthetus.TextEditor.RazorLib.TextEditors.Models;
using System.Collections.Generic;

namespace Luthetus.Ide.RazorLib.Events.Models;

Expand All @@ -24,13 +25,15 @@ public class OnOutput : ITextEditorTask
private readonly TerminalCommandBoundary _terminalCommandBoundary;

public OnOutput(
int outputOffset,
string output,
List<TextEditorTextSpan> outputTextSpanList,
ResourceUri resourceUri,
ITextEditorService textEditorService,
TerminalCommandBoundary terminalCommandBoundary,
Key<TextEditorViewModel> viewModelKey)
{
OutputOffset = outputOffset;
Output = output;
_outputTextSpanList = outputTextSpanList;
ResourceUri = resourceUri;
Expand All @@ -45,6 +48,7 @@ public OnOutput(
public Key<BackgroundTaskQueue> QueueKey { get; } = ContinuousBackgroundTaskWorker.GetQueueKey();
public string Name { get; } = nameof(OnOutput);
public Task? WorkProgress { get; }
public int OutputOffset { get; }
public string Output { get; }
public ResourceUri ResourceUri { get; }
public ITextEditorService TextEditorService { get; }
Expand Down Expand Up @@ -101,25 +105,33 @@ await editContext.TextEditorService.ModelApi.ApplyDecorationRangeFactory(
{
if (oldEvent is OnOutput oldEventOnOutput)
{
var outputList = new List<string>
var localOutputList = new List<string>
{
oldEventOnOutput.Output,
Output
};

var localOutputTextSpanAndOffsetTupleList = new List<(int OutputOffset, List<TextEditorTextSpan> OutputTextSpan)>
{
(oldEventOnOutput.OutputOffset, oldEventOnOutput._outputTextSpanList),
(OutputOffset, _outputTextSpanList)
};

return new OnOutputBatch(
outputList,
_outputTextSpanList,
oldEventOnOutput.OutputOffset,
localOutputList,
localOutputTextSpanAndOffsetTupleList,
ResourceUri,
TextEditorService,
_terminalCommandBoundary,
ViewModelKey);
}

if (oldEvent is OnOutputBatch oldEventOnWheelBatch)
if (oldEvent is OnOutputBatch oldOnOutputBatch)
{
oldEventOnWheelBatch.OutputList.Add(Output);
return oldEventOnWheelBatch;
oldOnOutputBatch.OutputList.Add(Output);
oldOnOutputBatch.OutputTextSpanAndOffsetTupleList.Add((OutputOffset, _outputTextSpanList));
return oldOnOutputBatch;
}

return null;
Expand Down
24 changes: 20 additions & 4 deletions Source/Lib/Ide/Ide.RazorLib/Events/Models/OnOutputBatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Luthetus.TextEditor.RazorLib;
using Luthetus.TextEditor.RazorLib.TextEditors.Displays;
using Luthetus.TextEditor.RazorLib.TextEditors.Models;
using System;

namespace Luthetus.Ide.RazorLib.Events.Models;

Expand All @@ -19,28 +20,31 @@ public class OnOutputBatch : ITextEditorTask
private readonly TerminalCommandBoundary _terminalCommandBoundary;

public OnOutputBatch(
int batchOutputOffset,
List<string> outputList,
List<TextEditorTextSpan> outputTextSpanList,
List<(int OutputOffset, List<TextEditorTextSpan> OutputTextSpan)> outputTextSpanAndOffsetTupleList,
ResourceUri resourceUri,
ITextEditorService textEditorService,
TerminalCommandBoundary terminalCommandBoundary,
Key<TextEditorViewModel> viewModelKey)
{
BatchOutputOffset = batchOutputOffset;
OutputList = outputList;
_outputTextSpanList = outputTextSpanList;
OutputTextSpanAndOffsetTupleList = outputTextSpanAndOffsetTupleList;
ResourceUri = resourceUri;
TextEditorService = textEditorService;
_terminalCommandBoundary = terminalCommandBoundary;
ViewModelKey = viewModelKey;
}

private List<TextEditorTextSpan> _outputTextSpanList;

public Key<BackgroundTask> BackgroundTaskKey { get; } = Key<BackgroundTask>.NewKey();
public Key<BackgroundTaskQueue> QueueKey { get; } = ContinuousBackgroundTaskWorker.GetQueueKey();
public string Name { get; } = nameof(OnOutput);
public Task? WorkProgress { get; }
public int BatchOutputOffset { get; }
public List<string> OutputList { get; }
public List<(int OutputOffset, List<TextEditorTextSpan> OutputTextSpanList)> OutputTextSpanAndOffsetTupleList { get; }
public ResourceUri ResourceUri { get; }
public ITextEditorService TextEditorService { get; }
public Key<TextEditorViewModel> ViewModelKey { get; }
Expand All @@ -49,9 +53,21 @@ public OnOutputBatch(

public Task InvokeWithEditContext(IEditContext editContext)
{
// Flatten 'OutputTextSpanAndOffsetTupleList'
var outputTextSpanList = new List<TextEditorTextSpan>();
foreach (var tuple in OutputTextSpanAndOffsetTupleList)
{
outputTextSpanList.AddRange(tuple.OutputTextSpanList.Select(x => x with
{
StartingIndexInclusive = x.StartingIndexInclusive + tuple.OutputOffset - BatchOutputOffset,
EndingIndexExclusive = x.EndingIndexExclusive + tuple.OutputOffset - BatchOutputOffset,
}));
}

var onOutput = new OnOutput(
BatchOutputOffset,
string.Join(string.Empty, OutputList),
_outputTextSpanList,
outputTextSpanList,
ResourceUri,
TextEditorService,
_terminalCommandBoundary,
Expand Down
5 changes: 5 additions & 0 deletions Source/Lib/Ide/Ide.RazorLib/Terminals/Models/Terminal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ public Task EnqueueCommandAsync(TerminalCommand terminalCommand)

var terminalCommandBoundary = new TerminalCommandBoundary();

var outputOffset = 0;

await command.Observe(_commandCancellationTokenSource.Token)
.ForEachAsync(cmdEvent =>
{
Expand Down Expand Up @@ -182,12 +184,15 @@ await command.Observe(_commandCancellationTokenSource.Token)
outputTextSpanList = terminalCommand.OutputParser.ParseLine(output);

_textEditorService.Post(new OnOutput(
outputOffset,
output,
outputTextSpanList,
ResourceUri,
_textEditorService,
terminalCommandBoundary,
TextEditorViewModelKey));

outputOffset += output.Length;
}

DispatchNewStateKey();
Expand Down

0 comments on commit 104f72c

Please sign in to comment.