提交 2654497f 编写于 作者: C CyrusNajmabadi

Merge branch 'jsonSerialization' into addUsingOOP10

......@@ -258,7 +258,7 @@ public async Task TestFailedInstallRollsBackFile()
}
private Task<ImmutableArray<PackageWithTypeResult>> CreateSearchResult(
string packageName, string typeName, IReadOnlyList<string> containingNamespaceNames)
string packageName, string typeName, ImmutableArray<string> containingNamespaceNames)
{
return CreateSearchResult(new PackageWithTypeResult(
packageName: packageName, typeName: typeName, version: null,
......@@ -268,6 +268,6 @@ public async Task TestFailedInstallRollsBackFile()
private Task<ImmutableArray<PackageWithTypeResult>> CreateSearchResult(params PackageWithTypeResult[] results)
=> Task.FromResult(ImmutableArray.Create(results));
private IReadOnlyList<string> CreateNameParts(params string[] parts) => parts;
private ImmutableArray<string> CreateNameParts(params string[] parts) => parts.ToImmutableArray();
}
}
\ No newline at end of file
......@@ -175,10 +175,11 @@ public SymbolSearchUpdateEngine(ISymbolSearchLogService logService)
// Only look at reference assembly results.
if (type.PackageName.ToString() == MicrosoftAssemblyReferencesName)
{
var nameParts = new List<string>();
var nameParts = ArrayBuilder<string>.GetInstance();
GetFullName(nameParts, type.FullName.Parent);
var result = new ReferenceAssemblyWithTypeResult(
type.AssemblyName.ToString(), type.Name.ToString(), containingNamespaceNames: nameParts);
type.AssemblyName.ToString(), type.Name.ToString(),
containingNamespaceNames: nameParts.ToImmutableAndFree());
results.Add(result);
}
}
......@@ -200,7 +201,7 @@ where this.IsType(symbol) && !this.IsType(symbol.Parent())
private PackageWithTypeResult CreateResult(AddReferenceDatabase database, Symbol type)
{
var nameParts = new List<string>();
var nameParts = ArrayBuilder<string>.GetInstance();
GetFullName(nameParts, type.FullName.Parent);
var packageName = type.PackageName.ToString();
......@@ -212,7 +213,7 @@ private PackageWithTypeResult CreateResult(AddReferenceDatabase database, Symbol
typeName: type.Name.ToString(),
version: version,
rank: GetRank(type),
containingNamespaceNames: nameParts);
containingNamespaceNames: nameParts.ToImmutableAndFree());
}
private int GetRank(Symbol symbol)
......@@ -260,7 +261,7 @@ private bool IsType(Symbol symbol)
return symbol.Type.IsType();
}
private void GetFullName(List<string> nameParts, Path8 path)
private void GetFullName(ArrayBuilder<string> nameParts, Path8 path)
{
if (!path.IsEmpty)
{
......
......@@ -124,11 +124,11 @@ private async Task<RemoteHostClient.Session> TryGetSessionAsync()
return ImmutableArray<PackageWithTypeResult>.Empty;
}
var results = await session.InvokeAsync<SerializablePackageWithTypeResult[]>(
var results = await session.InvokeAsync<ImmutableArray<PackageWithTypeResult>>(
nameof(IRemoteSymbolSearchUpdateEngine.FindPackagesWithTypeAsync),
source, name, arity).ConfigureAwait(false);
return results.Select(r => r.Rehydrate()).ToImmutableArray();
return results;
}
public async Task<ImmutableArray<PackageWithAssemblyResult>> FindPackagesWithAssemblyAsync(
......@@ -141,11 +141,11 @@ private async Task<RemoteHostClient.Session> TryGetSessionAsync()
return ImmutableArray<PackageWithAssemblyResult>.Empty;
}
var results = await session.InvokeAsync<SerializablePackageWithAssemblyResult[]>(
var results = await session.InvokeAsync<ImmutableArray<PackageWithAssemblyResult>>(
nameof(IRemoteSymbolSearchUpdateEngine.FindPackagesWithAssemblyAsync),
source, assemblyName).ConfigureAwait(false);
return results.Select(r => r.Rehydrate()).ToImmutableArray();
return results;
}
public async Task<ImmutableArray<ReferenceAssemblyWithTypeResult>> FindReferenceAssembliesWithTypeAsync(
......@@ -158,11 +158,11 @@ private async Task<RemoteHostClient.Session> TryGetSessionAsync()
return ImmutableArray<ReferenceAssemblyWithTypeResult>.Empty;
}
var results = await session.InvokeAsync<SerializableReferenceAssemblyWithTypeResult[]>(
var results = await session.InvokeAsync<ImmutableArray<ReferenceAssemblyWithTypeResult>>(
nameof(IRemoteSymbolSearchUpdateEngine.FindReferenceAssembliesWithTypeAsync),
name, arity).ConfigureAwait(false);
return results.Select(r => r.Rehydrate()).ToImmutableArray();
return results;
}
public async Task UpdateContinuouslyAsync(
......
......@@ -239,7 +239,7 @@ End Class", fixProviderData:=New ProviderData(installerServiceMock.Object, packa
installerServiceMock.Verify()
End Function
Private Function CreateSearchResult(packageName As String, typeName As String, nameParts As IReadOnlyList(Of String)) As Task(Of ImmutableArray(Of PackageWithTypeResult))
Private Function CreateSearchResult(packageName As String, typeName As String, nameParts As ImmutableArray(Of String)) As Task(Of ImmutableArray(Of PackageWithTypeResult))
Return CreateSearchResult(New PackageWithTypeResult(
packageName:=packageName,
typeName:=typeName,
......@@ -252,8 +252,8 @@ End Class", fixProviderData:=New ProviderData(installerServiceMock.Object, packa
Return Task.FromResult(ImmutableArray.Create(results))
End Function
Private Function CreateNameParts(ParamArray parts As String()) As IReadOnlyList(Of String)
Return parts
Private Function CreateNameParts(ParamArray parts As String()) As ImmutableArray(Of String)
Return parts.ToImmutableArray()
End Function
End Class
End Namespace
\ No newline at end of file
// 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.Collections.Immutable;
using System.Threading.Tasks;
namespace Microsoft.CodeAnalysis.DesignerAttributes
{
internal interface IRemoteDesignerAttributeService
{
Task<DesignerAttributeDocumentData[]> ScanDesignerAttributesAsync(ProjectId projectId);
Task<ImmutableArray<DesignerAttributeDocumentData>> ScanDesignerAttributesAsync(ProjectId projectId);
}
}
}
\ No newline at end of file
......@@ -48,12 +48,12 @@ internal abstract partial class AbstractDocumentHighlightsService : IDocumentHig
return (succeeded: false, ImmutableArray<DocumentHighlights>.Empty);
}
var result = await session.InvokeAsync<SerializableDocumentHighlights[]>(
var result = await session.InvokeAsync<ImmutableArray<SerializableDocumentHighlights>>(
nameof(IRemoteDocumentHighlights.GetDocumentHighlightsAsync),
document.Id,
position,
documentsToSearch.Select(d => d.Id).ToArray()).ConfigureAwait(false);
return (true, SerializableDocumentHighlights.Rehydrate(result, document.Project.Solution));
return (true, result.SelectAsArray(h => h.Rehydrate(document.Project.Solution)));
}
}
......
// 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.Collections.Immutable;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.CodeAnalysis.DocumentHighlighting
{
internal interface IRemoteDocumentHighlights
{
Task<SerializableDocumentHighlights[]> GetDocumentHighlightsAsync(
Task<ImmutableArray<SerializableDocumentHighlights>> GetDocumentHighlightsAsync(
DocumentId documentId, int position, DocumentId[] documentIdsToSearch);
}
internal struct SerializableDocumentHighlights
{
public DocumentId DocumentId;
public SerializableHighlightSpan[] HighlightSpans;
public ImmutableArray<HighlightSpan> HighlightSpans;
public static ImmutableArray<DocumentHighlights> Rehydrate(SerializableDocumentHighlights[] array, Solution solution)
{
var result = ArrayBuilder<DocumentHighlights>.GetInstance(array.Length);
foreach (var dehydrated in array)
{
result.Push(dehydrated.Rehydrate(solution));
}
return result.ToImmutableAndFree();
}
private DocumentHighlights Rehydrate(Solution solution)
=> new DocumentHighlights(solution.GetDocument(DocumentId), SerializableHighlightSpan.Rehydrate(HighlightSpans));
public static SerializableDocumentHighlights[] Dehydrate(ImmutableArray<DocumentHighlights> array)
{
var result = new SerializableDocumentHighlights[array.Length];
var index = 0;
foreach (var highlights in array)
{
result[index] = Dehydrate(highlights);
index++;
}
public DocumentHighlights Rehydrate(Solution solution)
=> new DocumentHighlights(solution.GetDocument(DocumentId), HighlightSpans.ToImmutableArray());
return result;
}
private static SerializableDocumentHighlights Dehydrate(DocumentHighlights highlights)
public static SerializableDocumentHighlights Dehydrate(DocumentHighlights highlights)
=> new SerializableDocumentHighlights
{
DocumentId = highlights.Document.Id,
HighlightSpans = SerializableHighlightSpan.Dehydrate(highlights.HighlightSpans)
HighlightSpans = highlights.HighlightSpans
};
}
internal struct SerializableHighlightSpan
{
public TextSpan TextSpan;
public HighlightSpanKind Kind;
internal static SerializableHighlightSpan[] Dehydrate(ImmutableArray<HighlightSpan> array)
{
var result = new SerializableHighlightSpan[array.Length];
var index = 0;
foreach (var span in array)
{
result[index] = Dehydrate(span);
index++;
}
return result;
}
private static SerializableHighlightSpan Dehydrate(HighlightSpan span)
=> new SerializableHighlightSpan
{
Kind = span.Kind,
TextSpan = span.TextSpan
};
internal static ImmutableArray<HighlightSpan> Rehydrate(SerializableHighlightSpan[] array)
{
var result = ArrayBuilder<HighlightSpan>.GetInstance(array.Length);
foreach (var dehydrated in array)
{
result.Push(dehydrated.Rehydrate());
}
return result.ToImmutableAndFree();
}
private HighlightSpan Rehydrate()
=> new HighlightSpan(TextSpan, Kind);
}
}
\ No newline at end of file
......@@ -15,23 +15,21 @@ internal abstract partial class AbstractNavigateToSearchService
private async Task<ImmutableArray<INavigateToSearchResult>> SearchDocumentInRemoteProcessAsync(
RemoteHostClient.Session session, Document document, string searchPattern, CancellationToken cancellationToken)
{
var serializableResults = await session.InvokeAsync<SerializableNavigateToSearchResult[]>(
var serializableResults = await session.InvokeAsync<ImmutableArray<SerializableNavigateToSearchResult>>(
nameof(IRemoteNavigateToSearchService.SearchDocumentAsync),
new object[] { document.Id, searchPattern }, cancellationToken).ConfigureAwait(false);
serializableResults = serializableResults ?? Array.Empty<SerializableNavigateToSearchResult>();
return serializableResults.Select(r => r.Rehydrate(document.Project.Solution)).ToImmutableArray();
return serializableResults.SelectAsArray(r => r.Rehydrate(document.Project.Solution));
}
private async Task<ImmutableArray<INavigateToSearchResult>> SearchProjectInRemoteProcessAsync(
RemoteHostClient.Session session, Project project, string searchPattern, CancellationToken cancellationToken)
{
var serializableResults = await session.InvokeAsync<SerializableNavigateToSearchResult[]>(
var serializableResults = await session.InvokeAsync<ImmutableArray<SerializableNavigateToSearchResult>>(
nameof(IRemoteNavigateToSearchService.SearchProjectAsync),
new object[] { project.Id, searchPattern }, cancellationToken).ConfigureAwait(false);
serializableResults = serializableResults ?? Array.Empty<SerializableNavigateToSearchResult>();
return serializableResults.Select(r => r.Rehydrate(project.Solution)).ToImmutableArray();
return serializableResults.SelectAsArray(r => r.Rehydrate(project.Solution));
}
private static Task<RemoteHostClient.Session> GetRemoteHostSessionAsync(Project project, 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.Collections.Immutable;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Remote;
......@@ -7,7 +8,7 @@ namespace Microsoft.CodeAnalysis.NavigateTo
{
internal interface IRemoteNavigateToSearchService
{
Task<SerializableNavigateToSearchResult[]> SearchDocumentAsync(DocumentId documentId, string searchPattern);
Task<SerializableNavigateToSearchResult[]> SearchProjectAsync(ProjectId projectId, string searchPattern);
Task<ImmutableArray<SerializableNavigateToSearchResult>> SearchDocumentAsync(DocumentId documentId, string searchPattern);
Task<ImmutableArray<SerializableNavigateToSearchResult>> SearchProjectAsync(ProjectId projectId, string searchPattern);
}
}
// 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.Collections.Immutable;
using System.Linq;
using Microsoft.CodeAnalysis.NavigateTo;
using Microsoft.CodeAnalysis.Navigation;
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.CodeAnalysis.Remote
{
internal class SerializableTaggedText
{
public string Tag;
public string Text;
public static SerializableTaggedText Dehydrate(TaggedText taggedText)
{
return new SerializableTaggedText { Tag = taggedText.Tag, Text = taggedText.Text };
}
internal static SerializableTaggedText[] Dehydrate(ImmutableArray<TaggedText> displayTaggedParts)
{
return displayTaggedParts.Select(Dehydrate).ToArray();
}
public TaggedText Rehydrate()
{
return new TaggedText(Tag, Text);
}
}
#region NavigateTo
internal class SerializableNavigateToSearchResult
......@@ -39,7 +17,7 @@ internal class SerializableNavigateToSearchResult
public NavigateToMatchKind MatchKind;
public bool IsCaseSensitive;
public string Name;
public TextSpan[] NameMatchSpans;
public ImmutableArray<TextSpan> NameMatchSpans;
public string SecondarySort;
public string Summary;
......@@ -54,7 +32,7 @@ internal static SerializableNavigateToSearchResult Dehydrate(INavigateToSearchRe
MatchKind = result.MatchKind,
IsCaseSensitive = result.IsCaseSensitive,
Name = result.Name,
NameMatchSpans = result.NameMatchSpans.ToArray(),
NameMatchSpans = result.NameMatchSpans,
SecondarySort = result.SecondarySort,
Summary = result.Summary,
NavigableItem = SerializableNavigableItem.Dehydrate(result.NavigableItem)
......@@ -104,7 +82,7 @@ internal class SerializableNavigableItem
{
public Glyph Glyph;
public SerializableTaggedText[] DisplayTaggedParts;
public ImmutableArray<TaggedText> DisplayTaggedParts;
public bool DisplayFileLocation;
......@@ -113,34 +91,29 @@ internal class SerializableNavigableItem
public DocumentId Document;
public TextSpan SourceSpan;
SerializableNavigableItem[] ChildItems;
ImmutableArray<SerializableNavigableItem> ChildItems;
public static SerializableNavigableItem Dehydrate(INavigableItem item)
{
return new SerializableNavigableItem
{
Glyph = item.Glyph,
DisplayTaggedParts = SerializableTaggedText.Dehydrate(item.DisplayTaggedParts),
DisplayTaggedParts = item.DisplayTaggedParts,
DisplayFileLocation = item.DisplayFileLocation,
IsImplicitlyDeclared = item.IsImplicitlyDeclared,
Document = item.Document.Id,
SourceSpan = item.SourceSpan,
ChildItems = SerializableNavigableItem.Dehydrate(item.ChildItems)
ChildItems = item.ChildItems.SelectAsArray(Dehydrate)
};
}
private static SerializableNavigableItem[] Dehydrate(ImmutableArray<INavigableItem> childItems)
{
return childItems.Select(Dehydrate).ToArray();
}
public INavigableItem Rehydrate(Solution solution)
{
var childItems = ChildItems == null
? ImmutableArray<INavigableItem>.Empty
: ChildItems.Select(c => c.Rehydrate(solution)).ToImmutableArray();
: ChildItems.SelectAsArray(c => c.Rehydrate(solution));
return new NavigableItem(
Glyph, DisplayTaggedParts.Select(p => p.Rehydrate()).ToImmutableArray(),
Glyph, DisplayTaggedParts.ToImmutableArray(),
DisplayFileLocation, IsImplicitlyDeclared,
solution.GetDocument(Document),
SourceSpan,
......
......@@ -121,7 +121,7 @@ public async Task AnalyzeProjectAsync(Project project, bool semanticsChanged, In
return null;
}
var serializedResults = await session.InvokeAsync<DesignerAttributeDocumentData[]>(
var serializedResults = await session.InvokeAsync<ImmutableArray<DesignerAttributeDocumentData>>(
nameof(IRemoteDesignerAttributeService.ScanDesignerAttributesAsync), project.Id).ConfigureAwait(false);
var data = serializedResults.ToImmutableDictionary(kvp => kvp.FilePath);
......
......@@ -93,7 +93,7 @@ class Test { }";
var solution = workspace.CurrentSolution;
var result = await client.RunCodeAnalysisServiceOnRemoteHostAsync<DesignerAttributeDocumentData[]>(
var result = await client.RunCodeAnalysisServiceOnRemoteHostAsync<ImmutableArray<DesignerAttributeDocumentData>>(
solution, nameof(IRemoteDesignerAttributeService.ScanDesignerAttributesAsync),
solution.Projects.First().Id, CancellationToken.None);
......
......@@ -98,7 +98,7 @@ internal static partial class DeclarationFinder
{
if (session != null)
{
var result = await session.InvokeAsync<SerializableSymbolAndProjectId[]>(
var result = await session.InvokeAsync<ImmutableArray<SerializableSymbolAndProjectId>>(
nameof(IRemoteSymbolFinder.FindAllDeclarationsWithNormalQueryAsync),
project.Id, query.Name, query.Kind, criteria).ConfigureAwait(false);
......@@ -113,7 +113,7 @@ internal static partial class DeclarationFinder
}
private static async Task<ImmutableArray<SymbolAndProjectId>> RehydrateAsync(
Solution solution, SerializableSymbolAndProjectId[] array, CancellationToken cancellationToken)
Solution solution, ImmutableArray<SerializableSymbolAndProjectId> array, CancellationToken cancellationToken)
{
var result = ArrayBuilder<SymbolAndProjectId>.GetInstance(array.Length);
......
......@@ -118,7 +118,7 @@ internal static partial class DeclarationFinder
{
if (session != null)
{
var result = await session.InvokeAsync<SerializableSymbolAndProjectId[]>(
var result = await session.InvokeAsync<ImmutableArray<SerializableSymbolAndProjectId>>(
nameof(IRemoteSymbolFinder.FindSolutionSourceDeclarationsWithNormalQueryAsync),
name, ignoreCase, criteria).ConfigureAwait(false);
......@@ -139,7 +139,7 @@ internal static partial class DeclarationFinder
{
if (session != null)
{
var result = await session.InvokeAsync<SerializableSymbolAndProjectId[]>(
var result = await session.InvokeAsync<ImmutableArray<SerializableSymbolAndProjectId>>(
nameof(IRemoteSymbolFinder.FindProjectSourceDeclarationsWithNormalQueryAsync),
project.Id, name, ignoreCase, criteria).ConfigureAwait(false);
......@@ -160,7 +160,7 @@ internal static partial class DeclarationFinder
{
if (session != null)
{
var result = await session.InvokeAsync<SerializableSymbolAndProjectId[]>(
var result = await session.InvokeAsync<ImmutableArray<SerializableSymbolAndProjectId>>(
nameof(IRemoteSymbolFinder.FindProjectSourceDeclarationsWithPatternAsync),
project.Id, pattern, criteria).ConfigureAwait(false);
......
// 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.Collections.Immutable;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Remote;
......@@ -10,16 +11,16 @@ internal interface IRemoteSymbolFinder
Task FindReferencesAsync(SerializableSymbolAndProjectId symbolAndProjectIdArg, DocumentId[] documentArgs);
Task FindLiteralReferencesAsync(object value);
Task<SerializableSymbolAndProjectId[]> FindAllDeclarationsWithNormalQueryAsync(
Task<ImmutableArray<SerializableSymbolAndProjectId>> FindAllDeclarationsWithNormalQueryAsync(
ProjectId projectId, string name, SearchKind searchKind, SymbolFilter criteria);
Task<SerializableSymbolAndProjectId[]> FindSolutionSourceDeclarationsWithNormalQueryAsync(
Task<ImmutableArray<SerializableSymbolAndProjectId>> FindSolutionSourceDeclarationsWithNormalQueryAsync(
string name, bool ignoreCase, SymbolFilter criteria);
Task<SerializableSymbolAndProjectId[]> FindProjectSourceDeclarationsWithNormalQueryAsync(
Task<ImmutableArray<SerializableSymbolAndProjectId>> FindProjectSourceDeclarationsWithNormalQueryAsync(
ProjectId projectId, string name, bool ignoreCase, SymbolFilter criteria);
Task<SerializableSymbolAndProjectId[]> FindProjectSourceDeclarationsWithPatternAsync(
Task<ImmutableArray<SerializableSymbolAndProjectId>> FindProjectSourceDeclarationsWithPatternAsync(
ProjectId projectId, string pattern, SymbolFilter criteria);
}
}
\ No newline at end of file
// 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.Diagnostics;
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;
using Roslyn.Utilities;
......@@ -133,78 +130,4 @@ internal class SerializableReferenceLocation
}
#endregion
#region SymbolSearch
internal class SerializablePackageWithTypeResult
{
public string PackageName;
public string TypeName;
public string Version;
public int Rank;
public string[] ContainingNamespaceNames;
public static SerializablePackageWithTypeResult Dehydrate(PackageWithTypeResult result)
{
return new SerializablePackageWithTypeResult
{
PackageName = result.PackageName,
TypeName = result.TypeName,
Version = result.Version,
Rank = result.Rank,
ContainingNamespaceNames = result.ContainingNamespaceNames.ToArray(),
};
}
public PackageWithTypeResult Rehydrate()
{
return new PackageWithTypeResult(
PackageName, TypeName, Version, Rank, ContainingNamespaceNames);
}
}
internal class SerializablePackageWithAssemblyResult
{
public string PackageName;
public string Version;
public int Rank;
public static SerializablePackageWithAssemblyResult Dehydrate(PackageWithAssemblyResult result)
{
return new SerializablePackageWithAssemblyResult
{
PackageName = result.PackageName,
Version = result.Version,
Rank = result.Rank,
};
}
public PackageWithAssemblyResult Rehydrate()
=> new PackageWithAssemblyResult(PackageName, Version, Rank);
}
internal class SerializableReferenceAssemblyWithTypeResult
{
public string AssemblyName;
public string TypeName;
public string[] ContainingNamespaceNames;
public static SerializableReferenceAssemblyWithTypeResult Dehydrate(
ReferenceAssemblyWithTypeResult result)
{
return new SerializableReferenceAssemblyWithTypeResult
{
ContainingNamespaceNames = result.ContainingNamespaceNames.ToArray(),
AssemblyName = result.AssemblyName,
TypeName = result.TypeName
};
}
public ReferenceAssemblyWithTypeResult Rehydrate()
{
return new ReferenceAssemblyWithTypeResult(AssemblyName, TypeName, ContainingNamespaceNames);
}
}
#endregion
}
\ No newline at end of file
// 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.Collections.Immutable;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Remote;
namespace Microsoft.CodeAnalysis.SymbolSearch
{
......@@ -9,8 +9,8 @@ internal interface IRemoteSymbolSearchUpdateEngine
{
Task UpdateContinuouslyAsync(string sourceName, string localSettingsDirectory);
Task<SerializablePackageWithTypeResult[]> FindPackagesWithTypeAsync(string source, string name, int arity);
Task<SerializablePackageWithAssemblyResult[]> FindPackagesWithAssemblyAsync(string source, string name);
Task<SerializableReferenceAssemblyWithTypeResult[]> FindReferenceAssembliesWithTypeAsync(string name, int arity);
Task<ImmutableArray<PackageWithTypeResult>> FindPackagesWithTypeAsync(string source, string name, int arity);
Task<ImmutableArray<PackageWithAssemblyResult>> FindPackagesWithAssemblyAsync(string source, string name);
Task<ImmutableArray<ReferenceAssemblyWithTypeResult>> FindReferenceAssembliesWithTypeAsync(string name, int arity);
}
}
\ No newline at end of file
......@@ -64,7 +64,7 @@ protected PackageResult(string packageName, int rank)
internal class PackageWithTypeResult : PackageResult
{
public readonly IReadOnlyList<string> ContainingNamespaceNames;
public readonly ImmutableArray<string> ContainingNamespaceNames;
public readonly string TypeName;
public readonly string Version;
......@@ -73,7 +73,7 @@ internal class PackageWithTypeResult : PackageResult
string typeName,
string version,
int rank,
IReadOnlyList<string> containingNamespaceNames)
ImmutableArray<string> containingNamespaceNames)
: base(packageName, rank)
{
TypeName = typeName;
......@@ -118,14 +118,14 @@ public int CompareTo(PackageWithAssemblyResult other)
internal class ReferenceAssemblyWithTypeResult
{
public readonly IReadOnlyList<string> ContainingNamespaceNames;
public readonly ImmutableArray<string> ContainingNamespaceNames;
public readonly string AssemblyName;
public readonly string TypeName;
public ReferenceAssemblyWithTypeResult(
string assemblyName,
string typeName,
IReadOnlyList<string> containingNamespaceNames)
ImmutableArray<string> containingNamespaceNames)
{
AssemblyName = assemblyName;
TypeName = typeName;
......
// 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.Collections.Immutable;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.DesignerAttributes;
......@@ -16,7 +17,7 @@ internal partial class CodeAnalysisService : IRemoteDesignerAttributeService
///
/// This will be called by ServiceHub/JsonRpc framework
/// </summary>
public async Task<DesignerAttributeDocumentData[]> ScanDesignerAttributesAsync(ProjectId projectId)
public async Task<ImmutableArray<DesignerAttributeDocumentData>> ScanDesignerAttributesAsync(ProjectId projectId)
{
using (RoslynLogger.LogBlock(FunctionId.CodeAnalysisService_GetDesignerAttributesAsync, projectId.DebugName, CancellationToken))
{
......@@ -25,7 +26,7 @@ public async Task<DesignerAttributeDocumentData[]> ScanDesignerAttributesAsync(P
var data = await AbstractDesignerAttributeService.TryAnalyzeProjectInCurrentProcessAsync(
project, CancellationToken).ConfigureAwait(false);
return data.Values.ToArray();
return data.Values.ToImmutableArray();
}
}
}
......
......@@ -11,7 +11,7 @@ namespace Microsoft.CodeAnalysis.Remote
// root level service for all Roslyn services
internal partial class CodeAnalysisService : IRemoteDocumentHighlights
{
public async Task<SerializableDocumentHighlights[]> GetDocumentHighlightsAsync(
public async Task<ImmutableArray<SerializableDocumentHighlights>> GetDocumentHighlightsAsync(
DocumentId documentId, int position, DocumentId[] documentIdsToSearch)
{
var solution = await GetSolutionAsync().ConfigureAwait(false);
......@@ -22,7 +22,7 @@ internal partial class CodeAnalysisService : IRemoteDocumentHighlights
var result = await service.GetDocumentHighlightsAsync(
document, position, documentsToSearch, CancellationToken).ConfigureAwait(false);
return SerializableDocumentHighlights.Dehydrate(result);
return result.SelectAsArray(SerializableDocumentHighlights.Dehydrate);
}
}
}
\ No newline at end of file
......@@ -9,7 +9,7 @@ namespace Microsoft.CodeAnalysis.Remote
{
internal partial class CodeAnalysisService : IRemoteNavigateToSearchService
{
public async Task<SerializableNavigateToSearchResult[]> SearchDocumentAsync(
public async Task<ImmutableArray<SerializableNavigateToSearchResult>> SearchDocumentAsync(
DocumentId documentId, string searchPattern)
{
using (UserOperationBooster.Boost())
......@@ -24,7 +24,7 @@ internal partial class CodeAnalysisService : IRemoteNavigateToSearchService
}
}
public async Task<SerializableNavigateToSearchResult[]> SearchProjectAsync(
public async Task<ImmutableArray<SerializableNavigateToSearchResult>> SearchProjectAsync(
ProjectId projectId, string searchPattern)
{
using (UserOperationBooster.Boost())
......@@ -39,10 +39,10 @@ internal partial class CodeAnalysisService : IRemoteNavigateToSearchService
}
}
private SerializableNavigateToSearchResult[] Convert(
private ImmutableArray<SerializableNavigateToSearchResult> Convert(
ImmutableArray<INavigateToSearchResult> result)
{
return result.Select(SerializableNavigateToSearchResult.Dehydrate).ToArray();
return result.SelectAsArray(SerializableNavigateToSearchResult.Dehydrate);
}
}
}
\ No newline at end of file
......@@ -44,7 +44,7 @@ public async Task FindLiteralReferencesAsync(object value)
value, solution, progressCallback, CancellationToken).ConfigureAwait(false);
}
public async Task<SerializableSymbolAndProjectId[]> FindAllDeclarationsWithNormalQueryAsync(
public async Task<ImmutableArray<SerializableSymbolAndProjectId>> FindAllDeclarationsWithNormalQueryAsync(
ProjectId projectId, string name, SearchKind searchKind, SymbolFilter criteria)
{
var solution = await GetSolutionAsync().ConfigureAwait(false);
......@@ -55,21 +55,21 @@ public async Task FindLiteralReferencesAsync(object value)
var result = await DeclarationFinder.FindAllDeclarationsWithNormalQueryInCurrentProcessAsync(
project, query, criteria, this.CancellationToken).ConfigureAwait(false);
return result.Select(SerializableSymbolAndProjectId.Dehydrate).ToArray();
return result.SelectAsArray(SerializableSymbolAndProjectId.Dehydrate);
}
}
public async Task<SerializableSymbolAndProjectId[]> FindSolutionSourceDeclarationsWithNormalQueryAsync(
public async Task<ImmutableArray<SerializableSymbolAndProjectId>> FindSolutionSourceDeclarationsWithNormalQueryAsync(
string name, bool ignoreCase, SymbolFilter criteria)
{
var solution = await GetSolutionAsync().ConfigureAwait(false);
var result = await DeclarationFinder.FindSourceDeclarationsWithNormalQueryInCurrentProcessAsync(
solution, name, ignoreCase, criteria, CancellationToken).ConfigureAwait(false);
return result.Select(SerializableSymbolAndProjectId.Dehydrate).ToArray();
return result.SelectAsArray(SerializableSymbolAndProjectId.Dehydrate);
}
public async Task<SerializableSymbolAndProjectId[]> FindProjectSourceDeclarationsWithNormalQueryAsync(
public async Task<ImmutableArray<SerializableSymbolAndProjectId>> FindProjectSourceDeclarationsWithNormalQueryAsync(
ProjectId projectId, string name, bool ignoreCase, SymbolFilter criteria)
{
var solution = await GetSolutionAsync().ConfigureAwait(false);
......@@ -78,10 +78,10 @@ public async Task FindLiteralReferencesAsync(object value)
var result = await DeclarationFinder.FindSourceDeclarationsWithNormalQueryInCurrentProcessAsync(
project, name, ignoreCase, criteria, CancellationToken).ConfigureAwait(false);
return result.Select(SerializableSymbolAndProjectId.Dehydrate).ToArray();
return result.SelectAsArray(SerializableSymbolAndProjectId.Dehydrate);
}
public async Task<SerializableSymbolAndProjectId[]> FindProjectSourceDeclarationsWithPatternAsync(
public async Task<ImmutableArray<SerializableSymbolAndProjectId>> FindProjectSourceDeclarationsWithPatternAsync(
ProjectId projectId, string pattern, SymbolFilter criteria)
{
var solution = await GetSolutionAsync().ConfigureAwait(false);
......@@ -90,7 +90,7 @@ public async Task FindLiteralReferencesAsync(object value)
var result = await DeclarationFinder.FindSourceDeclarationsWithPatternInCurrentProcessAsync(
project, pattern, criteria, CancellationToken).ConfigureAwait(false);
return result.Select(SerializableSymbolAndProjectId.Dehydrate).ToArray();
return result.SelectAsArray(SerializableSymbolAndProjectId.Dehydrate);
}
private class FindLiteralReferencesProgressCallback : IStreamingFindLiteralReferencesProgress
......
// 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.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.SymbolSearch;
......@@ -26,28 +26,28 @@ public Task UpdateContinuouslyAsync(string sourceName, string localSettingsDirec
return _updateEngine.UpdateContinuouslyAsync(sourceName, localSettingsDirectory);
}
public async Task<SerializablePackageWithTypeResult[]> FindPackagesWithTypeAsync(string source, string name, int arity)
public async Task<ImmutableArray<PackageWithTypeResult>> FindPackagesWithTypeAsync(string source, string name, int arity)
{
var results = await _updateEngine.FindPackagesWithTypeAsync(
source, name, arity).ConfigureAwait(false);
var serializedResults = results.Select(SerializablePackageWithTypeResult.Dehydrate).ToArray();
return serializedResults;
return results;
}
public async Task<SerializablePackageWithAssemblyResult[]> FindPackagesWithAssemblyAsync(string source, string assemblyName)
public async Task<ImmutableArray<PackageWithAssemblyResult>> FindPackagesWithAssemblyAsync(string source, string assemblyName)
{
var results = await _updateEngine.FindPackagesWithAssemblyAsync(
source, assemblyName).ConfigureAwait(false);
var serializedResults = results.Select(SerializablePackageWithAssemblyResult.Dehydrate).ToArray();
return serializedResults;
return results;
}
public async Task<SerializableReferenceAssemblyWithTypeResult[]> FindReferenceAssembliesWithTypeAsync(string name, int arity)
public async Task<ImmutableArray<ReferenceAssemblyWithTypeResult>> FindReferenceAssembliesWithTypeAsync(string name, int arity)
{
var results = await _updateEngine.FindReferenceAssembliesWithTypeAsync(
name, arity).ConfigureAwait(false);
var serializedResults = results.Select(SerializableReferenceAssemblyWithTypeResult.Dehydrate).ToArray();
return serializedResults;
return results;
}
private class LogService : ISymbolSearchLogService
......
......@@ -2,7 +2,11 @@
using System;
using System.Collections.Immutable;
using System.Linq;
using Microsoft.CodeAnalysis.DocumentHighlighting;
using Microsoft.CodeAnalysis.Packaging;
using Microsoft.CodeAnalysis.SymbolSearch;
using Microsoft.CodeAnalysis.Text;
using Microsoft.CodeAnalysis.TodoComments;
using Newtonsoft.Json;
using Roslyn.Utilities;
......@@ -13,9 +17,16 @@ internal partial class AggregateJsonConverter : JsonConverter
{
partial void AppendRoslynSpecificJsonConverters(ImmutableDictionary<Type, JsonConverter>.Builder builder)
{
Add(builder, new HighlightSpanJsonConverter());
Add(builder, new TaggedTextJsonConverter());
Add(builder, new TodoCommentDescriptorJsonConverter());
Add(builder, new TodoCommentJsonConverter());
Add(builder, new PackageSourceJsonConverter());
Add(builder, new PackageWithTypeResultJsonConverter());
Add(builder, new PackageWithAssemblyResultJsonConverter());
Add(builder, new ReferenceAssemblyWithTypeResultJsonConverter());
}
private class TodoCommentDescriptorJsonConverter : BaseJsonConverter<TodoCommentDescriptor>
......@@ -69,13 +80,13 @@ protected override void WriteValue(JsonWriter writer, TodoComment todoComment, J
{
writer.WriteStartObject();
writer.WritePropertyName("descriptor");
writer.WritePropertyName(nameof(TodoComment.Descriptor));
serializer.Serialize(writer, todoComment.Descriptor);
writer.WritePropertyName("message");
writer.WritePropertyName(nameof(TodoComment.Message));
writer.WriteValue(todoComment.Message);
writer.WritePropertyName("position");
writer.WritePropertyName(nameof(TodoComment.Position));
writer.WriteValue(todoComment.Position);
writer.WriteEndObject();
......@@ -101,14 +112,179 @@ protected override void WriteValue(JsonWriter writer, PackageSource source, Json
{
writer.WriteStartObject();
writer.WritePropertyName("name");
writer.WritePropertyName(nameof(PackageSource.Name));
writer.WriteValue(source.Name);
writer.WritePropertyName("source");
writer.WritePropertyName(nameof(PackageSource.Source));
writer.WriteValue(source.Source);
writer.WriteEndObject();
}
}
private class HighlightSpanJsonConverter : BaseJsonConverter<HighlightSpan>
{
protected override HighlightSpan ReadValue(JsonReader reader, JsonSerializer serializer)
{
Contract.ThrowIfFalse(reader.TokenType == JsonToken.StartObject);
var textSpan = ReadProperty<TextSpan>(serializer, reader);
var kind = (HighlightSpanKind)ReadProperty<long>(reader);
Contract.ThrowIfFalse(reader.Read());
Contract.ThrowIfFalse(reader.TokenType == JsonToken.EndObject);
return new HighlightSpan(textSpan, kind);
}
protected override void WriteValue(JsonWriter writer, HighlightSpan source, JsonSerializer serializer)
{
writer.WriteStartObject();
writer.WritePropertyName(nameof(HighlightSpan.TextSpan));
serializer.Serialize(writer, source.TextSpan);
writer.WritePropertyName(nameof(HighlightSpan.Kind));
writer.WriteValue(source.Kind);
writer.WriteEndObject();
}
}
private class PackageWithTypeResultJsonConverter : BaseJsonConverter<PackageWithTypeResult>
{
protected override PackageWithTypeResult ReadValue(JsonReader reader, JsonSerializer serializer)
{
Contract.ThrowIfFalse(reader.TokenType == JsonToken.StartObject);
var packageName = ReadProperty<string>(reader);
var typeName = ReadProperty<string>(reader);
var version = ReadProperty<string>(reader);
var rank = (int)ReadProperty<long>(reader);
var containingNamespaceNames = ReadProperty<ImmutableArray<string>>(serializer, reader);
Contract.ThrowIfFalse(reader.Read());
Contract.ThrowIfFalse(reader.TokenType == JsonToken.EndObject);
return new PackageWithTypeResult(packageName, typeName, version, rank, containingNamespaceNames);
}
protected override void WriteValue(JsonWriter writer, PackageWithTypeResult source, JsonSerializer serializer)
{
writer.WriteStartObject();
writer.WritePropertyName(nameof(PackageWithTypeResult.PackageName));
writer.WriteValue(source.PackageName);
writer.WritePropertyName(nameof(PackageWithTypeResult.TypeName));
writer.WriteValue(source.TypeName);
writer.WritePropertyName(nameof(PackageWithTypeResult.Version));
writer.WriteValue(source.Version);
writer.WritePropertyName(nameof(PackageWithTypeResult.Rank));
writer.WriteValue(source.Rank);
writer.WritePropertyName(nameof(PackageWithTypeResult.ContainingNamespaceNames));
serializer.Serialize(writer, source.ContainingNamespaceNames);
writer.WriteEndObject();
}
}
private class PackageWithAssemblyResultJsonConverter : BaseJsonConverter<PackageWithAssemblyResult>
{
protected override PackageWithAssemblyResult ReadValue(JsonReader reader, JsonSerializer serializer)
{
Contract.ThrowIfFalse(reader.TokenType == JsonToken.StartObject);
var packageName = ReadProperty<string>(reader);
var version = ReadProperty<string>(reader);
var rank = (int)ReadProperty<long>(reader);
Contract.ThrowIfFalse(reader.Read());
Contract.ThrowIfFalse(reader.TokenType == JsonToken.EndObject);
return new PackageWithAssemblyResult(packageName, version, rank);
}
protected override void WriteValue(JsonWriter writer, PackageWithAssemblyResult source, JsonSerializer serializer)
{
writer.WriteStartObject();
writer.WritePropertyName(nameof(PackageWithAssemblyResult.PackageName));
writer.WriteValue(source.PackageName);
writer.WritePropertyName(nameof(PackageWithAssemblyResult.Version));
writer.WriteValue(source.Version);
writer.WritePropertyName(nameof(PackageWithAssemblyResult.Rank));
writer.WriteValue(source.Rank);
writer.WriteEndObject();
}
}
private class ReferenceAssemblyWithTypeResultJsonConverter : BaseJsonConverter<ReferenceAssemblyWithTypeResult>
{
protected override ReferenceAssemblyWithTypeResult ReadValue(JsonReader reader, JsonSerializer serializer)
{
Contract.ThrowIfFalse(reader.TokenType == JsonToken.StartObject);
var assemblyName = ReadProperty<string>(reader);
var typeName = ReadProperty<string>(reader);
var containingNamespaceNames = ReadProperty<ImmutableArray<string>>(serializer, reader);
Contract.ThrowIfFalse(reader.Read());
Contract.ThrowIfFalse(reader.TokenType == JsonToken.EndObject);
return new ReferenceAssemblyWithTypeResult(assemblyName, typeName, containingNamespaceNames);
}
protected override void WriteValue(JsonWriter writer, ReferenceAssemblyWithTypeResult source, JsonSerializer serializer)
{
writer.WriteStartObject();
writer.WritePropertyName(nameof(ReferenceAssemblyWithTypeResult.AssemblyName));
writer.WriteValue(source.AssemblyName);
writer.WritePropertyName(nameof(ReferenceAssemblyWithTypeResult.TypeName));
writer.WriteValue(source.TypeName);
writer.WritePropertyName(nameof(ReferenceAssemblyWithTypeResult.ContainingNamespaceNames));
serializer.Serialize(writer, source.ContainingNamespaceNames);
writer.WriteEndObject();
}
}
private class TaggedTextJsonConverter : BaseJsonConverter<TaggedText>
{
protected override TaggedText ReadValue(JsonReader reader, JsonSerializer serializer)
{
Contract.ThrowIfFalse(reader.TokenType == JsonToken.StartObject);
var tag = ReadProperty<string>(reader);
var text = ReadProperty<string>(reader);
Contract.ThrowIfFalse(reader.Read());
Contract.ThrowIfFalse(reader.TokenType == JsonToken.EndObject);
return new TaggedText(tag, text);
}
protected override void WriteValue(JsonWriter writer, TaggedText source, JsonSerializer serializer)
{
writer.WriteStartObject();
writer.WritePropertyName(nameof(TaggedText.Tag));
writer.WriteValue(source.Tag);
writer.WritePropertyName(nameof(TaggedText.Text));
writer.WriteValue(source.Text);
writer.WriteEndObject();
}
}
}
}
\ No newline at end of file
......@@ -111,10 +111,10 @@ protected override void WriteValue(JsonWriter writer, TextSpan span, JsonSeriali
{
writer.WriteStartObject();
writer.WritePropertyName("start");
writer.WritePropertyName(nameof(TextSpan.Start));
writer.WriteValue(span.Start);
writer.WritePropertyName("length");
writer.WritePropertyName(nameof(TextSpan.Length));
writer.WriteValue(span.Length);
writer.WriteEndObject();
......@@ -144,13 +144,13 @@ protected override void WriteValue(JsonWriter writer, TextChange change, JsonSer
writer.WriteStartObject();
writer.WritePropertyName("start");
writer.WritePropertyName(nameof(TextSpan.Start));
writer.WriteValue(span.Start);
writer.WritePropertyName("length");
writer.WritePropertyName(nameof(TextSpan.Length));
writer.WriteValue(span.Length);
writer.WritePropertyName("newText");
writer.WritePropertyName(nameof(TextChange.NewText));
writer.WriteValue(change.NewText);
writer.WriteEndObject();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册