Skip to content

Commit

Permalink
Merge pull request #21539 from heejaechang/noImmutable
Browse files Browse the repository at this point in the history
removed ImmutableArray from json.net usage. and moved to IList
  • Loading branch information
brettfo authored Aug 17, 2017
2 parents cbc5d52 + a857f8c commit aca31f6
Show file tree
Hide file tree
Showing 38 changed files with 185 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using Microsoft.CodeAnalysis;

namespace Roslyn.Utilities
{
Expand Down Expand Up @@ -242,6 +244,19 @@ public static IEnumerable<T> WhereNotNull<T>(this IEnumerable<T> source)
return source.Where((Func<T, bool>)s_notNullTest);
}

public static ImmutableArray<TResult> SelectAsArray<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, TResult> selector)
{
if (source == null)
{
return ImmutableArray<TResult>.Empty;
}

var builder = ArrayBuilder<TResult>.GetInstance();
builder.AddRange(source.Select(selector));

return builder.ToImmutableAndFree();
}

public static bool All(this IEnumerable<bool> source)
{
if (source == null)
Expand Down
6 changes: 3 additions & 3 deletions src/EditorFeatures/CSharpTest/AddUsing/AddUsingTests_NuGet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,16 +257,16 @@ await TestInRegularAndScriptAsync(
installerServiceMock.Verify();
}

private Task<ImmutableArray<PackageWithTypeResult>> CreateSearchResult(
private Task<IList<PackageWithTypeResult>> CreateSearchResult(
string packageName, string typeName, ImmutableArray<string> containingNamespaceNames)
{
return CreateSearchResult(new PackageWithTypeResult(
packageName: packageName, typeName: typeName, version: null,
rank: 0, containingNamespaceNames: containingNamespaceNames));
}

private Task<ImmutableArray<PackageWithTypeResult>> CreateSearchResult(params PackageWithTypeResult[] results)
=> Task.FromResult(ImmutableArray.Create(results));
private Task<IList<PackageWithTypeResult>> CreateSearchResult(params PackageWithTypeResult[] results)
=> Task.FromResult<IList<PackageWithTypeResult>>(ImmutableArray.Create(results));

private ImmutableArray<string> CreateNameParts(params string[] parts) => parts.ToImmutableArray();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public async Task AnalyzeSyntaxAsync(Document document, InvocationReasons reason
}
}

private async Task<IList<TodoComment>> GetTodoCommentsAsync(Document document, ImmutableArray<TodoCommentDescriptor> tokens, CancellationToken cancellationToken)
private async Task<IList<TodoComment>> GetTodoCommentsAsync(Document document, IList<TodoCommentDescriptor> tokens, CancellationToken cancellationToken)
{
var service = document.GetLanguageService<ITodoCommentService>();
if (service == null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// 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.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Threading;
Expand Down Expand Up @@ -122,11 +123,11 @@ public async Task<ImmutableArray<PackageWithTypeResult>> FindPackagesWithTypeAsy
return ImmutableArray<PackageWithTypeResult>.Empty;
}

var results = await session.InvokeAsync<ImmutableArray<PackageWithTypeResult>>(
var results = await session.InvokeAsync<IList<PackageWithTypeResult>>(
nameof(IRemoteSymbolSearchUpdateEngine.FindPackagesWithTypeAsync),
source, name, arity).ConfigureAwait(false);

return results;
return results.ToImmutableArrayOrEmpty();
}

public async Task<ImmutableArray<PackageWithAssemblyResult>> FindPackagesWithAssemblyAsync(
Expand All @@ -139,11 +140,11 @@ public async Task<ImmutableArray<PackageWithAssemblyResult>> FindPackagesWithAss
return ImmutableArray<PackageWithAssemblyResult>.Empty;
}

var results = await session.InvokeAsync<ImmutableArray<PackageWithAssemblyResult>>(
var results = await session.InvokeAsync<IList<PackageWithAssemblyResult>>(
nameof(IRemoteSymbolSearchUpdateEngine.FindPackagesWithAssemblyAsync),
source, assemblyName).ConfigureAwait(false);

return results;
return results.ToImmutableArrayOrEmpty();
}

public async Task<ImmutableArray<ReferenceAssemblyWithTypeResult>> FindReferenceAssembliesWithTypeAsync(
Expand All @@ -156,11 +157,11 @@ public async Task<ImmutableArray<ReferenceAssemblyWithTypeResult>> FindReference
return ImmutableArray<ReferenceAssemblyWithTypeResult>.Empty;
}

var results = await session.InvokeAsync<ImmutableArray<ReferenceAssemblyWithTypeResult>>(
var results = await session.InvokeAsync<IList<ReferenceAssemblyWithTypeResult>>(
nameof(IRemoteSymbolSearchUpdateEngine.FindReferenceAssembliesWithTypeAsync),
name, arity).ConfigureAwait(false);

return results;
return results.ToImmutableArrayOrEmpty();
}

public async Task UpdateContinuouslyAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ImmutableArray(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 IList(Of PackageWithTypeResult))
Return CreateSearchResult(New PackageWithTypeResult(
packageName:=packageName,
typeName:=typeName,
Expand All @@ -248,8 +248,8 @@ End Class", fixProviderData:=New ProviderData(installerServiceMock.Object, packa
containingNamespaceNames:=nameParts))
End Function

Private Function CreateSearchResult(ParamArray results As PackageWithTypeResult()) As Task(Of ImmutableArray(Of PackageWithTypeResult))
Return Task.FromResult(ImmutableArray.Create(results))
Private Function CreateSearchResult(ParamArray results As PackageWithTypeResult()) As Task(Of IList(Of PackageWithTypeResult))
Return Task.FromResult(Of IList(Of PackageWithTypeResult))(ImmutableArray.Create(results))
End Function

Private Function CreateNameParts(ParamArray parts As String()) As ImmutableArray(Of String)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal class CSharpTodoCommentService : AbstractTodoCommentService
private static readonly int s_multilineCommentPostfixLength = "*/".Length;
private const string SingleLineCommentPrefix = "//";

protected override void AppendTodoComments(ImmutableArray<TodoCommentDescriptor> commentDescriptors, SyntacticDocument document, SyntaxTrivia trivia, List<TodoComment> todoList)
protected override void AppendTodoComments(IList<TodoCommentDescriptor> commentDescriptors, SyntacticDocument document, SyntaxTrivia trivia, List<TodoComment> todoList)
{
if (PreprocessorHasComment(trivia))
{
Expand Down
5 changes: 3 additions & 2 deletions src/Features/Core/Portable/AddImport/AddImportFixData.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// 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.Linq;
using Microsoft.CodeAnalysis.CodeActions;
Expand All @@ -19,7 +20,7 @@ internal class AddImportFixData
/// May be empty for fixes that don't need to add an import and only do something like
/// add a project/metadata reference.
/// </summary>
public ImmutableArray<TextChange> TextChanges { get; }
public IList<TextChange> TextChanges { get; }

/// <summary>
/// String to display in the lightbulb menu.
Expand All @@ -29,7 +30,7 @@ internal class AddImportFixData
/// <summary>
/// Tags that control what glyph is displayed in the lightbulb menu.
/// </summary>
public ImmutableArray<string> Tags { get; private set; }
public IList<string> Tags { get; private set; }

/// <summary>
/// The priority this item should have in the lightbulb list.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.AddImport
{
Expand Down Expand Up @@ -44,9 +45,9 @@ protected AddImportCodeAction(
FixData = fixData;

Title = fixData.Title;
Tags = fixData.Tags;
Tags = fixData.Tags.ToImmutableArrayOrEmpty();
Priority = fixData.Priority;
_textChanges = fixData.TextChanges;
_textChanges = fixData.TextChanges.ToImmutableArrayOrEmpty();
}

protected async Task<Document> GetUpdatedDocumentAsync(CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// 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.Linq;
using System.Threading;
Expand All @@ -19,12 +20,12 @@ private async Task<ImmutableArray<AddImportFixData>> GetFixesInRemoteProcessAsyn
string diagnosticId, bool placeSystemNamespaceFirst,
bool searchReferenceAssemblies, ImmutableArray<PackageSource> packageSources)
{
var result = await session.InvokeAsync<ImmutableArray<AddImportFixData>>(
var result = await session.InvokeAsync<IList<AddImportFixData>>(
nameof(IRemoteAddImportFeatureService.GetFixesAsync),
document.Id, span, diagnosticId, placeSystemNamespaceFirst,
searchReferenceAssemblies, packageSources).ConfigureAwait(false);

return result;
return result.AsImmutableOrEmpty();
}

/// <summary>
Expand Down Expand Up @@ -56,7 +57,7 @@ public Task UpdateContinuouslyAsync(string sourceName, string localSettingsDirec
throw new NotImplementedException();
}

public async Task<ImmutableArray<PackageWithTypeResult>> FindPackagesWithTypeAsync(
public async Task<IList<PackageWithTypeResult>> FindPackagesWithTypeAsync(
string source, string name, int arity)
{
var result = await _symbolSearchService.FindPackagesWithTypeAsync(
Expand All @@ -65,7 +66,7 @@ public async Task<ImmutableArray<PackageWithTypeResult>> FindPackagesWithTypeAsy
return result;
}

public async Task<ImmutableArray<PackageWithAssemblyResult>> FindPackagesWithAssemblyAsync(
public async Task<IList<PackageWithAssemblyResult>> FindPackagesWithAssemblyAsync(
string source, string name)
{
var result = await _symbolSearchService.FindPackagesWithAssemblyAsync(
Expand All @@ -74,7 +75,7 @@ public async Task<ImmutableArray<PackageWithAssemblyResult>> FindPackagesWithAss
return result;
}

public async Task<ImmutableArray<ReferenceAssemblyWithTypeResult>> FindReferenceAssembliesWithTypeAsync(
public async Task<IList<ReferenceAssemblyWithTypeResult>> FindReferenceAssembliesWithTypeAsync(
string name, int arity)
{
var result = await _symbolSearchService.FindReferenceAssembliesWithTypeAsync(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// 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.Generic;
using System.Collections.Immutable;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Packaging;
Expand All @@ -9,8 +10,8 @@ namespace Microsoft.CodeAnalysis.AddImport
{
internal interface IRemoteAddImportFeatureService
{
Task<ImmutableArray<AddImportFixData>> GetFixesAsync(
Task<IList<AddImportFixData>> GetFixesAsync(
DocumentId documentId, TextSpan span, string diagnosticId, bool placeSystemNamespaceFirst,
bool searchReferenceAssemblies, ImmutableArray<PackageSource> packageSources);
bool searchReferenceAssemblies, IList<PackageSource> packageSources);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Packaging;
using Microsoft.CodeAnalysis.SymbolSearch;
using Microsoft.CodeAnalysis.Utilities;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.AddImport
Expand Down Expand Up @@ -87,7 +88,7 @@ private async Task FindReferenceAssemblyTypeReferencesAsync(
cancellationToken.ThrowIfCancellationRequested();
var results = await _symbolSearchService.FindReferenceAssembliesWithTypeAsync(
name, arity, cancellationToken).ConfigureAwait(false);
if (results.IsDefault)
if (results == null)
{
return;
}
Expand Down Expand Up @@ -118,7 +119,7 @@ private async Task FindNugetTypeReferencesAsync(
cancellationToken.ThrowIfCancellationRequested();
var results = await _symbolSearchService.FindPackagesWithTypeAsync(
source.Name, name, arity, cancellationToken).ConfigureAwait(false);
if (results.IsDefault)
if (results == null)
{
return;
}
Expand Down Expand Up @@ -160,7 +161,7 @@ private async Task HandleReferenceAssemblyReferenceAsync(

var desiredName = GetDesiredName(isAttributeSearch, result.TypeName);
allReferences.Add(new AssemblyReference(
_owner, new SearchResult(desiredName, nameNode, result.ContainingNamespaceNames, weight), result));
_owner, new SearchResult(desiredName, nameNode, result.ContainingNamespaceNames.ToReadOnlyList(), weight), result));
}

private void HandleNugetReference(
Expand All @@ -174,7 +175,7 @@ private void HandleNugetReference(
{
var desiredName = GetDesiredName(isAttributeSearch, result.TypeName);
allReferences.Add(new PackageReference(_owner,
new SearchResult(desiredName, nameNode, result.ContainingNamespaceNames, weight),
new SearchResult(desiredName, nameNode, result.ContainingNamespaceNames.ToReadOnlyList(), weight),
source, result.PackageName, result.Version));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// 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.Generic;
using System.Collections.Immutable;
using System.Threading.Tasks;

namespace Microsoft.CodeAnalysis.DesignerAttributes
{
internal interface IRemoteDesignerAttributeService
{
Task<ImmutableArray<DesignerAttributeDocumentData>> ScanDesignerAttributesAsync(ProjectId projectId);
Task<IList<DesignerAttributeDocumentData>> ScanDesignerAttributesAsync(ProjectId projectId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public async Task<ImmutableArray<DocumentHighlights>> GetDocumentHighlightsAsync
return (succeeded: false, ImmutableArray<DocumentHighlights>.Empty);
}

var result = await session.InvokeAsync<ImmutableArray<SerializableDocumentHighlights>>(
var result = await session.InvokeAsync<IList<SerializableDocumentHighlights>>(
nameof(IRemoteDocumentHighlights.GetDocumentHighlightsAsync),
document.Id,
position,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// 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.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Threading.Tasks;
Expand All @@ -8,14 +9,14 @@ namespace Microsoft.CodeAnalysis.DocumentHighlighting
{
internal interface IRemoteDocumentHighlights
{
Task<ImmutableArray<SerializableDocumentHighlights>> GetDocumentHighlightsAsync(
Task<IList<SerializableDocumentHighlights>> GetDocumentHighlightsAsync(
DocumentId documentId, int position, DocumentId[] documentIdsToSearch);
}

internal struct SerializableDocumentHighlights
{
public DocumentId DocumentId;
public ImmutableArray<HighlightSpan> HighlightSpans;
public IList<HighlightSpan> HighlightSpans;

public DocumentHighlights Rehydrate(Solution solution)
=> new DocumentHighlights(solution.GetDocument(DocumentId), HighlightSpans.ToImmutableArray());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// 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.Generic;
using System.Collections.Immutable;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Remote;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.NavigateTo
{
Expand All @@ -12,7 +14,7 @@ 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<ImmutableArray<SerializableNavigateToSearchResult>>(
var serializableResults = await session.InvokeAsync<IList<SerializableNavigateToSearchResult>>(
nameof(IRemoteNavigateToSearchService.SearchDocumentAsync),
document.Id, searchPattern).ConfigureAwait(false);

Expand All @@ -22,7 +24,7 @@ private async Task<ImmutableArray<INavigateToSearchResult>> SearchDocumentInRemo
private async Task<ImmutableArray<INavigateToSearchResult>> SearchProjectInRemoteProcessAsync(
RemoteHostClient.Session session, Project project, string searchPattern, CancellationToken cancellationToken)
{
var serializableResults = await session.InvokeAsync<ImmutableArray<SerializableNavigateToSearchResult>>(
var serializableResults = await session.InvokeAsync<IList<SerializableNavigateToSearchResult>>(
nameof(IRemoteNavigateToSearchService.SearchProjectAsync),
project.Id, searchPattern).ConfigureAwait(false);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// 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.Generic;
using System.Collections.Immutable;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Remote;
Expand All @@ -8,7 +9,7 @@ namespace Microsoft.CodeAnalysis.NavigateTo
{
internal interface IRemoteNavigateToSearchService
{
Task<ImmutableArray<SerializableNavigateToSearchResult>> SearchDocumentAsync(DocumentId documentId, string searchPattern);
Task<ImmutableArray<SerializableNavigateToSearchResult>> SearchProjectAsync(ProjectId projectId, string searchPattern);
Task<IList<SerializableNavigateToSearchResult>> SearchDocumentAsync(DocumentId documentId, string searchPattern);
Task<IList<SerializableNavigateToSearchResult>> SearchProjectAsync(ProjectId projectId, string searchPattern);
}
}
Loading

0 comments on commit aca31f6

Please sign in to comment.