Skip to content

Instantly share code, notes, and snippets.

@0xF6
Created July 1, 2019 23:45
Show Gist options
  • Select an option

  • Save 0xF6/f4f75867ebf7af19953d82f9a8c7d3aa to your computer and use it in GitHub Desktop.

Select an option

Save 0xF6/f4f75867ebf7af19953d82f9a8c7d3aa to your computer and use it in GitHub Desktop.
namespace ConsoleApp9
{
using System;
using Pixie;
using Pixie.Code;
using Pixie.Markup;
using Pixie.Terminal;
using Pixie.Terminal.Render;
using Pixie.Transforms;
class Program
{
private static LogEntry MakeDiagnostic(LogEntry entry)
{
return DiagnosticExtractor.Transform(entry, new Text("program"));
}
private const string SourceCode = @"public static class Program
{
public Program()
{
}
}";
static void Main(string[] args)
{
ILog log = TerminalLog
.Acquire()
.WithRenderers(new NodeRenderer[]
{
new HighlightedSourceRenderer(5)
});
log = new TransformLog(
log,
new Func<LogEntry, LogEntry>[]
{
MakeDiagnostic
});
var doc = new StringDocument("code.cs", SourceCode);
var ctorStartOffset = SourceCode.IndexOf("public Program()", StringComparison.InvariantCulture);
var ctorNameOffset = SourceCode.IndexOf("Program()", StringComparison.InvariantCulture);
var highlightRegion = new SourceRegion(
new SourceSpan(doc, ctorStartOffset, "public Program()".Length))
.ExcludeCharacters(char.IsWhiteSpace);
var focusRegion = new SourceRegion(
new SourceSpan(doc, ctorNameOffset, "Program".Length));
log.Log(
new LogEntry(
Severity.Error,
"hello world",
new MarkupNode[]
{
new Text("look at this beautiful error message!"),
new HighlightedSource(highlightRegion, focusRegion)
}));
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment