Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error reporting to Inline Hints #56917

Merged
merged 1 commit into from
Oct 1, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 47 additions & 38 deletions src/EditorFeatures/Core.Wpf/InlineHints/InlineHintsTagger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
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;
using Microsoft.VisualStudio.Text.Classification;
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
Expand Down Expand Up @@ -111,57 +113,64 @@ private TextFormattingRunProperties Format

public IEnumerable<ITagSpan<IntraTextAdornmentTag>> GetTags(NormalizedSnapshotSpanCollection spans)
{
if (spans.Count == 0)
try
{
return Array.Empty<ITagSpan<IntraTextAdornmentTag>>();
}

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<ITagSpan<IntraTextAdornmentTag>>();
}

// 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<ITagSpan<IntraTextAdornmentTag>>();
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<ITagSpan<IntraTextAdornmentTag>>();
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<IntraTextAdornmentTag>(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<IntraTextAdornmentTag>(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()
Expand Down