-
╭─ ~/spectre.console .NET 8.0 main
+
╭─ ~/spectre.console .NET 9.0 main
╰─ dotnet run
╭────────────────────────────────────────────────────────╮
diff --git a/docs/src/Utilities/HighlightService.cs b/docs/src/Utilities/HighlightService.cs
index cb7768780..a0b7e9410 100644
--- a/docs/src/Utilities/HighlightService.cs
+++ b/docs/src/Utilities/HighlightService.cs
@@ -58,21 +58,31 @@ public static async Task
Highlight(Compilation compilation, ISymbol symb
}
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 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);
}