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;
|
||||||
using Godot.Collections;
|
using Godot.Collections;
|
||||||
using Microsoft.CodeAnalysis;
|
using Microsoft.CodeAnalysis;
|
||||||
@@ -20,23 +22,28 @@ public partial class CustomHighlighter : SyntaxHighlighter
|
|||||||
private Dictionary MapClassifiedSpansToHighlights(int line)
|
private Dictionary MapClassifiedSpansToHighlights(int line)
|
||||||
{
|
{
|
||||||
var highlights = new Dictionary();
|
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 (classifiedSpans.Count > 2) throw new NotImplementedException("More than 2 classified spans is not supported yet.");
|
||||||
if (fileSpan.StartLinePosition.Line != line)
|
if (classifiedSpans.Count is not 1)
|
||||||
continue;
|
{
|
||||||
|
ClassifiedSpan? staticClassifiedSpan = classifiedSpans.FirstOrDefault(s => s.ClassificationType == ClassificationTypeNames.StaticSymbol);
|
||||||
if (classifiedSpan.TextSpan.Length == 0)
|
if (staticClassifiedSpan is not null) classifiedSpans.Remove(staticClassifiedSpan.Value);
|
||||||
continue; // Skip empty spans
|
}
|
||||||
|
|
||||||
// Column index of the first character in this span
|
// Column index of the first character in this span
|
||||||
int columnIndex = fileSpan.StartLinePosition.Character;
|
int columnIndex = fileSpan.StartLinePosition.Character;
|
||||||
|
|
||||||
// Build the highlight entry
|
// Build the highlight entry
|
||||||
var highlightInfo = new Dictionary
|
var highlightInfo = new Dictionary
|
||||||
{
|
{
|
||||||
{ ColorStringName, GetColorForClassification(classifiedSpan.ClassificationType) }
|
{ ColorStringName, GetColorForClassification(classifiedSpans.Single().ClassificationType) }
|
||||||
};
|
};
|
||||||
|
|
||||||
highlights[columnIndex] = highlightInfo;
|
highlights[columnIndex] = highlightInfo;
|
||||||
|
|||||||
Reference in New Issue
Block a user