提交 6332863d 编写于 作者: C Cyrus Najmabadi

Make code more resilient to potential bad situations.

上级 68811116
......@@ -124,7 +124,7 @@ private bool ShouldConsiderSymbol(ISymbol symbol)
return additionalReferenceProvider.GetAdditionalReferencesAsync(document, symbol, cancellationToken);
}
return Task.FromResult<IEnumerable<Location>>(SpecializedCollections.EmptyEnumerable<Location>());
return Task.FromResult(SpecializedCollections.EmptyEnumerable<Location>());
}
private async Task<IEnumerable<DocumentHighlights>> CreateSpansAsync(
......@@ -247,18 +247,26 @@ private async Task AddLocationSpan(Location location, Solution solution, HashSet
private async Task<ValueTuple<Document, TextSpan>?> GetLocationSpanAsync(Solution solution, Location location, CancellationToken cancellationToken)
{
var tree = location.SourceTree;
if (location != null && location.IsInSource)
{
var tree = location.SourceTree;
var document = solution.GetDocument(tree);
var syntaxFacts = document?.Project?.LanguageServices?.GetService<ISyntaxFactsService>();
var document = solution.GetDocument(tree);
var syntaxFacts = document.Project.LanguageServices.GetService<ISyntaxFactsService>();
if (syntaxFacts != null)
{
// Specify findInsideTrivia: true to ensure that we search within XML doc comments.
var root = await tree.GetRootAsync(cancellationToken).ConfigureAwait(false);
var token = root.FindToken(location.SourceSpan.Start, findInsideTrivia: true);
// Specify findInsideTrivia: true to ensure that we search within XML doc comments.
var root = await tree.GetRootAsync(cancellationToken).ConfigureAwait(false);
var token = root.FindToken(location.SourceSpan.Start, findInsideTrivia: true);
return syntaxFacts.IsGenericName(token.Parent) || syntaxFacts.IsIndexerMemberCRef(token.Parent)
? ValueTuple.Create(document, token.Span)
: ValueTuple.Create(document, location.SourceSpan);
}
}
return syntaxFacts.IsGenericName(token.Parent) || syntaxFacts.IsIndexerMemberCRef(token.Parent)
? ValueTuple.Create(document, token.Span)
: ValueTuple.Create(document, location.SourceSpan);
return null;
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册