Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

moved to List from ImmutableArray on json return type. #21395

Merged
merged 5 commits into from
Aug 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.PooledObjects;

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💭 I thought we already had this extension method. Maybe not accessible here though?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's between ImmutalbArray to ImmutableArray . this is IEnumerable to ImmutableArray

{
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,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.SymbolSearch
{
Expand Down Expand Up @@ -61,31 +63,31 @@ public RemoteUpdateEngine(
public async Task<ImmutableArray<PackageWithTypeResult>> FindPackagesWithTypeAsync(
string source, string name, int arity, CancellationToken cancellationToken)
{
var results = await _session.TryInvokeAsync<ImmutableArray<PackageWithTypeResult>>(
var results = await _session.TryInvokeAsync<IList<PackageWithTypeResult>>(
nameof(IRemoteSymbolSearchUpdateEngine.FindPackagesWithTypeAsync),
new object[] { source, name, arity }, cancellationToken).ConfigureAwait(false);

return results.NullToEmpty();
return results.ToImmutableArrayOrEmpty();
}

public async Task<ImmutableArray<PackageWithAssemblyResult>> FindPackagesWithAssemblyAsync(
string source, string assemblyName, CancellationToken cancellationToken)
{
var results = await _session.TryInvokeAsync<ImmutableArray<PackageWithAssemblyResult>>(
var results = await _session.TryInvokeAsync<IList<PackageWithAssemblyResult>>(
nameof(IRemoteSymbolSearchUpdateEngine.FindPackagesWithAssemblyAsync),
new object[] { source, assemblyName }, cancellationToken).ConfigureAwait(false);

return results.NullToEmpty();
return results.ToImmutableArrayOrEmpty();
}

public async Task<ImmutableArray<ReferenceAssemblyWithTypeResult>> FindReferenceAssembliesWithTypeAsync(
string name, int arity, CancellationToken cancellationToken)
{
var results = await _session.TryInvokeAsync<ImmutableArray<ReferenceAssemblyWithTypeResult>>(
var results = await _session.TryInvokeAsync<IList<ReferenceAssemblyWithTypeResult>>(
nameof(IRemoteSymbolSearchUpdateEngine.FindReferenceAssembliesWithTypeAsync),
new object[] { name, arity }, cancellationToken).ConfigureAwait(false);

return results.NullToEmpty();
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 @@ -28,7 +28,7 @@ public CSharpTodoCommentService(Workspace workspace) : base(workspace)
{
}

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
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public async Task<ImmutableArray<AddImportFixData>> GetFixesAsync(
if (RemoteSupportedLanguages.IsSupported(document.Project.Language))
{
var callbackTarget = new RemoteSymbolSearchService(symbolSearchService, cancellationToken);
var result = await document.Project.Solution.TryRunCodeAnalysisRemoteAsync<ImmutableArray<AddImportFixData>>(
var result = await document.Project.Solution.TryRunCodeAnalysisRemoteAsync<IList<AddImportFixData>>(
RemoteFeatureOptions.AddImportEnabled,
callbackTarget,
nameof(IRemoteAddImportFeatureService.GetFixesAsync),
Expand All @@ -78,9 +78,9 @@ public async Task<ImmutableArray<AddImportFixData>> GetFixesAsync(

var documentOptions = await document.GetOptionsAsync(cancellationToken).ConfigureAwait(false);

if (!result.IsDefault)
if (result != null)
{
return result;
return result.ToImmutableArray();
}
}

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.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -39,21 +40,21 @@ public Task UpdateContinuouslyAsync(string sourceName, string localSettingsDirec
throw new NotImplementedException();
}

public Task<ImmutableArray<PackageWithTypeResult>> FindPackagesWithTypeAsync(
public Task<IList<PackageWithTypeResult>> FindPackagesWithTypeAsync(
string source, string name, int arity, CancellationToken cancellationToken)
{
return _symbolSearchService.FindPackagesWithTypeAsync(
source, name, arity, cancellationToken);
}

public Task<ImmutableArray<PackageWithAssemblyResult>> FindPackagesWithAssemblyAsync(
public Task<IList<PackageWithAssemblyResult>> FindPackagesWithAssemblyAsync(
string source, string name, CancellationToken cancellationToken)
{
return _symbolSearchService.FindPackagesWithAssemblyAsync(
source, name, cancellationToken);
}

public Task<ImmutableArray<ReferenceAssemblyWithTypeResult>> FindReferenceAssembliesWithTypeAsync(
public Task<IList<ReferenceAssemblyWithTypeResult>> FindReferenceAssembliesWithTypeAsync(
string name, int arity, CancellationToken cancellationToken)
{
return _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;
using System.Threading.Tasks;
Expand All @@ -10,8 +11,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, CancellationToken cancellationToken);
bool searchReferenceAssemblies, IList<PackageSource> packageSources, CancellationToken cancellationToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.CodeAnalysis.Packaging;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.SymbolSearch;
using Microsoft.CodeAnalysis.Utilities;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.AddImport
Expand Down Expand Up @@ -90,7 +91,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 @@ -121,7 +122,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 @@ -163,7 +164,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 @@ -177,7 +178,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,13 +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.Immutable;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

namespace Microsoft.CodeAnalysis.DesignerAttributes
{
internal interface IRemoteDesignerAttributeService
{
Task<ImmutableArray<DesignerAttributeDocumentData>> ScanDesignerAttributesAsync(ProjectId projectId, CancellationToken cancellationToken);
Task<IList<DesignerAttributeDocumentData>> ScanDesignerAttributesAsync(ProjectId projectId, CancellationToken cancellationToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public async Task<ImmutableArray<DocumentHighlights>> GetDocumentHighlightsAsync
private async Task<(bool succeeded, ImmutableArray<DocumentHighlights> highlights)> GetDocumentHighlightsInRemoteProcessAsync(
Document document, int position, IImmutableSet<Document> documentsToSearch, CancellationToken cancellationToken)
{
var result = await document.Project.Solution.TryRunCodeAnalysisRemoteAsync<ImmutableArray<SerializableDocumentHighlights>>(
var result = await document.Project.Solution.TryRunCodeAnalysisRemoteAsync<IList<SerializableDocumentHighlights>>(
RemoteFeatureOptions.DocumentHighlightingEnabled,
nameof(IRemoteDocumentHighlights.GetDocumentHighlightsAsync),
new object[]
Expand All @@ -50,7 +50,7 @@ public async Task<ImmutableArray<DocumentHighlights>> GetDocumentHighlightsAsync
},
cancellationToken).ConfigureAwait(false);

if (result.IsDefault)
if (result == null)
{
return (succeeded: false, ImmutableArray<DocumentHighlights>.Empty);
}
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 All @@ -9,17 +10,17 @@ namespace Microsoft.CodeAnalysis.DocumentHighlighting
{
internal interface IRemoteDocumentHighlights
{
Task<ImmutableArray<SerializableDocumentHighlights>> GetDocumentHighlightsAsync(
Task<IList<SerializableDocumentHighlights>> GetDocumentHighlightsAsync(
DocumentId documentId, int position, DocumentId[] documentIdsToSearch, CancellationToken cancellationToken);
}

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);
=> new DocumentHighlights(solution.GetDocument(DocumentId), HighlightSpans.ToImmutableArray());

public static SerializableDocumentHighlights Dehydrate(DocumentHighlights highlights)
=> new SerializableDocumentHighlights
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// 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;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Experiments;
using Microsoft.CodeAnalysis.Remote;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.NavigateTo
{
Expand All @@ -17,23 +19,23 @@ private async Task<ImmutableArray<INavigateToSearchResult>> SearchDocumentInRemo
{
var solution = document.Project.Solution;

var serializableResults = await client.TryRunCodeAnalysisRemoteAsync<ImmutableArray<SerializableNavigateToSearchResult>>(
var serializableResults = await client.TryRunCodeAnalysisRemoteAsync<IList<SerializableNavigateToSearchResult>>(
solution, nameof(IRemoteNavigateToSearchService.SearchDocumentAsync),
new object[] { document.Id, searchPattern }, cancellationToken).ConfigureAwait(false);

return serializableResults.NullToEmpty().SelectAsArray(r => r.Rehydrate(solution));
return serializableResults.SelectAsArray(r => r.Rehydrate(solution));
}

private async Task<ImmutableArray<INavigateToSearchResult>> SearchProjectInRemoteProcessAsync(
RemoteHostClient client, Project project, string searchPattern, CancellationToken cancellationToken)
{
var solution = project.Solution;

var serializableResults = await client.TryRunCodeAnalysisRemoteAsync<ImmutableArray<SerializableNavigateToSearchResult>>(
var serializableResults = await client.TryRunCodeAnalysisRemoteAsync<IList<SerializableNavigateToSearchResult>>(
solution, nameof(IRemoteNavigateToSearchService.SearchProjectAsync),
new object[] { project.Id, searchPattern }, cancellationToken).ConfigureAwait(false);

return serializableResults.NullToEmpty().SelectAsArray(r => r.Rehydrate(solution));
return serializableResults.SelectAsArray(r => r.Rehydrate(solution));
}

private static async Task<RemoteHostClient> TryGetRemoteHostClientAsync(Project project, CancellationToken cancellationToken)
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;
using System.Threading.Tasks;
Expand All @@ -9,7 +10,7 @@ namespace Microsoft.CodeAnalysis.NavigateTo
{
internal interface IRemoteNavigateToSearchService
{
Task<ImmutableArray<SerializableNavigateToSearchResult>> SearchDocumentAsync(DocumentId documentId, string searchPattern, CancellationToken cancellationToken);
Task<ImmutableArray<SerializableNavigateToSearchResult>> SearchProjectAsync(ProjectId projectId, string searchPattern, CancellationToken cancellationToken);
Task<IList<SerializableNavigateToSearchResult>> SearchDocumentAsync(DocumentId documentId, string searchPattern, CancellationToken cancellationToken);
Task<IList<SerializableNavigateToSearchResult>> SearchProjectAsync(ProjectId projectId, string searchPattern, CancellationToken cancellationToken);
}
}
Loading