Skip to content
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 @@ -7,17 +7,35 @@
using System.Collections.Immutable;
using Microsoft.CodeAnalysis.PooledObjects;

namespace Roslyn.Utilities;
namespace Microsoft.CodeAnalysis;

internal static class ICollectionExtensions
{
public static void AddRange<T>(this ICollection<T> collection, IEnumerable<T>? values)
public static void RemoveRange<T>(this ICollection<T> collection, IEnumerable<T>? items)
{
if (collection == null)
if (items != null)
{
throw new ArgumentNullException(nameof(collection));
foreach (var item in items)
{
collection.Remove(item);
}
}
}

public static void AddIfNotNull<T>(this ICollection<T> collection, T? value) where T : struct
{
if (value != null)
collection.Add(value.Value);
}

public static void AddIfNotNull<T>(this ICollection<T> collection, T? value) where T : class
{
if (value != null)
collection.Add(value);
}

public static void AddRange<T>(this ICollection<T> collection, IEnumerable<T>? values)
{
if (values != null)
{
foreach (var item in values)
Expand All @@ -29,9 +47,6 @@ public static void AddRange<T>(this ICollection<T> collection, IEnumerable<T>? v

public static void AddRange<T>(this ICollection<T> collection, ArrayBuilder<T>? values)
{
if (collection == null)
throw new ArgumentNullException(nameof(collection));

if (values != null)
{
foreach (var item in values)
Expand All @@ -41,9 +56,6 @@ public static void AddRange<T>(this ICollection<T> collection, ArrayBuilder<T>?

public static void AddRange<T>(this ICollection<T> collection, HashSet<T>? values)
{
if (collection == null)
throw new ArgumentNullException(nameof(collection));

if (values != null)
{
foreach (var item in values)
Expand All @@ -53,9 +65,6 @@ public static void AddRange<T>(this ICollection<T> collection, HashSet<T>? value

public static void AddRange<TKey, TValue>(this ICollection<TKey> collection, Dictionary<TKey, TValue>.KeyCollection? keyCollection) where TKey : notnull
{
if (collection == null)
throw new ArgumentNullException(nameof(collection));

if (keyCollection != null)
{
foreach (var key in keyCollection)
Expand All @@ -65,11 +74,6 @@ public static void AddRange<TKey, TValue>(this ICollection<TKey> collection, Dic

public static void AddRange<T>(this ICollection<T> collection, ImmutableArray<T> values)
{
if (collection == null)
{
throw new ArgumentNullException(nameof(collection));
}

if (!values.IsDefault)
{
foreach (var item in values)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,19 @@ public static IEnumerable<T> WhereNotNull<T>(this IEnumerable<T?> source)
return source.Where((Func<T?, bool>)s_notNullTest)!;
}

public static ImmutableArray<T> WhereAsArray<T, TArg>(this IEnumerable<T> values, Func<T, TArg, bool> predicate, TArg arg)
{
var result = ArrayBuilder<T>.GetInstance();

foreach (var value in values)
{
if (predicate(value, arg))
result.Add(value);
}

return result.ToImmutableAndFree();
}

public static T[] AsArray<T>(this IEnumerable<T> source)
=> source as T[] ?? source.ToArray();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@
<Compile Include="$(MSBuildThisFileDirectory)OneOrMany.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TemporaryArray`1.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TemporaryArrayExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensions\EnumerableExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensions\IEnumerableExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensions\ImmutableArrayExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensions\ICollectionExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Specialized\SpecializedCollections.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Specialized\SpecializedCollections.Empty.Collection.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Specialized\SpecializedCollections.Empty.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ internal abstract class AbstractSuppressionBatchFixAllProvider : FixAllProvider
// Determine the set of documents to actually fix. We can also use this to update the progress bar with
// the amount of remaining work to perform. We'll update the progress bar as we compute each fix in
// AddDocumentFixesAsync.
var source = documentsAndDiagnosticsToFixMap.WhereAsArray(static (kvp, _) => !kvp.Value.IsDefaultOrEmpty, state: false);
var source = documentsAndDiagnosticsToFixMap.WhereAsArray(static (kvp, _) => !kvp.Value.IsDefaultOrEmpty, arg: false);
progressTracker.AddItems(source.Length);

return await ProducerConsumer<(Diagnostic diagnostic, CodeAction action)>.RunParallelAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Microsoft.CodeAnalysis.QuickInfo;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.ExternalAccess.Copilot.Internal.Analyzer;

Expand Down Expand Up @@ -167,7 +168,7 @@ public async Task<ImmutableArray<Diagnostic>> GetCachedDocumentDiagnosticsAsync(

protected virtual Task<ImmutableArray<Diagnostic>> GetDiagnosticsIntersectWithSpanAsync(Document document, IReadOnlyList<Diagnostic> diagnostics, TextSpan span, CancellationToken cancellationToken)
{
return Task.FromResult(diagnostics.WhereAsArray((diagnostic, _) => diagnostic.Location.SourceSpan.IntersectsWith(span), state: (object?)null));
return Task.FromResult(diagnostics.WhereAsArray(static (diagnostic, span) => diagnostic.Location.SourceSpan.IntersectsWith(span), span));
}

public async Task StartRefinementSessionAsync(Document oldDocument, Document newDocument, Diagnostic? primaryDiagnostic, CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.LanguageServer.Testing;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.LanguageService;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.FindSymbols.Finders;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Microsoft.CodeAnalysis.LanguageService;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.FindSymbols.Finders;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Microsoft.CodeAnalysis.LanguageService;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.FindSymbols.Finders;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.LanguageService;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.FindSymbols.Finders;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.LanguageService;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.FindSymbols.Finders;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,6 @@
<Compile Include="$(MSBuildThisFileDirectory)Utilities\EditDistance.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Utilities\IBidirectionalMap.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Utilities\ICacheEntry.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Utilities\ICollectionExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Utilities\IDictionaryExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Utilities\IGroupingExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Utilities\IntegerUtilities.cs" />
Expand Down Expand Up @@ -544,7 +543,6 @@
<Compile Include="$(MSBuildThisFileDirectory)Extensions\ControlFlowGraphExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensions\ControlFlowRegionExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensions\IAssemblySymbolExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensions\ICollectionExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensions\ICompilationExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensions\IMethodSymbolExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensions\INamedTypeSymbolExtensions.cs" />
Expand Down

This file was deleted.