mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-08-02 18:17:30 +08:00
Update documentation packages to latest versions
* HighlightService was modified to support GetClassifiedSpansAsync method * Updated Program.cs to pull in the proper location of the Json and ImageSharp extension projects * Statiq must have changed how they are doing xrefs, so I adjusted those to be more specific with a few links
This commit is contained in:

committed by
Patrik Svensson

parent
ab8384acf6
commit
43e9669395
@ -15,7 +15,7 @@
|
||||
|
||||
<div id="container">
|
||||
<div id="console">
|
||||
<div class="line"><span style="color:var(--brightBlack)">╭─</span><span style="color:var(--folder)"></span><span style="background-color:var(--folder);color:var(--black)"> ~/spectre.console</span><span style="color:var(--folder);background-color:var(--dotnet)"></span><span style="background-color:var(--blue)"> .NET 8.0 </span><span style="color:var(--dotnet);background-color:var(--git)"></span><span style="background-color:var(--git);color:var(--background)">  main </span><span style="color:var(--git)"></span></div>
|
||||
<div class="line"><span style="color:var(--brightBlack)">╭─</span><span style="color:var(--folder)"></span><span style="background-color:var(--folder);color:var(--black)"> ~/spectre.console</span><span style="color:var(--folder);background-color:var(--dotnet)"></span><span style="background-color:var(--blue)"> .NET 9.0 </span><span style="color:var(--dotnet);background-color:var(--git)"></span><span style="background-color:var(--git);color:var(--background)">  main </span><span style="color:var(--git)"></span></div>
|
||||
<div class="line"><span style="color:var(--brightBlack)">╰─</span> dotnet run</div>
|
||||
<div class="line"></div>
|
||||
<div class="line">╭────────────────────────────────────────────────────────╮</div>
|
||||
|
@ -58,21 +58,31 @@ internal static class HighlightService
|
||||
}
|
||||
|
||||
var text = await syntaxReference.SyntaxTree.GetTextAsync();
|
||||
// we need a workspace, but it seems it is only used to resolve a few services and nothing else so an empty one will suffice
|
||||
return HighlightElement(_emptyWorkspace, model, text, textSpan, indent);
|
||||
|
||||
// we need a document for the syntax highlighter, so create a temporary solution and project to hold it.
|
||||
var workspace = new AdhocWorkspace();
|
||||
var solution = workspace.CurrentSolution
|
||||
.AddProject("TempProject", "TempProject", "C#")
|
||||
.AddDocument("TempDocument", await syntaxReference.SyntaxTree.GetTextAsync());
|
||||
|
||||
var document = solution.Project.Documents.First();
|
||||
|
||||
var highlightElement = await HighlightElement(document, text, textSpan, indent);
|
||||
return highlightElement;
|
||||
}
|
||||
|
||||
private static int GetIndent(SyntaxTriviaList leadingTrivia)
|
||||
{
|
||||
var whitespace = leadingTrivia.FirstOrDefault(i => i.Kind() == SyntaxKind.WhitespaceTrivia);
|
||||
var whitespace = leadingTrivia.FirstOrDefault(i => i.IsKind(SyntaxKind.WhitespaceTrivia));
|
||||
return whitespace == default ? 0 : whitespace.Span.Length;
|
||||
}
|
||||
|
||||
private static string HighlightElement(Workspace workspace, SemanticModel semanticModel, SourceText fullSourceText,
|
||||
private static async Task<string> HighlightElement(Document document,
|
||||
SourceText fullSourceText,
|
||||
TextSpan textSpan, int indent)
|
||||
{
|
||||
|
||||
var classifiedSpans = Classifier.GetClassifiedSpans(semanticModel, textSpan, workspace);
|
||||
var classifiedSpans = await Classifier.GetClassifiedSpansAsync(document, textSpan);
|
||||
return HighlightElement(classifiedSpans, fullSourceText, indent);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user