提交 f2c777e3 编写于 作者: C CyrusNajmabadi

Provide implementation that will call into the remote client.

上级 a32e1377
......@@ -685,7 +685,9 @@
<PublicAPI Include="PublicAPI.Shipped.txt" />
<PublicAPI Include="PublicAPI.Unshipped.txt" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Folder Include="NavigateTo\" />
</ItemGroup>
<Import Project="..\..\..\Compilers\Core\AnalyzerDriver\AnalyzerDriver.projitems" Label="Shared" />
<Import Project="..\..\..\..\build\Targets\VSL.Imports.targets" />
</Project>
\ No newline at end of file
......@@ -8,7 +8,7 @@
namespace Microsoft.CodeAnalysis.NavigateTo
{
internal sealed partial class DefaultNavigateToEngineService
internal partial class DefaultNavigateToEngineService
{
private class SearchResult : INavigateToSearchResult
{
......
......@@ -16,7 +16,7 @@
namespace Microsoft.CodeAnalysis.NavigateTo
{
[ExportWorkspaceService(typeof(INavigateToEngineService), layer: ServiceLayer.Default), Shared]
internal partial class DefaultNavigateToEngineService : INavigateToEngineService
internal sealed partial class DefaultNavigateToEngineService : INavigateToEngineService
{
public Task<ImmutableArray<INavigateToSearchResult>> SearchProjectAsync(
Project project, string searchPattern, CancellationToken cancellationToken)
......
// 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;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Composition;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Editor.Implementation.NavigateTo;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.NavigateTo;
using Microsoft.CodeAnalysis.Remote;
using Microsoft.CodeAnalysis.Remote.Arguments;
using Microsoft.VisualStudio.LanguageServices.Implementation.Extensions;
using Microsoft.VisualStudio.LanguageServices.Remote;
namespace Microsoft.VisualStudio.LanguageServices.NavigateTo
{
[ExportWorkspaceService(typeof(INavigateToEngineService)), Shared]
internal class VisualStudioNavigateToEngineService : INavigateToEngineService
{
public async Task<ImmutableArray<INavigateToSearchResult>> SearchDocumentAsync(
Document document, string searchPattern, CancellationToken cancellationToken)
{
var client = await GetRemoteHostClientAsync(document.Project, cancellationToken).ConfigureAwait(false);
if (client == null)
{
return await DefaultNavigateToEngineService.SearchDocumentInCurrentProcessAsync(
document, searchPattern, cancellationToken).ConfigureAwait(false);
}
else
{
return await SearchDocumentInRemoteProcessAsync(
client, document, searchPattern, cancellationToken).ConfigureAwait(false);
}
}
private async Task<ImmutableArray<INavigateToSearchResult>> SearchDocumentInRemoteProcessAsync(
RemoteHostClient client, Document document, string searchPattern, CancellationToken cancellationToken)
{
var solution = document.Project.Solution;
using (var session = await client.CreateCodeAnalysisServiceSessionAsync(
solution, cancellationToken).ConfigureAwait(false))
{
var serializableResults = await session.InvokeAsync<SerializableNavigateToSearchResult[]>(
WellKnownServiceHubServices.CodeAnalysisService_SearchDocumentAsync,
SerializableDocumentId.Dehydrate(document),
searchPattern).ConfigureAwait(false);
return serializableResults.Select(r => r.Rehydrate(solution)).ToImmutableArray();
}
}
public async Task<ImmutableArray<INavigateToSearchResult>> SearchProjectAsync(
Project project, string searchPattern, CancellationToken cancellationToken)
{
var client = await GetRemoteHostClientAsync(project, cancellationToken).ConfigureAwait(false);
if (client == null)
{
return await DefaultNavigateToEngineService.SearchProjectInCurrentProcessAsync(
project, searchPattern, cancellationToken).ConfigureAwait(false);
}
else
{
return await SearchProjectInRemoteProcessAsync(
client, project, searchPattern, cancellationToken).ConfigureAwait(false);
}
}
private async Task<ImmutableArray<INavigateToSearchResult>> SearchProjectInRemoteProcessAsync(
RemoteHostClient client, Project project, string searchPattern, CancellationToken cancellationToken)
{
var solution = project.Solution;
using (var session = await client.CreateCodeAnalysisServiceSessionAsync(
solution, cancellationToken).ConfigureAwait(false))
{
var serializableResults = await session.InvokeAsync<SerializableNavigateToSearchResult[]>(
WellKnownServiceHubServices.CodeAnalysisService_SearchProjectAsync,
SerializableProjectId.Dehydrate(project.Id),
searchPattern).ConfigureAwait(false);
return serializableResults.Select(r => r.Rehydrate(solution)).ToImmutableArray();
}
}
private static Task<RemoteHostClient> GetRemoteHostClientAsync(
Project project, CancellationToken cancellationToken)
{
var clientService = project.Solution.Workspace.Services.GetService<IRemoteHostClientService>();
return clientService.GetRemoteHostClientAsync(cancellationToken);
}
}
}
......@@ -89,6 +89,9 @@
<Compile Include="..\..\..\Workspaces\Remote\ServiceHub\Shared\Extensions.cs">
<Link>Shared\Extensions.cs</Link>
</Compile>
<Compile Include="..\..\..\Workspaces\Remote\ServiceHub\Shared\RemoteArguments.cs">
<Link>Shared\RemoteArguments.cs</Link>
</Compile>
<Compile Include="..\..\..\Workspaces\Remote\ServiceHub\Shared\ServerDirectStream.cs">
<Link>Shared\ServerDirectStream.cs</Link>
</Compile>
......@@ -110,6 +113,7 @@
<Compile Include="FindReferences\StreamingFindReferencesPresenter.TableDataSourceFindReferencesContext.cs" />
<Compile Include="FindReferences\StreamingFindReferencesPresenter.TableEntriesSnapshot.cs" />
<Compile Include="FindReferences\TaggedTextAndHighlightSpan.cs" />
<Compile Include="NavigateTo\VisualStudioNavigateToEngineService.cs" />
<Compile Include="Remote\JsonRpcClient.cs" />
<Compile Include="Remote\JsonRpcSession.cs" />
<Compile Include="Remote\RemoteHostClientFactory.cs" />
......@@ -133,5 +137,6 @@
<InternalsVisibleToTest Include="Roslyn.VisualStudio.Test.Utilities.Next" />
<InternalsVisibleToTest Include="Roslyn.VisualStudio.Next.UnitTests" />
</ItemGroup>
<ItemGroup />
<Import Project="..\..\..\..\build\Targets\VSL.Imports.targets" />
</Project>
\ No newline at end of file
......@@ -19,6 +19,10 @@
<Project>{1EE8CAD3-55F9-4D91-96B2-084641DA9A6C}</Project>
<Name>CodeAnalysis</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\EditorFeatures\Core\EditorFeatures.csproj">
<Project>{3cdeeab7-2256-418a-beb2-620b5cb16302}</Project>
<Name>EditorFeatures</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\Features\Core\Portable\Features.csproj">
<Project>{edc68a0e-c68d-4a74-91b7-bf38ec909888}</Project>
<Name>Features</Name>
......@@ -50,6 +54,7 @@
<ItemGroup>
<None Include="project.json" />
<Compile Include="CodeLens\CodeLensArguments.cs" />
<Compile Include="Shared\RemoteArguments.cs" />
<Compile Include="Services\CodeAnalysisService_CodeLens.cs" />
<Compile Include="Services\SnapshotService.JsonRpcAssetSource.cs" />
<PublicAPI Include="PublicAPI.Shipped.txt" />
......@@ -74,6 +79,7 @@
<InternalsVisibleToTest Include="Roslyn.VisualStudio.Next.UnitTests" />
</ItemGroup>
<ItemGroup>
<Folder Include="NavigateTo\" />
<Folder Include="Storage\" />
</ItemGroup>
<Import Project="..\..\..\..\build\Targets\VSL.Imports.targets" />
......
// 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;
using System.Collections.Immutable;
using System.Linq;
using Microsoft.CodeAnalysis.Editor.Implementation.NavigateTo;
using Microsoft.CodeAnalysis.NavigateTo;
using Microsoft.CodeAnalysis.Navigation;
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.CodeAnalysis.Remote.Arguments
{
#region Common Arguments
/// <summary>
/// Arguments to pass from client to server when performing operations
/// </summary>
internal class SerializableProjectId
{
public Guid Id;
public string DebugName;
public static SerializableProjectId Dehydrate(ProjectId id)
{
return new SerializableProjectId { Id = id.Id, DebugName = id.DebugName };
}
public ProjectId Rehydrate()
{
return ProjectId.CreateFromSerialized(Id, DebugName);
}
}
internal class SerializableDocumentId
{
public SerializableProjectId ProjectId;
public Guid Id;
public string DebugName;
public static SerializableDocumentId Dehydrate(Document document)
{
return Dehydrate(document.Id);
}
public static SerializableDocumentId Dehydrate(DocumentId id)
{
return new SerializableDocumentId
{
ProjectId = SerializableProjectId.Dehydrate(id.ProjectId),
Id = id.Id,
DebugName = id.DebugName
};
}
public DocumentId Rehydrate()
{
return DocumentId.CreateFromSerialized(
ProjectId.Rehydrate(), Id, DebugName);
}
}
internal class SerializableTextSpan
{
public int Start;
public int Length;
public static SerializableTextSpan Dehydrate(TextSpan textSpan)
{
return new SerializableTextSpan { Start = textSpan.Start, Length = textSpan.Length };
}
public TextSpan Rehydrate()
{
return new TextSpan(Start, Length);
}
}
internal class SerializableTaggedText
{
public string Tag;
public string Text;
public static SerializableTaggedText Dehydrate(TaggedText taggedText)
{
return new SerializableTaggedText { Tag = taggedText.Tag, Text = taggedText.Text };
}
public TaggedText Rehydrate()
{
return new TaggedText(Tag, Text);
}
}
#endregion
#region NavigateTo
internal class SerializableNavigateToSearchResult
{
public string AdditionalInformation;
public string Kind;
public NavigateToMatchKind MatchKind;
public bool IsCaseSensitive;
public string Name;
public string SecondarySort;
public string Summary;
public SerializableNavigableItem NavigableItem;
internal INavigateToSearchResult Rehydrate(Solution solution)
{
return new NavigateToSearchResult(
AdditionalInformation, Kind, MatchKind, IsCaseSensitive,
Name, SecondarySort, Summary, NavigableItem.Rehydrate(solution));
}
private class NavigateToSearchResult : INavigateToSearchResult
{
public string AdditionalInformation { get; }
public string Kind { get; }
public NavigateToMatchKind MatchKind { get; }
public bool IsCaseSensitive { get; }
public string Name { get; }
public string SecondarySort { get; }
public string Summary { get; }
public INavigableItem NavigableItem { get; }
public NavigateToSearchResult(string additionalInformation, string kind, NavigateToMatchKind matchKind, bool isCaseSensitive, string name, string secondarySort, string summary, INavigableItem navigableItem)
{
AdditionalInformation = additionalInformation;
Kind = kind;
MatchKind = matchKind;
IsCaseSensitive = isCaseSensitive;
Name = name;
SecondarySort = secondarySort;
Summary = summary;
NavigableItem = navigableItem;
}
}
}
internal class SerializableNavigableItem
{
public Glyph Glyph;
public SerializableTaggedText[] DisplayTaggedParts;
public bool DisplayFileLocation;
public bool IsImplicitlyDeclared;
public SerializableDocumentId Document;
public SerializableTextSpan SourceSpan;
SerializableNavigableItem[] ChildItems;
public INavigableItem Rehydrate(Solution solution)
{
var childItems = ChildItems == null
? ImmutableArray<INavigableItem>.Empty
: ChildItems.Select(c => c.Rehydrate(solution)).ToImmutableArray();
return new NavigableItem(
Glyph, DisplayTaggedParts.Select(p => p.Rehydrate()).ToImmutableArray(),
DisplayFileLocation, IsImplicitlyDeclared,
solution.GetDocument(Document.Rehydrate()),
SourceSpan.Rehydrate(),
childItems);
}
private class NavigableItem : INavigableItem
{
public Glyph Glyph { get; }
public ImmutableArray<TaggedText> DisplayTaggedParts { get; }
public bool DisplayFileLocation { get; }
public bool IsImplicitlyDeclared { get; }
public Document Document { get; }
public TextSpan SourceSpan { get; }
public ImmutableArray<INavigableItem> ChildItems { get; }
public NavigableItem(
Glyph glyph, ImmutableArray<TaggedText> displayTaggedParts,
bool displayFileLocation, bool isImplicitlyDeclared, Document document, TextSpan sourceSpan, ImmutableArray<INavigableItem> childItems)
{
Glyph = glyph;
DisplayTaggedParts = displayTaggedParts;
DisplayFileLocation = displayFileLocation;
IsImplicitlyDeclared = isImplicitlyDeclared;
Document = document;
SourceSpan = sourceSpan;
ChildItems = childItems;
}
}
}
#endregion
}
\ No newline at end of file
......@@ -14,6 +14,10 @@ internal static class WellKnownServiceHubServices
public const string CodeAnalysisService_FindReferenceMethodsAsync = "FindReferenceMethodsAsync";
public const string CodeAnalysisService_GetFullyQualifiedName = "GetFullyQualifiedName";
// NavigateTo
public const string CodeAnalysisService_SearchDocumentAsync = "SearchDocumentAsync";
public const string CodeAnalysisService_SearchProjectAsync = "SearchProjectAsync";
public const string AssetService_RequestAssetAsync = "RequestAssetAsync";
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册