提交 5ea743de 编写于 作者: J Jonathon Marolf

Capture documents in dump in event of FindToken crash with linked files.

We are seeing reports of Visual Studio crashing in FindToken with argument out
of range exceptions.  It appears that this is causes by linked files being of
differing lengths.  This change captures the original and linked documents
on the stack so we can better understand what is happening.
上级 4fa6e3fe
......@@ -8,6 +8,7 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.DocumentationComments;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.ErrorReporting;
using Microsoft.CodeAnalysis.LanguageServices;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Shared.Utilities;
......@@ -75,7 +76,7 @@ internal abstract partial class AbstractSemanticQuickInfoProvider : AbstractQuic
foreach (var link in linkedDocumentIds)
{
var linkedDocument = document.Project.Solution.GetDocument(link);
var linkedToken = await FindTokenInLinkedDocument(token, linkedDocument, cancellationToken).ConfigureAwait(false);
var linkedToken = await FindTokenInLinkedDocument(token, document, linkedDocument, cancellationToken).ConfigureAwait(false);
if (linkedToken != default(SyntaxToken))
{
......@@ -116,7 +117,7 @@ internal abstract partial class AbstractSemanticQuickInfoProvider : AbstractQuic
return await CreateContentAsync(document.Project.Solution.Workspace, token, bestBinding.Item2, bestBinding.Item3, supportedPlatforms, cancellationToken).ConfigureAwait(false);
}
private async Task<SyntaxToken> FindTokenInLinkedDocument(SyntaxToken token, Document linkedDocument, CancellationToken cancellationToken)
private async Task<SyntaxToken> FindTokenInLinkedDocument(SyntaxToken token, Document originalDocument, Document linkedDocument, CancellationToken cancellationToken)
{
if (!linkedDocument.SupportsSyntaxTree)
{
......@@ -125,13 +126,24 @@ private async Task<SyntaxToken> FindTokenInLinkedDocument(SyntaxToken token, Doc
var root = await linkedDocument.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
// Don't search trivia because we want to ignore inactive regions
var linkedToken = root.FindToken(token.SpanStart);
try
{
// Don't search trivia because we want to ignore inactive regions
var linkedToken = root.FindToken(token.SpanStart);
// The new and old tokens should have the same span?
if (token.Span == linkedToken.Span)
// The new and old tokens should have the same span?
if (token.Span == linkedToken.Span)
{
return linkedToken;
}
}
catch (Exception e)
{
return linkedToken;
// We are seeing linked files with different spans cause FindToken to crash.
// Capturing more information for https://devdiv.visualstudio.com/DevDiv/_workitems?id=209299
var originalText = await originalDocument.GetTextAsync().ConfigureAwait(false);
var linkedText = await linkedDocument.GetTextAsync().ConfigureAwait(false);
FatalError.Report(e);
}
return default(SyntaxToken);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册