private async void UpdateHighlightLineAsync()

in Samples-NetCore/DotNetPad/DotNetPad.Presentation/Controls/CodeHighlighter.cs [71:111]


        private async void UpdateHighlightLineAsync(VersionedHighlightedLine line)
        {
            try
            {
                await Task.Run(async () =>
                {
                    await initialDelayTask.ConfigureAwait(false);
                    if (CancelUpdate(Document, line)) return;

                    var documentLine = line.DocumentLine;
                    var spans = await GetClassifiedSpansAsync(documentLine, line.CancellationToken).ConfigureAwait(false);

                    await TaskHelper.Run(() =>
                    {
                        if (CancelUpdate(Document, line)) return;

                        var newLineSections = new List<HighlightedSection>();
                        foreach (var classifiedSpan in spans)
                        {
                            if (IsOutsideLine(documentLine, classifiedSpan.TextSpan.Start, classifiedSpan.TextSpan.Length))
                            {
                                continue;
                            }
                            newLineSections.Add(new HighlightedSection
                            {
                                Color = CodeHighlightColors.GetHighlightingColor(classifiedSpan.ClassificationType),
                                Offset = classifiedSpan.TextSpan.Start,
                                Length = classifiedSpan.TextSpan.Length
                            });
                        }
                        if (!line.Sections.SequenceEqual(newLineSections, HighlightedSectionComparer.Default))
                        {
                            line.Sections.Clear();
                            foreach (var newSection in newLineSections) { line.Sections.Add(newSection); }
                            HighlightingStateChanged?.Invoke(documentLine.LineNumber, documentLine.LineNumber);
                        }
                    }, uiTaskScheduler).ConfigureAwait(false);
                }, line.CancellationToken);
            }
            catch (OperationCanceledException) { }
        }