fix symbol highlighting with additive classifiedSpan
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
using Microsoft.CodeAnalysis;
|
||||
@@ -20,23 +22,28 @@ public partial class CustomHighlighter : SyntaxHighlighter
|
||||
private Dictionary MapClassifiedSpansToHighlights(int line)
|
||||
{
|
||||
var highlights = new Dictionary();
|
||||
|
||||
// consider no linq or ZLinq
|
||||
var spansGroupedByFileSpan = ClassifiedSpans
|
||||
.Where(s => s.fileSpan.StartLinePosition.Line == line && s.classifiedSpan.TextSpan.Length is not 0)
|
||||
.GroupBy(span => span.fileSpan)
|
||||
.Select(group => (fileSpan: group.Key, classifiedSpans: group.Select(s => s.classifiedSpan).ToList()));
|
||||
|
||||
foreach (var (fileSpan, classifiedSpan) in ClassifiedSpans)
|
||||
foreach (var (fileSpan, classifiedSpans) in spansGroupedByFileSpan)
|
||||
{
|
||||
// Only take spans on the requested line
|
||||
if (fileSpan.StartLinePosition.Line != line)
|
||||
continue;
|
||||
|
||||
if (classifiedSpan.TextSpan.Length == 0)
|
||||
continue; // Skip empty spans
|
||||
|
||||
if (classifiedSpans.Count > 2) throw new NotImplementedException("More than 2 classified spans is not supported yet.");
|
||||
if (classifiedSpans.Count is not 1)
|
||||
{
|
||||
ClassifiedSpan? staticClassifiedSpan = classifiedSpans.FirstOrDefault(s => s.ClassificationType == ClassificationTypeNames.StaticSymbol);
|
||||
if (staticClassifiedSpan is not null) classifiedSpans.Remove(staticClassifiedSpan.Value);
|
||||
}
|
||||
// Column index of the first character in this span
|
||||
int columnIndex = fileSpan.StartLinePosition.Character;
|
||||
|
||||
// Build the highlight entry
|
||||
var highlightInfo = new Dictionary
|
||||
{
|
||||
{ ColorStringName, GetColorForClassification(classifiedSpan.ClassificationType) }
|
||||
{ ColorStringName, GetColorForClassification(classifiedSpans.Single().ClassificationType) }
|
||||
};
|
||||
|
||||
highlights[columnIndex] = highlightInfo;
|
||||
|
||||
Reference in New Issue
Block a user