提交 9a91df60 编写于 作者: H Heejae Chang

moved every thing to IList

上级 29637c41
......@@ -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
{
......@@ -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)
......
......@@ -257,7 +257,7 @@ public async Task TestFailedInstallRollsBackFile()
installerServiceMock.Verify();
}
private Task<IReadOnlyList<PackageWithTypeResult>> CreateSearchResult(
private Task<IList<PackageWithTypeResult>> CreateSearchResult(
string packageName, string typeName, ImmutableArray<string> containingNamespaceNames)
{
return CreateSearchResult(new PackageWithTypeResult(
......@@ -265,8 +265,8 @@ public async Task TestFailedInstallRollsBackFile()
rank: 0, containingNamespaceNames: containingNamespaceNames));
}
private Task<IReadOnlyList<PackageWithTypeResult>> CreateSearchResult(params PackageWithTypeResult[] results)
=> Task.FromResult<IReadOnlyList<PackageWithTypeResult>>(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();
}
......
......@@ -87,19 +87,19 @@ public async Task AnalyzeSyntaxAsync(Document document, InvocationReasons reason
}
}
private async Task<IReadOnlyList<TodoComment>> GetTodoCommentsAsync(Document document, IReadOnlyList<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)
{
// no inproc support
return SpecializedCollections.EmptyReadOnlyList<TodoComment>();
return SpecializedCollections.EmptyList<TodoComment>();
}
return await service.GetTodoCommentsAsync(document, tokens, cancellationToken).ConfigureAwait(false);
}
private async Task<ImmutableArray<TodoItem>> CreateItemsAsync(Document document, IReadOnlyList<TodoComment> comments, CancellationToken cancellationToken)
private async Task<ImmutableArray<TodoItem>> CreateItemsAsync(Document document, IList<TodoComment> comments, CancellationToken cancellationToken)
{
var items = ImmutableArray.CreateBuilder<TodoItem>();
if (comments != null)
......
// 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
{
......@@ -61,31 +63,31 @@ private partial class RemoteUpdateEngine : ISymbolSearchUpdateEngine, ISymbolSea
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(
......
......@@ -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 IReadOnlyList(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,
......@@ -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 IReadOnlyList(Of PackageWithTypeResult))
Return Task.FromResult(Of IReadOnlyList(Of PackageWithTypeResult))(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)
......
......@@ -28,7 +28,7 @@ public CSharpTodoCommentService(Workspace workspace) : base(workspace)
{
}
protected override void AppendTodoComments(IReadOnlyList<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))
{
......
......@@ -61,7 +61,7 @@ protected AbstractAddImportFeatureService()
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),
......@@ -78,9 +78,9 @@ protected AbstractAddImportFeatureService()
var documentOptions = await document.GetOptionsAsync(cancellationToken).ConfigureAwait(false);
if (!result.IsDefault)
if (result != null)
{
return result;
return result.ToImmutableArray();
}
}
......
......@@ -40,21 +40,21 @@ public Task UpdateContinuouslyAsync(string sourceName, string localSettingsDirec
throw new NotImplementedException();
}
public Task<IReadOnlyList<PackageWithTypeResult>> FindPackagesWithTypeAsync(
public Task<IList<PackageWithTypeResult>> FindPackagesWithTypeAsync(
string source, string name, int arity, CancellationToken cancellationToken)
{
return _symbolSearchService.FindPackagesWithTypeAsync(
source, name, arity, cancellationToken);
}
public Task<IReadOnlyList<PackageWithAssemblyResult>> FindPackagesWithAssemblyAsync(
public Task<IList<PackageWithAssemblyResult>> FindPackagesWithAssemblyAsync(
string source, string name, CancellationToken cancellationToken)
{
return _symbolSearchService.FindPackagesWithAssemblyAsync(
source, name, cancellationToken);
}
public Task<IReadOnlyList<ReferenceAssemblyWithTypeResult>> FindReferenceAssembliesWithTypeAsync(
public Task<IList<ReferenceAssemblyWithTypeResult>> FindReferenceAssembliesWithTypeAsync(
string name, int arity, CancellationToken cancellationToken)
{
return _symbolSearchService.FindReferenceAssembliesWithTypeAsync(
......
......@@ -11,8 +11,8 @@ namespace Microsoft.CodeAnalysis.AddImport
{
internal interface IRemoteAddImportFeatureService
{
Task<IReadOnlyList<AddImportFixData>> GetFixesAsync(
Task<IList<AddImportFixData>> GetFixesAsync(
DocumentId documentId, TextSpan span, string diagnosticId, bool placeSystemNamespaceFirst,
bool searchReferenceAssemblies, IReadOnlyList<PackageSource> packageSources, CancellationToken cancellationToken);
bool searchReferenceAssemblies, IList<PackageSource> packageSources, CancellationToken cancellationToken);
}
}
......@@ -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
......@@ -163,7 +164,7 @@ private partial class SymbolReferenceFinder
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(
......@@ -177,7 +178,7 @@ private partial class SymbolReferenceFinder
{
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));
}
......
......@@ -8,6 +8,6 @@ namespace Microsoft.CodeAnalysis.DesignerAttributes
{
internal interface IRemoteDesignerAttributeService
{
Task<IReadOnlyList<DesignerAttributeDocumentData>> ScanDesignerAttributesAsync(ProjectId projectId, CancellationToken cancellationToken);
Task<IList<DesignerAttributeDocumentData>> ScanDesignerAttributesAsync(ProjectId projectId, CancellationToken cancellationToken);
}
}
......@@ -39,7 +39,7 @@ internal abstract partial class AbstractDocumentHighlightsService : IDocumentHig
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[]
......@@ -50,12 +50,12 @@ internal abstract partial class AbstractDocumentHighlightsService : IDocumentHig
},
cancellationToken).ConfigureAwait(false);
if (result.IsDefault)
if (result == null)
{
return (succeeded: false, ImmutableArray<DocumentHighlights>.Empty);
}
return (true, result.SelectAsArray(h => h.Rehydrate(document.Project.Solution)));
return (true, result.Select(h => h.Rehydrate(document.Project.Solution)).ToImmutableArray());
}
private async Task<ImmutableArray<DocumentHighlights>> GetDocumentHighlightsInCurrentProcessAsync(
......
......@@ -10,14 +10,14 @@ namespace Microsoft.CodeAnalysis.DocumentHighlighting
{
internal interface IRemoteDocumentHighlights
{
Task<IReadOnlyList<SerializableDocumentHighlights>> GetDocumentHighlightsAsync(
Task<IList<SerializableDocumentHighlights>> GetDocumentHighlightsAsync(
DocumentId documentId, int position, DocumentId[] documentIdsToSearch, CancellationToken cancellationToken);
}
internal struct SerializableDocumentHighlights
{
public DocumentId DocumentId;
public IReadOnlyList<HighlightSpan> HighlightSpans;
public IList<HighlightSpan> HighlightSpans;
public DocumentHighlights Rehydrate(Solution solution)
=> new DocumentHighlights(solution.GetDocument(DocumentId), HighlightSpans.ToImmutableArray());
......
// 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
{
......@@ -17,11 +19,11 @@ internal abstract partial class AbstractNavigateToSearchService
{
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(
......@@ -29,11 +31,11 @@ internal abstract partial class AbstractNavigateToSearchService
{
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)
......
......@@ -10,7 +10,7 @@ namespace Microsoft.CodeAnalysis.NavigateTo
{
internal interface IRemoteNavigateToSearchService
{
Task<IReadOnlyList<SerializableNavigateToSearchResult>> SearchDocumentAsync(DocumentId documentId, string searchPattern, CancellationToken cancellationToken);
Task<IReadOnlyList<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);
}
}
......@@ -36,9 +36,9 @@ protected AbstractTodoCommentService(Workspace workspace)
protected abstract string GetNormalizedText(string message);
protected abstract int GetCommentStartingIndex(string message);
protected abstract void AppendTodoComments(IReadOnlyList<TodoCommentDescriptor> commentDescriptors, SyntacticDocument document, SyntaxTrivia trivia, List<TodoComment> todoList);
protected abstract void AppendTodoComments(IList<TodoCommentDescriptor> commentDescriptors, SyntacticDocument document, SyntaxTrivia trivia, List<TodoComment> todoList);
public async Task<IReadOnlyList<TodoComment>> GetTodoCommentsAsync(Document document, IReadOnlyList<TodoCommentDescriptor> commentDescriptors, CancellationToken cancellationToken)
public async Task<IList<TodoComment>> GetTodoCommentsAsync(Document document, IList<TodoCommentDescriptor> commentDescriptors, CancellationToken cancellationToken)
{
// make sure given input is right one
Contract.ThrowIfFalse(_workspace == document.Project.Solution.Workspace);
......@@ -58,17 +58,17 @@ public async Task<IReadOnlyList<TodoComment>> GetTodoCommentsAsync(Document docu
return await GetTodoCommentsInCurrentProcessAsync(document, commentDescriptors, cancellationToken).ConfigureAwait(false);
}
private async Task<IReadOnlyList<TodoComment>> GetTodoCommentsInRemoteHostAsync(
RemoteHostClient client, Document document, IReadOnlyList<TodoCommentDescriptor> commentDescriptors, CancellationToken cancellationToken)
private async Task<IList<TodoComment>> GetTodoCommentsInRemoteHostAsync(
RemoteHostClient client, Document document, IList<TodoCommentDescriptor> commentDescriptors, CancellationToken cancellationToken)
{
var keepAliveSession = await TryGetKeepAliveSessionAsync(client, cancellationToken).ConfigureAwait(false);
var result = await keepAliveSession.TryInvokeAsync<IReadOnlyList<TodoComment>>(
var result = await keepAliveSession.TryInvokeAsync<IList<TodoComment>>(
nameof(IRemoteTodoCommentService.GetTodoCommentsAsync),
document.Project.Solution,
new object[] { document.Id, commentDescriptors }, cancellationToken).ConfigureAwait(false);
return result ?? SpecializedCollections.EmptyReadOnlyList<TodoComment>();
return result ?? SpecializedCollections.EmptyList<TodoComment>();
}
private async Task<KeepAliveSession> TryGetKeepAliveSessionAsync(RemoteHostClient client, CancellationToken cancellationToken)
......@@ -84,8 +84,8 @@ private async Task<KeepAliveSession> TryGetKeepAliveSessionAsync(RemoteHostClien
}
}
private async Task<IReadOnlyList<TodoComment>> GetTodoCommentsInCurrentProcessAsync(
Document document, IReadOnlyList<TodoCommentDescriptor> commentDescriptors, CancellationToken cancellationToken)
private async Task<IList<TodoComment>> GetTodoCommentsInCurrentProcessAsync(
Document document, IList<TodoCommentDescriptor> commentDescriptors, CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
......@@ -115,7 +115,7 @@ private bool ContainsComments(SyntaxTrivia trivia)
return PreprocessorHasComment(trivia) || IsSingleLineComment(trivia) || IsMultilineComment(trivia);
}
protected void AppendTodoCommentInfoFromSingleLine(IReadOnlyList<TodoCommentDescriptor> commentDescriptors, SyntacticDocument document, string message, int start, List<TodoComment> todoList)
protected void AppendTodoCommentInfoFromSingleLine(IList<TodoCommentDescriptor> commentDescriptors, SyntacticDocument document, string message, int start, List<TodoComment> todoList)
{
var index = GetCommentStartingIndex(message);
if (index >= message.Length)
......@@ -147,7 +147,7 @@ protected void AppendTodoCommentInfoFromSingleLine(IReadOnlyList<TodoCommentDesc
}
}
protected void ProcessMultilineComment(IReadOnlyList<TodoCommentDescriptor> commentDescriptors, SyntacticDocument document, SyntaxTrivia trivia, int postfixLength, List<TodoComment> todoList)
protected void ProcessMultilineComment(IList<TodoCommentDescriptor> commentDescriptors, SyntacticDocument document, SyntaxTrivia trivia, int postfixLength, List<TodoComment> todoList)
{
// this is okay since we know it is already alive
var text = document.Text;
......
......@@ -13,6 +13,6 @@ namespace Microsoft.CodeAnalysis.TodoComments
/// </summary>
internal interface IRemoteTodoCommentService
{
Task<IReadOnlyList<TodoComment>> GetTodoCommentsAsync(PinnedSolutionInfo solutionInfo, DocumentId documentId, IReadOnlyList<TodoCommentDescriptor> commentDescriptors, CancellationToken cancellationToken);
Task<IList<TodoComment>> GetTodoCommentsAsync(PinnedSolutionInfo solutionInfo, DocumentId documentId, IList<TodoCommentDescriptor> commentDescriptors, CancellationToken cancellationToken);
}
}
......@@ -42,6 +42,6 @@ public TodoComment(TodoCommentDescriptor descriptor, string message, int positio
internal interface ITodoCommentService : ILanguageService
{
Task<IReadOnlyList<TodoComment>> GetTodoCommentsAsync(Document document, IReadOnlyList<TodoCommentDescriptor> commentDescriptors, CancellationToken cancellationToken);
Task<IList<TodoComment>> GetTodoCommentsAsync(Document document, IList<TodoCommentDescriptor> commentDescriptors, CancellationToken cancellationToken);
}
}
......@@ -25,7 +25,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.TodoComments
MyBase.New(workspace)
End Sub
Protected Overrides Sub AppendTodoComments(commentDescriptors As IReadOnlyList(Of TodoCommentDescriptor), document As SyntacticDocument, trivia As SyntaxTrivia, todoList As List(Of TodoComment))
Protected Overrides Sub AppendTodoComments(commentDescriptors As IList(Of TodoCommentDescriptor), document As SyntacticDocument, trivia As SyntaxTrivia, todoList As List(Of TodoComment))
If PreprocessorHasComment(trivia) Then
Dim commentTrivia = trivia.GetStructure().DescendantTrivia().First(Function(t) t.RawKind = SyntaxKind.CommentTrivia)
......
......@@ -130,7 +130,7 @@ public async Task AnalyzeProjectAsync(Project project, bool semanticsChanged, In
return null;
}
var serializedResults = await session.InvokeAsync<IReadOnlyList<DesignerAttributeDocumentData>>(
var serializedResults = await session.InvokeAsync<IList<DesignerAttributeDocumentData>>(
nameof(IRemoteDesignerAttributeService.ScanDesignerAttributesAsync), new object[] { project.Id }, cancellationToken).ConfigureAwait(false);
var data = serializedResults.ToImmutableDictionary(kvp => kvp.FilePath);
......
......@@ -108,7 +108,7 @@ private async Task UpdateSourceInBackgroundAsync(string sourceName)
await engine.UpdateContinuouslyAsync(sourceName, _localSettingsDirectory).ConfigureAwait(false);
}
public async Task<IReadOnlyList<PackageWithTypeResult>> FindPackagesWithTypeAsync(
public async Task<IList<PackageWithTypeResult>> FindPackagesWithTypeAsync(
string source, string name, int arity, CancellationToken cancellationToken)
{
var engine = await GetEngine(cancellationToken).ConfigureAwait(false);
......@@ -118,7 +118,7 @@ private async Task UpdateSourceInBackgroundAsync(string sourceName)
return FilterAndOrderPackages(allPackagesWithType);
}
public async Task<IReadOnlyList<PackageWithAssemblyResult>> FindPackagesWithAssemblyAsync(
public async Task<IList<PackageWithAssemblyResult>> FindPackagesWithAssemblyAsync(
string source, string assemblyName, CancellationToken cancellationToken)
{
var engine = await GetEngine(cancellationToken).ConfigureAwait(false);
......@@ -170,7 +170,7 @@ private async Task UpdateSourceInBackgroundAsync(string sourceName)
return result.ToImmutableAndFree();
}
public async Task<IReadOnlyList<ReferenceAssemblyWithTypeResult>> FindReferenceAssembliesWithTypeAsync(
public async Task<IList<ReferenceAssemblyWithTypeResult>> FindReferenceAssembliesWithTypeAsync(
string name, int arity, CancellationToken cancellationToken)
{
var engine = await GetEngine(cancellationToken).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;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Threading;
......@@ -99,12 +100,12 @@ internal static partial class DeclarationFinder
return (false, ImmutableArray<SymbolAndProjectId>.Empty);
}
var result = await project.Solution.TryRunCodeAnalysisRemoteAsync<ImmutableArray<SerializableSymbolAndProjectId>>(
var result = await project.Solution.TryRunCodeAnalysisRemoteAsync<IList<SerializableSymbolAndProjectId>>(
RemoteFeatureOptions.SymbolFinderEnabled,
nameof(IRemoteSymbolFinder.FindAllDeclarationsWithNormalQueryAsync),
new object[] { project.Id, query.Name, query.Kind, criteria }, cancellationToken).ConfigureAwait(false);
if (result.IsDefault)
if (result == null)
{
return (false, ImmutableArray<SymbolAndProjectId>.Empty);
}
......@@ -116,9 +117,9 @@ internal static partial class DeclarationFinder
}
private static async Task<ImmutableArray<SymbolAndProjectId>> RehydrateAsync(
Solution solution, ImmutableArray<SerializableSymbolAndProjectId> array, CancellationToken cancellationToken)
Solution solution, IList<SerializableSymbolAndProjectId> array, CancellationToken cancellationToken)
{
var result = ArrayBuilder<SymbolAndProjectId>.GetInstance(array.Length);
var result = ArrayBuilder<SymbolAndProjectId>.GetInstance(array.Count);
foreach (var dehydrated in array)
{
......
// 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;
......@@ -115,12 +116,12 @@ internal static partial class DeclarationFinder
private static async Task<(bool, ImmutableArray<SymbolAndProjectId>)> TryFindSourceDeclarationsWithNormalQueryInRemoteProcessAsync(
Solution solution, string name, bool ignoreCase, SymbolFilter criteria, CancellationToken cancellationToken)
{
var result = await solution.TryRunCodeAnalysisRemoteAsync<ImmutableArray<SerializableSymbolAndProjectId>>(
var result = await solution.TryRunCodeAnalysisRemoteAsync<IList<SerializableSymbolAndProjectId>>(
RemoteFeatureOptions.SymbolFinderEnabled,
nameof(IRemoteSymbolFinder.FindSolutionSourceDeclarationsWithNormalQueryAsync),
new object[] { name, ignoreCase, criteria }, cancellationToken).ConfigureAwait(false);
if (result.IsDefault)
if (result == null)
{
return (false, ImmutableArray<SymbolAndProjectId>.Empty);
}
......@@ -139,12 +140,12 @@ internal static partial class DeclarationFinder
return (false, ImmutableArray<SymbolAndProjectId>.Empty);
}
var result = await project.Solution.TryRunCodeAnalysisRemoteAsync<ImmutableArray<SerializableSymbolAndProjectId>>(
var result = await project.Solution.TryRunCodeAnalysisRemoteAsync<IList<SerializableSymbolAndProjectId>>(
RemoteFeatureOptions.SymbolFinderEnabled,
nameof(IRemoteSymbolFinder.FindProjectSourceDeclarationsWithNormalQueryAsync),
new object[] { project.Id, name, ignoreCase, criteria }, cancellationToken).ConfigureAwait(false);
if (result.IsDefault)
if (result == null)
{
return (false, ImmutableArray<SymbolAndProjectId>.Empty);
}
......@@ -163,12 +164,12 @@ internal static partial class DeclarationFinder
return (false, ImmutableArray<SymbolAndProjectId>.Empty);
}
var result = await project.Solution.TryRunCodeAnalysisRemoteAsync<ImmutableArray<SerializableSymbolAndProjectId>>(
var result = await project.Solution.TryRunCodeAnalysisRemoteAsync<IList<SerializableSymbolAndProjectId>>(
RemoteFeatureOptions.SymbolFinderEnabled,
nameof(IRemoteSymbolFinder.FindProjectSourceDeclarationsWithPatternAsync),
new object[] { project.Id, pattern, criteria }, cancellationToken).ConfigureAwait(false);
if (result.IsDefault)
if (result == null)
{
return (false, ImmutableArray<SymbolAndProjectId>.Empty);
}
......
......@@ -14,16 +14,16 @@ internal interface IRemoteSymbolFinder
Task FindReferencesAsync(SerializableSymbolAndProjectId symbolAndProjectIdArg, DocumentId[] documentArgs, CancellationToken cancellationToken);
Task FindLiteralReferencesAsync(object value, TypeCode typeCode, CancellationToken cancellationToken);
Task<IReadOnlyList<SerializableSymbolAndProjectId>> FindAllDeclarationsWithNormalQueryAsync(
Task<IList<SerializableSymbolAndProjectId>> FindAllDeclarationsWithNormalQueryAsync(
ProjectId projectId, string name, SearchKind searchKind, SymbolFilter criteria, CancellationToken cancellationToken);
Task<IReadOnlyList<SerializableSymbolAndProjectId>> FindSolutionSourceDeclarationsWithNormalQueryAsync(
Task<IList<SerializableSymbolAndProjectId>> FindSolutionSourceDeclarationsWithNormalQueryAsync(
string name, bool ignoreCase, SymbolFilter criteria, CancellationToken cancellationToken);
Task<IReadOnlyList<SerializableSymbolAndProjectId>> FindProjectSourceDeclarationsWithNormalQueryAsync(
Task<IList<SerializableSymbolAndProjectId>> FindProjectSourceDeclarationsWithNormalQueryAsync(
ProjectId projectId, string name, bool ignoreCase, SymbolFilter criteria, CancellationToken cancellationToken);
Task<IReadOnlyList<SerializableSymbolAndProjectId>> FindProjectSourceDeclarationsWithPatternAsync(
Task<IList<SerializableSymbolAndProjectId>> FindProjectSourceDeclarationsWithPatternAsync(
ProjectId projectId, string pattern, SymbolFilter criteria, CancellationToken cancellationToken);
}
}
......@@ -11,8 +11,8 @@ internal interface IRemoteSymbolSearchUpdateEngine
{
Task UpdateContinuouslyAsync(string sourceName, string localSettingsDirectory);
Task<IReadOnlyList<PackageWithTypeResult>> FindPackagesWithTypeAsync(string source, string name, int arity, CancellationToken cancellationToken);
Task<IReadOnlyList<PackageWithAssemblyResult>> FindPackagesWithAssemblyAsync(string source, string name, CancellationToken cancellationToken);
Task<IReadOnlyList<ReferenceAssemblyWithTypeResult>> FindReferenceAssembliesWithTypeAsync(string name, int arity, CancellationToken cancellationToken);
Task<IList<PackageWithTypeResult>> FindPackagesWithTypeAsync(string source, string name, int arity, CancellationToken cancellationToken);
Task<IList<PackageWithAssemblyResult>> FindPackagesWithAssemblyAsync(string source, string name, CancellationToken cancellationToken);
Task<IList<ReferenceAssemblyWithTypeResult>> FindReferenceAssembliesWithTypeAsync(string name, int arity, CancellationToken cancellationToken);
}
}
......@@ -23,7 +23,7 @@ internal interface ISymbolSearchService : IWorkspaceService
/// Implementations should return results in order from best to worst (from their
/// perspective).
/// </summary>
Task<IReadOnlyList<PackageWithTypeResult>> FindPackagesWithTypeAsync(
Task<IList<PackageWithTypeResult>> FindPackagesWithTypeAsync(
string source, string name, int arity, CancellationToken cancellationToken);
/// <summary>
......@@ -34,7 +34,7 @@ internal interface ISymbolSearchService : IWorkspaceService
/// Implementations should return results in order from best to worst (from their
/// perspective).
/// </summary>
Task<IReadOnlyList<PackageWithAssemblyResult>> FindPackagesWithAssemblyAsync(
Task<IList<PackageWithAssemblyResult>> FindPackagesWithAssemblyAsync(
string source, string assemblyName, CancellationToken cancellationToken);
/// <summary>
......@@ -46,7 +46,7 @@ internal interface ISymbolSearchService : IWorkspaceService
/// Implementations should return results in order from best to worst (from their
/// perspective).
/// </summary>
Task<IReadOnlyList<ReferenceAssemblyWithTypeResult>> FindReferenceAssembliesWithTypeAsync(
Task<IList<ReferenceAssemblyWithTypeResult>> FindReferenceAssembliesWithTypeAsync(
string name, int arity, CancellationToken cancellationToken);
}
......@@ -64,7 +64,7 @@ protected PackageResult(string packageName, int rank)
internal class PackageWithTypeResult : PackageResult
{
public readonly IReadOnlyList<string> ContainingNamespaceNames;
public readonly IList<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)
IList<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 IList<string> ContainingNamespaceNames;
public readonly string AssemblyName;
public readonly string TypeName;
public ReferenceAssemblyWithTypeResult(
string assemblyName,
string typeName,
IReadOnlyList<string> containingNamespaceNames)
IList<string> containingNamespaceNames)
{
AssemblyName = assemblyName;
TypeName = typeName;
......@@ -136,22 +136,22 @@ internal class ReferenceAssemblyWithTypeResult
[ExportWorkspaceService(typeof(ISymbolSearchService)), Shared]
internal class DefaultSymbolSearchService : ISymbolSearchService
{
public Task<IReadOnlyList<PackageWithTypeResult>> FindPackagesWithTypeAsync(
public Task<IList<PackageWithTypeResult>> FindPackagesWithTypeAsync(
string source, string name, int arity, CancellationToken cancellationToken)
{
return SpecializedTasks.EmptyReadOnlyList<PackageWithTypeResult>();
return SpecializedTasks.EmptyList<PackageWithTypeResult>();
}
public Task<IReadOnlyList<PackageWithAssemblyResult>> FindPackagesWithAssemblyAsync(
public Task<IList<PackageWithAssemblyResult>> FindPackagesWithAssemblyAsync(
string source, string assemblyName, CancellationToken cancellationToken)
{
return SpecializedTasks.EmptyReadOnlyList<PackageWithAssemblyResult>();
return SpecializedTasks.EmptyList<PackageWithAssemblyResult>();
}
public Task<IReadOnlyList<ReferenceAssemblyWithTypeResult>> FindReferenceAssembliesWithTypeAsync(
public Task<IList<ReferenceAssemblyWithTypeResult>> FindReferenceAssembliesWithTypeAsync(
string name, int arity, CancellationToken cancellationToken)
{
return SpecializedTasks.EmptyReadOnlyList<ReferenceAssemblyWithTypeResult>();
return SpecializedTasks.EmptyList<ReferenceAssemblyWithTypeResult>();
}
}
}
using System.Collections.Generic;
using System.Collections;
using System.Collections.Generic;
namespace Microsoft.CodeAnalysis.Utilities
{
internal static class IReadOnlyListExtensions
{
public static IReadOnlyList<T> ToReadOnlyList<T>(this IList<T> list)
{
if (list is IReadOnlyList<T> readOnlyList)
{
return readOnlyList;
}
return new ReadOnlyList<T>(list);
}
public static T Last<T>(this IReadOnlyList<T> list)
{
return list[list.Count - 1];
}
private class ReadOnlyList<T> : IReadOnlyList<T>
{
private readonly IList<T> _list;
public ReadOnlyList(IList<T> list)
{
_list = list;
}
public T this[int index] => _list[index];
public int Count => _list.Count;
public IEnumerator<T> GetEnumerator() => _list.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => _list.GetEnumerator();
}
}
}
......@@ -14,9 +14,9 @@ namespace Microsoft.CodeAnalysis.Remote
{
internal partial class CodeAnalysisService : IRemoteAddImportFeatureService
{
public async Task<IReadOnlyList<AddImportFixData>> GetFixesAsync(
public async Task<IList<AddImportFixData>> GetFixesAsync(
DocumentId documentId, TextSpan span, string diagnosticId, bool placeSystemNamespaceFirst,
bool searchReferenceAssemblies, IReadOnlyList<PackageSource> packageSources, CancellationToken cancellationToken)
bool searchReferenceAssemblies, IList<PackageSource> packageSources, CancellationToken cancellationToken)
{
using (UserOperationBooster.Boost())
{
......@@ -55,28 +55,28 @@ public SymbolSearchService(CodeAnalysisService codeAnalysisService)
this.codeAnalysisService = codeAnalysisService;
}
public async Task<IReadOnlyList<PackageWithTypeResult>> FindPackagesWithTypeAsync(
public async Task<IList<PackageWithTypeResult>> FindPackagesWithTypeAsync(
string source, string name, int arity, CancellationToken cancellationToken)
{
var result = await codeAnalysisService.Rpc.InvokeAsync<IReadOnlyList<PackageWithTypeResult>>(
var result = await codeAnalysisService.Rpc.InvokeAsync<IList<PackageWithTypeResult>>(
nameof(FindPackagesWithTypeAsync), source, name, arity).ConfigureAwait(false);
return result;
}
public async Task<IReadOnlyList<PackageWithAssemblyResult>> FindPackagesWithAssemblyAsync(
public async Task<IList<PackageWithAssemblyResult>> FindPackagesWithAssemblyAsync(
string source, string assemblyName, CancellationToken cancellationToken)
{
var result = await codeAnalysisService.Rpc.InvokeAsync<IReadOnlyList<PackageWithAssemblyResult>>(
var result = await codeAnalysisService.Rpc.InvokeAsync<IList<PackageWithAssemblyResult>>(
nameof(FindPackagesWithAssemblyAsync), source, assemblyName).ConfigureAwait(false);
return result;
}
public async Task<IReadOnlyList<ReferenceAssemblyWithTypeResult>> FindReferenceAssembliesWithTypeAsync(
public async Task<IList<ReferenceAssemblyWithTypeResult>> FindReferenceAssembliesWithTypeAsync(
string name, int arity, CancellationToken cancellationToken)
{
var result = await codeAnalysisService.Rpc.InvokeAsync<IReadOnlyList<ReferenceAssemblyWithTypeResult>>(
var result = await codeAnalysisService.Rpc.InvokeAsync<IList<ReferenceAssemblyWithTypeResult>>(
nameof(FindReferenceAssembliesWithTypeAsync), name, arity).ConfigureAwait(false);
return result;
......
......@@ -19,7 +19,7 @@ internal partial class CodeAnalysisService : IRemoteDesignerAttributeService
///
/// This will be called by ServiceHub/JsonRpc framework
/// </summary>
public async Task<IReadOnlyList<DesignerAttributeDocumentData>> ScanDesignerAttributesAsync(ProjectId projectId, CancellationToken cancellationToken)
public async Task<IList<DesignerAttributeDocumentData>> ScanDesignerAttributesAsync(ProjectId projectId, CancellationToken cancellationToken)
{
using (RoslynLogger.LogBlock(FunctionId.CodeAnalysisService_GetDesignerAttributesAsync, projectId.DebugName, cancellationToken))
{
......@@ -31,7 +31,7 @@ public async Task<IReadOnlyList<DesignerAttributeDocumentData>> ScanDesignerAttr
if (data.Count == 0)
{
return SpecializedCollections.EmptyReadOnlyList<DesignerAttributeDocumentData>();
return SpecializedCollections.EmptyList<DesignerAttributeDocumentData>();
}
return data.Values.ToList();
......
......@@ -14,7 +14,7 @@ namespace Microsoft.CodeAnalysis.Remote
// root level service for all Roslyn services
internal partial class CodeAnalysisService : IRemoteDocumentHighlights
{
public async Task<IReadOnlyList<SerializableDocumentHighlights>> GetDocumentHighlightsAsync(
public async Task<IList<SerializableDocumentHighlights>> GetDocumentHighlightsAsync(
DocumentId documentId, int position, DocumentId[] documentIdsToSearch, CancellationToken cancellationToken)
{
// NOTE: In projection scenarios, we might get a set of documents to search
......
......@@ -10,7 +10,7 @@ namespace Microsoft.CodeAnalysis.Remote
{
internal partial class CodeAnalysisService : IRemoteNavigateToSearchService
{
public async Task<IReadOnlyList<SerializableNavigateToSearchResult>> SearchDocumentAsync(
public async Task<IList<SerializableNavigateToSearchResult>> SearchDocumentAsync(
DocumentId documentId, string searchPattern, CancellationToken cancellationToken)
{
using (UserOperationBooster.Boost())
......@@ -25,7 +25,7 @@ internal partial class CodeAnalysisService : IRemoteNavigateToSearchService
}
}
public async Task<IReadOnlyList<SerializableNavigateToSearchResult>> SearchProjectAsync(
public async Task<IList<SerializableNavigateToSearchResult>> SearchProjectAsync(
ProjectId projectId, string searchPattern, CancellationToken cancellationToken)
{
using (UserOperationBooster.Boost())
......
......@@ -60,7 +60,7 @@ public async Task FindLiteralReferencesAsync(object value, TypeCode typeCode, Ca
}
}
public async Task<IReadOnlyList<SerializableSymbolAndProjectId>> FindAllDeclarationsWithNormalQueryAsync(
public async Task<IList<SerializableSymbolAndProjectId>> FindAllDeclarationsWithNormalQueryAsync(
ProjectId projectId, string name, SearchKind searchKind, SymbolFilter criteria, CancellationToken cancellationToken)
{
using (UserOperationBooster.Boost())
......@@ -78,7 +78,7 @@ public async Task FindLiteralReferencesAsync(object value, TypeCode typeCode, Ca
}
}
public async Task<IReadOnlyList<SerializableSymbolAndProjectId>> FindSolutionSourceDeclarationsWithNormalQueryAsync(
public async Task<IList<SerializableSymbolAndProjectId>> FindSolutionSourceDeclarationsWithNormalQueryAsync(
string name, bool ignoreCase, SymbolFilter criteria, CancellationToken cancellationToken)
{
using (UserOperationBooster.Boost())
......@@ -91,7 +91,7 @@ public async Task FindLiteralReferencesAsync(object value, TypeCode typeCode, Ca
}
}
public async Task<IReadOnlyList<SerializableSymbolAndProjectId>> FindProjectSourceDeclarationsWithNormalQueryAsync(
public async Task<IList<SerializableSymbolAndProjectId>> FindProjectSourceDeclarationsWithNormalQueryAsync(
ProjectId projectId, string name, bool ignoreCase, SymbolFilter criteria, CancellationToken cancellationToken)
{
using (UserOperationBooster.Boost())
......@@ -106,7 +106,7 @@ public async Task FindLiteralReferencesAsync(object value, TypeCode typeCode, Ca
}
}
public async Task<IReadOnlyList<SerializableSymbolAndProjectId>> FindProjectSourceDeclarationsWithPatternAsync(
public async Task<IList<SerializableSymbolAndProjectId>> FindProjectSourceDeclarationsWithPatternAsync(
ProjectId projectId, string pattern, SymbolFilter criteria, CancellationToken cancellationToken)
{
using (UserOperationBooster.Boost())
......
......@@ -23,7 +23,7 @@ internal partial class CodeAnalysisService : IRemoteTodoCommentService
///
/// This will be called by ServiceHub/JsonRpc framework
/// </summary>
public async Task<IReadOnlyList<TodoComment>> GetTodoCommentsAsync(PinnedSolutionInfo solutionInfo, DocumentId documentId, IReadOnlyList<TodoCommentDescriptor> tokens, CancellationToken cancellationToken)
public async Task<IList<TodoComment>> GetTodoCommentsAsync(PinnedSolutionInfo solutionInfo, DocumentId documentId, IList<TodoCommentDescriptor> tokens, CancellationToken cancellationToken)
{
using (RoslynLogger.LogBlock(FunctionId.CodeAnalysisService_GetTodoCommentsAsync, documentId.ProjectId.DebugName, cancellationToken))
{
......@@ -37,7 +37,7 @@ public async Task<IReadOnlyList<TodoComment>> GetTodoCommentsAsync(PinnedSolutio
return await service.GetTodoCommentsAsync(document, tokens, cancellationToken).ConfigureAwait(false);
}
return SpecializedCollections.EmptyReadOnlyList<TodoComment>();
return SpecializedCollections.EmptyList<TodoComment>();
}
}
}
......
......@@ -29,7 +29,7 @@ public Task UpdateContinuouslyAsync(string sourceName, string localSettingsDirec
return _updateEngine.UpdateContinuouslyAsync(sourceName, localSettingsDirectory);
}
public async Task<IReadOnlyList<PackageWithTypeResult>> FindPackagesWithTypeAsync(string source, string name, int arity, CancellationToken cancellationToken)
public async Task<IList<PackageWithTypeResult>> FindPackagesWithTypeAsync(string source, string name, int arity, CancellationToken cancellationToken)
{
var results = await _updateEngine.FindPackagesWithTypeAsync(
source, name, arity, cancellationToken).ConfigureAwait(false);
......@@ -37,7 +37,7 @@ public async Task<IReadOnlyList<PackageWithTypeResult>> FindPackagesWithTypeAsyn
return results;
}
public async Task<IReadOnlyList<PackageWithAssemblyResult>> FindPackagesWithAssemblyAsync(string source, string assemblyName, CancellationToken cancellationToken)
public async Task<IList<PackageWithAssemblyResult>> FindPackagesWithAssemblyAsync(string source, string assemblyName, CancellationToken cancellationToken)
{
var results = await _updateEngine.FindPackagesWithAssemblyAsync(
source, assemblyName, cancellationToken).ConfigureAwait(false);
......@@ -45,7 +45,7 @@ public async Task<IReadOnlyList<PackageWithAssemblyResult>> FindPackagesWithAsse
return results;
}
public async Task<IReadOnlyList<ReferenceAssemblyWithTypeResult>> FindReferenceAssembliesWithTypeAsync(string name, int arity, CancellationToken cancellationToken)
public async Task<IList<ReferenceAssemblyWithTypeResult>> FindReferenceAssembliesWithTypeAsync(string name, int arity, CancellationToken cancellationToken)
{
var results = await _updateEngine.FindReferenceAssembliesWithTypeAsync(
name, arity, cancellationToken).ConfigureAwait(false);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册