From 50c93389c1d41d72425a765e9414b3491400fdc3 Mon Sep 17 00:00:00 2001 From: Ankita Khera Date: Fri, 1 Oct 2021 12:54:09 -0700 Subject: [PATCH] added fatal error reporting --- .../Core.Wpf/InlineHints/InlineHintsTagger.cs | 85 ++++++++++--------- 1 file changed, 47 insertions(+), 38 deletions(-) diff --git a/src/EditorFeatures/Core.Wpf/InlineHints/InlineHintsTagger.cs b/src/EditorFeatures/Core.Wpf/InlineHints/InlineHintsTagger.cs index e83bef7bdda36..572183444d060 100644 --- a/src/EditorFeatures/Core.Wpf/InlineHints/InlineHintsTagger.cs +++ b/src/EditorFeatures/Core.Wpf/InlineHints/InlineHintsTagger.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Composition; using Microsoft.CodeAnalysis.Editor.Shared.Utilities; +using Microsoft.CodeAnalysis.ErrorReporting; using Microsoft.CodeAnalysis.InlineHints; using Microsoft.CodeAnalysis.Text; using Microsoft.VisualStudio.Text; @@ -13,6 +14,7 @@ using Microsoft.VisualStudio.Text.Editor; using Microsoft.VisualStudio.Text.Formatting; using Microsoft.VisualStudio.Text.Tagging; +using Roslyn.Utilities; using static System.Windows.Forms.VisualStyles.VisualStyleElement; namespace Microsoft.CodeAnalysis.Editor.InlineHints @@ -111,57 +113,64 @@ private TextFormattingRunProperties Format public IEnumerable> GetTags(NormalizedSnapshotSpanCollection spans) { - if (spans.Count == 0) + try { - return Array.Empty>(); - } - - var snapshot = spans[0].Snapshot; - if (_cache.Count == 0 || snapshot != _cacheSnapshot) - { - // Calculate UI elements - _cache.Clear(); - _cacheSnapshot = snapshot; + if (spans.Count == 0) + { + return Array.Empty>(); + } - // Calling into the InlineParameterNameHintsDataTaggerProvider which only responds with the current - // active view and disregards and requests for tags not in that view - var fullSpan = new SnapshotSpan(snapshot, 0, snapshot.Length); - var tags = _tagAggregator.GetTags(new NormalizedSnapshotSpanCollection(fullSpan)); - foreach (var tag in tags) + var snapshot = spans[0].Snapshot; + if (_cache.Count == 0 || snapshot != _cacheSnapshot) { - // Gets the associated span from the snapshot span and creates the IntraTextAdornmentTag from the data - // tags. Only dealing with the dataTagSpans if the count is 1 because we do not see a multi-buffer case - // occuring - var dataTagSpans = tag.Span.GetSpans(snapshot); - if (dataTagSpans.Count == 1) + // Calculate UI elements + _cache.Clear(); + _cacheSnapshot = snapshot; + + // Calling into the InlineParameterNameHintsDataTaggerProvider which only responds with the current + // active view and disregards and requests for tags not in that view + var fullSpan = new SnapshotSpan(snapshot, 0, snapshot.Length); + var tags = _tagAggregator.GetTags(new NormalizedSnapshotSpanCollection(fullSpan)); + foreach (var tag in tags) { - _cache.Add((tag, tagSpan: null)); + // Gets the associated span from the snapshot span and creates the IntraTextAdornmentTag from the data + // tags. Only dealing with the dataTagSpans if the count is 1 because we do not see a multi-buffer case + // occuring + var dataTagSpans = tag.Span.GetSpans(snapshot); + if (dataTagSpans.Count == 1) + { + _cache.Add((tag, tagSpan: null)); + } } } - } - var document = snapshot.GetOpenDocumentInCurrentContextWithChanges(); - var classify = document?.Project.Solution.Options.GetOption(InlineHintsOptions.ColorHints, document?.Project.Language) ?? false; + var document = snapshot.GetOpenDocumentInCurrentContextWithChanges(); + var classify = document?.Project.Solution.Options.GetOption(InlineHintsOptions.ColorHints, document?.Project.Language) ?? false; - var selectedSpans = new List>(); - for (var i = 0; i < _cache.Count; i++) - { - var tagSpan = _cache[i].mappingTagSpan.Span.GetSpans(snapshot)[0]; - if (spans.IntersectsWith(tagSpan)) + var selectedSpans = new List>(); + for (var i = 0; i < _cache.Count; i++) { - if (_cache[i].tagSpan is not { } hintTagSpan) + var tagSpan = _cache[i].mappingTagSpan.Span.GetSpans(snapshot)[0]; + if (spans.IntersectsWith(tagSpan)) { - var parameterHintUITag = InlineHintsTag.Create( - _cache[i].mappingTagSpan.Tag.Hint, Format, _textView, tagSpan, _taggerProvider, _formatMap, classify); - hintTagSpan = new TagSpan(tagSpan, parameterHintUITag); - _cache[i] = (_cache[i].mappingTagSpan, hintTagSpan); + if (_cache[i].tagSpan is not { } hintTagSpan) + { + var parameterHintUITag = InlineHintsTag.Create( + _cache[i].mappingTagSpan.Tag.Hint, Format, _textView, tagSpan, _taggerProvider, _formatMap, classify); + hintTagSpan = new TagSpan(tagSpan, parameterHintUITag); + _cache[i] = (_cache[i].mappingTagSpan, hintTagSpan); + } + + selectedSpans.Add(hintTagSpan); } - - selectedSpans.Add(hintTagSpan); } - } - return selectedSpans; + return selectedSpans; + } + catch (Exception e) when (FatalError.ReportAndPropagateUnlessCanceled(e)) + { + throw ExceptionUtilities.Unreachable; + } } public void Dispose()