提交 a26e6d25 编写于 作者: C CyrusNajmabadi

Add comments.

上级 071c0ae0
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.FindSymbols;
using Microsoft.CodeAnalysis.Remote.FindReferences;
namespace Microsoft.VisualStudio.LanguageServices.Implementation.FindSymbols
{
internal partial class VisualStudioSymbolFinderEngineService : ISymbolFinderEngineService
{
/// <summary>
/// Callback object we pass to the OOP server to hear about the result
/// of the FindReferencesEngine as it executes there.
/// </summary>
private class ServerCallback
{
private readonly Solution _solution;
private readonly IStreamingFindReferencesProgress _progress;
private readonly CancellationToken _cancellationToken;
public ServerCallback(
Solution solution,
IStreamingFindReferencesProgress progress,
CancellationToken cancellationToken)
{
_solution = solution;
_progress = progress;
_cancellationToken = cancellationToken;
}
public Task OnStartedAsync() => _progress.OnStartedAsync();
public Task OnCompletedAsync() => _progress.OnCompletedAsync();
public Task ReportProgressAsync(int current, int maximum) => _progress.ReportProgressAsync(current, maximum);
public Task OnFindInDocumentStartedAsync(SerializableDocumentId documentId)
{
var document = _solution.GetDocument(documentId.Rehydrate());
return _progress.OnFindInDocumentStartedAsync(document);
}
public Task OnFindInDocumentCompletedAsync(SerializableDocumentId documentId)
{
var document = _solution.GetDocument(documentId.Rehydrate());
return _progress.OnFindInDocumentCompletedAsync(document);
}
public async Task OnDefinitionFoundAsync(SerializableSymbolAndProjectId definition)
{
var symbolAndProjectId = await definition.RehydrateAsync(
_solution, _cancellationToken).ConfigureAwait(false);
await _progress.OnDefinitionFoundAsync(symbolAndProjectId).ConfigureAwait(false);
}
public async Task OnReferenceFoundAsync(
SerializableSymbolAndProjectId definition, SerializableReferenceLocation reference)
{
var symbolAndProjectId = await definition.RehydrateAsync(
_solution, _cancellationToken).ConfigureAwait(false);
var referenceLocation = await reference.RehydrateAsync(
_solution, _cancellationToken).ConfigureAwait(false);
await _progress.OnReferenceFoundAsync(symbolAndProjectId, referenceLocation).ConfigureAwait(false);
}
}
}
}
\ No newline at end of file
......@@ -17,7 +17,7 @@
namespace Microsoft.VisualStudio.LanguageServices.Implementation.FindSymbols
{
[ExportWorkspaceService(typeof(ISymbolFinderEngineService), ServiceLayer.Host), Shared]
internal class VisualStudioSymbolFinderEngineService : ISymbolFinderEngineService
internal partial class VisualStudioSymbolFinderEngineService : ISymbolFinderEngineService
{
public async Task FindReferencesAsync(
SymbolAndProjectId symbolAndProjectId, Solution solution,
......@@ -58,6 +58,9 @@ internal class VisualStudioSymbolFinderEngineService : ISymbolFinderEngineServic
return;
}
// Create a callback that we can pass to the server process to hear about the
// results as it finds them. When we hear about results we'll forward them to
// the 'progress' parameter which will then upate the UI.
var serverCallback = new ServerCallback(solution, progress, cancellationToken);
using (var session = await client.CreateCodeAnalysisServiceSessionAsync(
......@@ -69,56 +72,5 @@ internal class VisualStudioSymbolFinderEngineService : ISymbolFinderEngineServic
documents?.Select(SerializableDocumentId.Dehydrate).ToArray()).ConfigureAwait(false);
}
}
private class ServerCallback
{
private readonly Solution _solution;
private readonly IStreamingFindReferencesProgress _progress;
private readonly CancellationToken _cancellationToken;
public ServerCallback(
Solution solution,
IStreamingFindReferencesProgress progress,
CancellationToken cancellationToken)
{
_solution = solution;
_progress = progress;
_cancellationToken = cancellationToken;
}
public Task OnStartedAsync() => _progress.OnStartedAsync();
public Task OnCompletedAsync() => _progress.OnCompletedAsync();
public Task ReportProgressAsync(int current, int maximum) => _progress.ReportProgressAsync(current, maximum);
public Task OnFindInDocumentStartedAsync(SerializableDocumentId documentId)
{
var document = _solution.GetDocument(documentId.Rehydrate());
return _progress.OnFindInDocumentStartedAsync(document);
}
public Task OnFindInDocumentCompletedAsync(SerializableDocumentId documentId)
{
var document = _solution.GetDocument(documentId.Rehydrate());
return _progress.OnFindInDocumentCompletedAsync(document);
}
public async Task OnDefinitionFoundAsync(SerializableSymbolAndProjectId definition)
{
var symbolAndProjectId = await definition.RehydrateAsync(
_solution, _cancellationToken).ConfigureAwait(false);
await _progress.OnDefinitionFoundAsync(symbolAndProjectId).ConfigureAwait(false);
}
public async Task OnReferenceFoundAsync(
SerializableSymbolAndProjectId definition, SerializableReferenceLocation reference)
{
var symbolAndProjectId = await definition.RehydrateAsync(
_solution, _cancellationToken).ConfigureAwait(false);
var referenceLocation = await reference.RehydrateAsync(
_solution, _cancellationToken).ConfigureAwait(false);
await _progress.OnReferenceFoundAsync(symbolAndProjectId, referenceLocation).ConfigureAwait(false);
}
}
}
}
\ No newline at end of file
......@@ -124,6 +124,7 @@
<DesignTime>True</DesignTime>
<DependentUpon>ServicesVisualStudioNextResources.resx</DependentUpon>
</Compile>
<Compile Include="FindSymbols\VisualStudioSymbolFinderEngineService.ServerCallback.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="ServicesVisualStudioNextResources.resx">
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册