提交 3db406c5 编写于 作者: C CyrusNajmabadi 提交者: GitHub

Merge pull request #18681 from CyrusNajmabadi/oopNFW

Report an NFW instead of asserting when we encounter a symbol we can't roundtrip to OOP.
......@@ -118,8 +118,11 @@ internal static partial class DeclarationFinder
foreach (var dehydrated in array)
{
cancellationToken.ThrowIfCancellationRequested();
var rehydrated = await dehydrated.RehydrateAsync(solution, cancellationToken).ConfigureAwait(false);
result.Add(rehydrated);
var rehydrated = await dehydrated.TryRehydrateAsync(solution, cancellationToken).ConfigureAwait(false);
if (rehydrated != null)
{
result.Add(rehydrated.Value);
}
}
return result.ToImmutableAndFree();
......
......@@ -52,15 +52,20 @@ public Task OnFindInDocumentCompletedAsync(DocumentId documentId)
public async Task OnDefinitionFoundAsync(SerializableSymbolAndProjectId definition)
{
var symbolAndProjectId = await definition.RehydrateAsync(
var symbolAndProjectId = await definition.TryRehydrateAsync(
_solution, _cancellationToken).ConfigureAwait(false);
if (!symbolAndProjectId.HasValue)
{
return;
}
lock (_gate)
{
_definitionMap[definition] = symbolAndProjectId;
_definitionMap[definition] = symbolAndProjectId.Value;
}
await _progress.OnDefinitionFoundAsync(symbolAndProjectId).ConfigureAwait(false);
await _progress.OnDefinitionFoundAsync(symbolAndProjectId.Value).ConfigureAwait(false);
}
public async Task OnReferenceFoundAsync(
......
......@@ -5,6 +5,7 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.ErrorReporting;
using Microsoft.CodeAnalysis.FindSymbols;
using Microsoft.CodeAnalysis.SymbolSearch;
using Microsoft.CodeAnalysis.Text;
......@@ -46,7 +47,7 @@ public bool Equals(SerializableSymbolAndProjectId other)
};
}
public async Task<SymbolAndProjectId> RehydrateAsync(
public async Task<SymbolAndProjectId?> TryRehydrateAsync(
Solution solution, CancellationToken cancellationToken)
{
var projectId = ProjectId;
......@@ -57,7 +58,20 @@ public bool Equals(SerializableSymbolAndProjectId other)
// locations in symbols are save to resolve as we rehydrate the SymbolKey.
var symbol = SymbolKey.Resolve(
SymbolKeyData, compilation, resolveLocations: true, cancellationToken: cancellationToken).GetAnySymbol();
Debug.Assert(symbol != null, "We should always be able to resolve a symbol back on the host side.");
if (symbol == null)
{
try
{
throw new InvalidOperationException(
$"We should always be able to resolve a symbol back on the host side:\r\n{SymbolKeyData}");
}
catch (Exception ex) when (FatalError.ReportWithoutCrash(ex))
{
return null;
}
}
return new SymbolAndProjectId(symbol, projectId);
}
}
......@@ -113,8 +127,8 @@ internal class SerializableReferenceLocation
return null;
}
var symbolAndProjectId = await Alias.RehydrateAsync(solution, cancellationToken).ConfigureAwait(false);
return symbolAndProjectId.Symbol as IAliasSymbol;
var symbolAndProjectId = await Alias.TryRehydrateAsync(solution, cancellationToken).ConfigureAwait(false);
return symbolAndProjectId.GetValueOrDefault().Symbol as IAliasSymbol;
}
}
......
......@@ -15,14 +15,24 @@ public async Task FindReferencesAsync(SerializableSymbolAndProjectId symbolAndPr
{
var solution = await GetSolutionAsync().ConfigureAwait(false);
var symbolAndProjectId = await symbolAndProjectIdArg.RehydrateAsync(
var symbolAndProjectId = await symbolAndProjectIdArg.TryRehydrateAsync(
solution, CancellationToken).ConfigureAwait(false);
var progressCallback = new FindReferencesProgressCallback(this);
if (!symbolAndProjectId.HasValue)
{
await progressCallback.OnStartedAsync().ConfigureAwait(false);
await progressCallback.OnCompletedAsync().ConfigureAwait(false);
return;
}
var documents = documentArgs?.Select(solution.GetDocument)
.ToImmutableHashSet();
var progressCallback = new FindReferencesProgressCallback(this);
await SymbolFinder.FindReferencesInCurrentProcessAsync(
symbolAndProjectId, solution, progressCallback, documents, CancellationToken).ConfigureAwait(false);
symbolAndProjectId.Value, solution,
progressCallback, documents, CancellationToken).ConfigureAwait(false);
}
public async Task FindLiteralReferencesAsync(object value)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册