Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Krüger <mikkrg@microsoft.com>2019-07-01 08:56:35 +0300
committerMike Krüger <mikkrg@microsoft.com>2019-07-03 06:29:57 +0300
commitbedbb3e4dc95ae462e384cc1ce95f90eb850fb31 (patch)
tree5aa9d89c47a011195c828f14df7c02b1af3c018a /main/src/addins/MonoDevelop.SourceEditor2
parentd0409558817bc07123ce0979de35f2ef07e2fc65 (diff)
Fixes VSTS Bug 938323: [FATAL] System.ArgumentOutOfRangeException
exception in Microsoft.VisualStudio.Text.SnapshotSpan..ctor() https://devdiv.visualstudio.com/DevDiv/_workitems/edit/938323 Real fix was using the correct snapshot in the constructor: new SnapshotSpan(snapshotLine.Snapshot, snapshotLine.Extent.Span); - using the SnapShot from the text buffer may throw an exception.
Diffstat (limited to 'main/src/addins/MonoDevelop.SourceEditor2')
-rw-r--r--main/src/addins/MonoDevelop.SourceEditor2/VSEditor/TagBasedSyntaxHighlighting.cs76
1 files changed, 42 insertions, 34 deletions
diff --git a/main/src/addins/MonoDevelop.SourceEditor2/VSEditor/TagBasedSyntaxHighlighting.cs b/main/src/addins/MonoDevelop.SourceEditor2/VSEditor/TagBasedSyntaxHighlighting.cs
index bcb9df0d6b..4e8cd30d18 100644
--- a/main/src/addins/MonoDevelop.SourceEditor2/VSEditor/TagBasedSyntaxHighlighting.cs
+++ b/main/src/addins/MonoDevelop.SourceEditor2/VSEditor/TagBasedSyntaxHighlighting.cs
@@ -67,46 +67,54 @@ namespace Microsoft.VisualStudio.Platform
public Task<HighlightedLine> GetHighlightedLineAsync (IDocumentLine line, CancellationToken cancellationToken)
{
- ITextSnapshotLine snapshotLine = (line as Mono.TextEditor.TextDocument.DocumentLineFromTextSnapshotLine)?.Line;
+ var snapshotLine = (line as Mono.TextEditor.TextDocument.DocumentLineFromTextSnapshotLine)?.Line;
if ((this.classifier == null) || (snapshotLine == null)) {
return Task.FromResult (new HighlightedLine (line, new [] { new ColoredSegment (0, line.Length, ScopeStack.Empty) }));
}
- List<ColoredSegment> coloredSegments = new List<ColoredSegment> ();
- SnapshotSpan snapshotSpan = new SnapshotSpan(textView.TextBuffer.CurrentSnapshot, snapshotLine.Extent.Span);
- int start = snapshotSpan.Start.Position;
- int end = snapshotSpan.End.Position;
-
- IList<ClassificationSpan> classifications = this.classifier.GetClassificationSpans (snapshotSpan);
-
- int lastClassifiedOffsetEnd = start;
- ScopeStack scopeStack;
- foreach (ClassificationSpan curSpan in classifications) {
- if (curSpan.Span.Start > lastClassifiedOffsetEnd) {
- scopeStack = defaultScopeStack;
- ColoredSegment whitespaceSegment = new ColoredSegment (lastClassifiedOffsetEnd - start, curSpan.Span.Start - lastClassifiedOffsetEnd, scopeStack);
- coloredSegments.Add (whitespaceSegment);
- }
-
- scopeStack = GetScopeStackFromClassificationType (curSpan.ClassificationType);
- if (scopeStack.Peek ().StartsWith ("comment", StringComparison.Ordinal)) {
- ScanAndAddComment (coloredSegments, start, scopeStack, curSpan);
- } else {
- var curColoredSegment = new ColoredSegment (curSpan.Span.Start - start, curSpan.Span.Length, scopeStack);
- coloredSegments.Add (curColoredSegment);
- }
-
- lastClassifiedOffsetEnd = curSpan.Span.End;
- }
-
- if (end > lastClassifiedOffsetEnd) {
- scopeStack = defaultScopeStack;
- ColoredSegment whitespaceSegment = new ColoredSegment (lastClassifiedOffsetEnd - start, end - lastClassifiedOffsetEnd, scopeStack);
- coloredSegments.Add (whitespaceSegment);
+ try {
+ var coloredSegments = new List<ColoredSegment>();
+
+ var snapshotSpan = new SnapshotSpan(snapshotLine.Snapshot, snapshotLine.Extent.Span);
+ int start = snapshotSpan.Start.Position;
+ int end = snapshotSpan.End.Position;
+
+ var classifications = classifier.GetClassificationSpans(snapshotSpan);
+
+ int lastClassifiedOffsetEnd = start;
+ ScopeStack scopeStack;
+ foreach (var curSpan in classifications)
+ {
+ if (curSpan.Span.Start > lastClassifiedOffsetEnd) {
+ scopeStack = defaultScopeStack;
+ var whitespaceSegment = new ColoredSegment (lastClassifiedOffsetEnd - start, curSpan.Span.Start - lastClassifiedOffsetEnd, scopeStack);
+ coloredSegments.Add (whitespaceSegment);
+ }
+
+ scopeStack = GetScopeStackFromClassificationType (curSpan.ClassificationType);
+ if (scopeStack.Peek ().StartsWith ("comment", StringComparison.Ordinal)) {
+ ScanAndAddComment (coloredSegments, start, scopeStack, curSpan);
+ } else {
+ var curColoredSegment = new ColoredSegment (curSpan.Span.Start - start, curSpan.Span.Length, scopeStack);
+ coloredSegments.Add (curColoredSegment);
+ }
+
+ lastClassifiedOffsetEnd = curSpan.Span.End;
+ }
+
+ if (end > lastClassifiedOffsetEnd) {
+ scopeStack = defaultScopeStack;
+ var whitespaceSegment = new ColoredSegment (lastClassifiedOffsetEnd - start, end - lastClassifiedOffsetEnd, scopeStack);
+ coloredSegments.Add (whitespaceSegment);
+ }
+
+ return Task.FromResult (new HighlightedLine (line, coloredSegments));
+ } catch (Exception e) {
+ LoggingService.LogInternalError ("Error while getting highlighted line " + line, e);
+ return Task.FromResult (new HighlightedLine (line, new [] { new ColoredSegment (0, line.Length, ScopeStack.Empty) }));
}
-
- return Task.FromResult(new HighlightedLine (line, coloredSegments));
}
+
#region Tag Comment Scanning
void ScanAndAddComment (List<ColoredSegment> coloredSegments, int startOffset, ScopeStack commentScopeStack, ClassificationSpan classificationSpan)