Skip to content
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

#351 Repl is slow when displaying lots of coloured output #352

Merged
merged 1 commit into from
Jun 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 9 additions & 4 deletions Common/Product/ReplWindow/Repl/OutputBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using System.Diagnostics;
using System.Text;
using System.Windows.Threading;
using Microsoft.VisualStudio.Text;

#if NTVS_FEATURE_INTERACTIVEWINDOW
namespace Microsoft.NodejsTools.Repl {
Expand Down Expand Up @@ -241,11 +242,15 @@ internal sealed class OutputBuffer : IDisposable {
}

if (entries.Length > 0) {
for (int i = 0; i < entries.Length; i++) {
var entry = entries[i];

_window.AppendOutput(entry.Properties.Color, entry.Buffer.ToString(), i == entries.Length - 1);
var colors = new List<ColoredSpan>();
var text = new StringBuilder();
foreach (var entry in entries) {
int start = text.Length;
text.Append(entry.Buffer.ToString());
colors.Add(new ColoredSpan(new Span(start, entry.Buffer.Length), entry.Properties.Color));
}
_window.AppendOutput(colors, text.ToString());

_window.TextView.Caret.EnsureVisible();
}
}
Expand Down
3 changes: 3 additions & 0 deletions Common/Product/ReplWindow/Repl/ReplOutputClassifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class ReplOutputClassifier : IClassifier {
if (startIndex < 0) {
startIndex = ~startIndex - 1;
}
if (startIndex < 0) {
startIndex = 0;
}

int spanEnd = span.End.Position;
for (int i = startIndex; i < coloredSpans.Count && coloredSpans[i].Span.Start < spanEnd; i++) {
Expand Down
29 changes: 15 additions & 14 deletions Common/Product/ReplWindow/Repl/ReplWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2087,15 +2087,11 @@ private sealed class CommandFilter : IOleCommandTarget {
}

public void WriteOutput(object output) {
UIThread(() => {
Write(output);
});
Write(output);
}

public void WriteError(object output) {
UIThread(() => {
Write(output, error: true);
});
Write(output, error: true);
}

private void Write(object text, bool error = false) {
Expand All @@ -2110,7 +2106,7 @@ private sealed class CommandFilter : IOleCommandTarget {
/// <summary>
/// Appends text to the output buffer and updates projection buffer to include it.
/// </summary>
internal void AppendOutput(ConsoleColor color, string text, bool lastOutput) {
internal void AppendOutput(IEnumerable<ColoredSpan> colors, string text) {
int oldBufferLength = _outputBuffer.CurrentSnapshot.Length;
int oldLineCount = _outputBuffer.CurrentSnapshot.LineCount;

Expand All @@ -2129,7 +2125,7 @@ private sealed class CommandFilter : IOleCommandTarget {
}

edit.Insert(oldBufferLength, text);
if (lastOutput && !_readingStdIn && !EndsWithLineBreak(text)) {
if (!_readingStdIn && !EndsWithLineBreak(text)) {
var lineBreak = GetLineBreak();
edit.Insert(oldBufferLength, lineBreak);
newOutputLength += lineBreak.Length;
Expand All @@ -2154,7 +2150,10 @@ private sealed class CommandFilter : IOleCommandTarget {
);

var outputSpan = new ReplSpan(trackingSpan, ReplSpanKind.Output);
_outputColors.Add(new ColoredSpan(span, color));
_outputColors.AddRange(colors.Select(cs => new ColoredSpan(
new Span(cs.Span.Start + oldBufferLength, cs.Span.Length),
cs.Color
)));

bool appended = false;

Expand Down Expand Up @@ -2210,7 +2209,11 @@ private sealed class CommandFilter : IOleCommandTarget {

private bool TryShowObject(object obj) {
UIElement element = obj as UIElement;
if (element != null) {
if (element == null) {
return false;
}

UIThread(() => {
_buffer.Flush();

// figure out where we're inserting the image
Expand Down Expand Up @@ -2244,10 +2247,8 @@ private sealed class CommandFilter : IOleCommandTarget {
OnInlineAdornmentAdded();
WriteLine(String.Empty);
WriteLine(String.Empty);
return true;
}

return false;
});
return true;
}

private void OnAdornmentLoaded(object source, EventArgs e) {
Expand Down