Browse Source

Write IL-with-C# comment slices as spans

The "IL with C#" view cut up to four substrings (prefix, trimmed
prefix, highlighted range, suffix) out of every source line emitted
alongside an IL instruction. ISmartTextOutput now accepts a
ReadOnlySpan<char> - as a default interface method falling back to
Write(text.ToString()) so existing implementers keep working - and
AvaloniaEditTextOutput appends the span straight into its
StringBuilder. The overload lives on ISmartTextOutput rather than
ITextOutput because the latter is netstandard2.0 (no default interface
methods there), where a new member would break every external
implementer of the decompiler library; the highlighted-comment path is
typed against ISmartTextOutput already.

Assisted-by: Claude:claude-fable-5:Claude Code
pull/3963/head
Christoph Wille 1 month ago
parent
commit
0ff17e5b8a
  1. 8
      ILSpy/Languages/CSharpILMixedLanguage.cs
  2. 7
      ILSpy/TextView/AvaloniaEditTextOutput.cs
  3. 7
      ILSpy/TextView/ISmartTextOutput.cs

8
ILSpy/Languages/CSharpILMixedLanguage.cs

@ -181,13 +181,13 @@ namespace ICSharpCode.ILSpy.Languages @@ -181,13 +181,13 @@ namespace ICSharpCode.ILSpy.Languages
output.Write("// ");
output.BeginSpan(gray);
if (isSingleLine)
output.Write(text.Substring(0, startColumn).TrimStart());
output.Write(text.AsSpan(0, startColumn).TrimStart());
else
output.Write(text.Substring(0, startColumn));
output.Write(text.AsSpan(0, startColumn));
output.EndSpan();
output.Write(text.Substring(startColumn, endColumn - startColumn));
output.Write(text.AsSpan(startColumn, endColumn - startColumn));
output.BeginSpan(gray);
output.Write(text.Substring(endColumn));
output.Write(text.AsSpan(endColumn));
output.EndSpan();
output.WriteLine();
}

7
ILSpy/TextView/AvaloniaEditTextOutput.cs

@ -186,6 +186,13 @@ namespace ICSharpCode.ILSpy.TextView @@ -186,6 +186,13 @@ namespace ICSharpCode.ILSpy.TextView
CheckLength();
}
public void Write(ReadOnlySpan<char> text)
{
WriteIndentIfNeeded();
builder.Append(text);
CheckLength();
}
public void WriteLine()
{
if (IgnoreNewLineAndIndent)

7
ILSpy/TextView/ISmartTextOutput.cs

@ -48,6 +48,13 @@ namespace ICSharpCode.ILSpy.TextView @@ -48,6 +48,13 @@ namespace ICSharpCode.ILSpy.TextView
void BeginSpan(HighlightingColor highlightingColor);
void EndSpan();
/// <summary>
/// Writes a slice of text without requiring the caller to allocate an intermediate
/// string. Implementations that buffer internally should override the default,
/// which falls back to <see cref="ITextOutput.Write(string)"/>.
/// </summary>
void Write(ReadOnlySpan<char> text) => Write(text.ToString());
/// <summary>
/// Title displayed in the document tab's header.
/// </summary>

Loading…
Cancel
Save