From 5b1cefb97476732a3962115e7eda2b1e6a8acfbf Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:06:03 -0700 Subject: [PATCH 01/57] use collection expr --- .../CSharpUpdateExpressionSyntaxHelper.cs | 2 +- src/Analyzers/Core/Analyzers/Formatting/FormatterHelper.cs | 6 +++--- .../PopulateSwitch/PopulateSwitchExpressionHelpers.cs | 2 +- .../CodeFixes/NamingStyle/NamingStyleCodeFixProvider.cs | 5 +---- .../Core/InlineHints/InlineHintsDataTaggerProvider.cs | 2 +- src/EditorFeatures/Core/InlineRename/InlineRenameSession.cs | 2 +- ...RenameTrackingTaggerProvider.RenameTrackingCodeAction.cs | 3 +-- .../Core/Shared/Extensions/ITextSnapshotExtensions.cs | 2 +- .../Tagging/AbstractAsynchronousTaggerProvider.TagSource.cs | 4 ++-- .../Core/Tagging/AbstractAsynchronousTaggerProvider.cs | 2 +- 10 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/Analyzers/CSharp/Analyzers/UseCollectionInitializer/CSharpUpdateExpressionSyntaxHelper.cs b/src/Analyzers/CSharp/Analyzers/UseCollectionInitializer/CSharpUpdateExpressionSyntaxHelper.cs index 79de454fef8ff..96b629b7390a8 100644 --- a/src/Analyzers/CSharp/Analyzers/UseCollectionInitializer/CSharpUpdateExpressionSyntaxHelper.cs +++ b/src/Analyzers/CSharp/Analyzers/UseCollectionInitializer/CSharpUpdateExpressionSyntaxHelper.cs @@ -40,5 +40,5 @@ public void GetPartsOfIfStatement( } private static IEnumerable ExtractEmbeddedStatements(StatementSyntax embeddedStatement) - => embeddedStatement is BlockSyntax block ? block.Statements : SpecializedCollections.SingletonEnumerable(embeddedStatement); + => embeddedStatement is BlockSyntax block ? block.Statements : [embeddedStatement]; } diff --git a/src/Analyzers/Core/Analyzers/Formatting/FormatterHelper.cs b/src/Analyzers/Core/Analyzers/Formatting/FormatterHelper.cs index 7b4a7640b7dde..cc91eb9d9ddc7 100644 --- a/src/Analyzers/Core/Analyzers/Formatting/FormatterHelper.cs +++ b/src/Analyzers/Core/Analyzers/Formatting/FormatterHelper.cs @@ -30,10 +30,10 @@ internal static IEnumerable GetDefaultFormattingRules(IS /// An optional cancellation token. /// The formatted tree's root node. public static SyntaxNode Format(SyntaxNode node, ISyntaxFormatting syntaxFormattingService, SyntaxFormattingOptions options, CancellationToken cancellationToken) - => Format(node, SpecializedCollections.SingletonEnumerable(node.FullSpan), syntaxFormattingService, options, rules: null, cancellationToken: cancellationToken); + => Format(node, [node.FullSpan], syntaxFormattingService, options, rules: null, cancellationToken: cancellationToken); public static SyntaxNode Format(SyntaxNode node, TextSpan spanToFormat, ISyntaxFormatting syntaxFormattingService, SyntaxFormattingOptions options, CancellationToken cancellationToken) - => Format(node, SpecializedCollections.SingletonEnumerable(spanToFormat), syntaxFormattingService, options, rules: null, cancellationToken: cancellationToken); + => Format(node, [spanToFormat], syntaxFormattingService, options, rules: null, cancellationToken: cancellationToken); /// /// Formats the whitespace of a syntax tree. @@ -63,5 +63,5 @@ internal static IFormattingResult GetFormattingResult(SyntaxNode node, IEnumerab /// An optional cancellation token. /// The changes necessary to format the tree. public static IList GetFormattedTextChanges(SyntaxNode node, ISyntaxFormatting syntaxFormattingService, SyntaxFormattingOptions options, CancellationToken cancellationToken) - => GetFormattedTextChanges(node, SpecializedCollections.SingletonEnumerable(node.FullSpan), syntaxFormattingService, options, rules: null, cancellationToken: cancellationToken); + => GetFormattedTextChanges(node, [node.FullSpan], syntaxFormattingService, options, rules: null, cancellationToken: cancellationToken); } diff --git a/src/Analyzers/Core/Analyzers/PopulateSwitch/PopulateSwitchExpressionHelpers.cs b/src/Analyzers/Core/Analyzers/PopulateSwitch/PopulateSwitchExpressionHelpers.cs index 0404194fec0ce..2e4336069220e 100644 --- a/src/Analyzers/Core/Analyzers/PopulateSwitch/PopulateSwitchExpressionHelpers.cs +++ b/src/Analyzers/Core/Analyzers/PopulateSwitch/PopulateSwitchExpressionHelpers.cs @@ -35,7 +35,7 @@ public static ICollection GetMissingEnumMembers(ISwitchExpressionOperat } } - return SpecializedCollections.EmptyCollection(); + return []; } public static bool HasNullSwitchArm(ISwitchExpressionOperation operation) diff --git a/src/Analyzers/Core/CodeFixes/NamingStyle/NamingStyleCodeFixProvider.cs b/src/Analyzers/Core/CodeFixes/NamingStyle/NamingStyleCodeFixProvider.cs index 87f345e571b6b..bdf383bd56b35 100644 --- a/src/Analyzers/Core/CodeFixes/NamingStyle/NamingStyleCodeFixProvider.cs +++ b/src/Analyzers/Core/CodeFixes/NamingStyle/NamingStyleCodeFixProvider.cs @@ -148,10 +148,7 @@ public FixNameCodeAction( } protected override async Task> ComputePreviewOperationsAsync(CancellationToken cancellationToken) - { - return SpecializedCollections.SingletonEnumerable( - new ApplyChangesOperation(await _createChangedSolutionAsync(cancellationToken).ConfigureAwait(false))); - } + => [new ApplyChangesOperation(await _createChangedSolutionAsync(cancellationToken).ConfigureAwait(false))]; protected override async Task> ComputeOperationsAsync(IProgress progress, CancellationToken cancellationToken) { diff --git a/src/EditorFeatures/Core/InlineHints/InlineHintsDataTaggerProvider.cs b/src/EditorFeatures/Core/InlineHints/InlineHintsDataTaggerProvider.cs index 699a25166b41c..16c437592808a 100644 --- a/src/EditorFeatures/Core/InlineHints/InlineHintsDataTaggerProvider.cs +++ b/src/EditorFeatures/Core/InlineHints/InlineHintsDataTaggerProvider.cs @@ -91,7 +91,7 @@ protected override IEnumerable GetSpansToTag(ITextView? textView, return base.GetSpansToTag(textView, subjectBuffer); } - return SpecializedCollections.SingletonEnumerable(visibleSpanOpt.Value); + return [visibleSpanOpt.Value]; } protected override async Task ProduceTagsAsync( diff --git a/src/EditorFeatures/Core/InlineRename/InlineRenameSession.cs b/src/EditorFeatures/Core/InlineRename/InlineRenameSession.cs index 70d17e84c9b60..ba6f8bddefdd6 100644 --- a/src/EditorFeatures/Core/InlineRename/InlineRenameSession.cs +++ b/src/EditorFeatures/Core/InlineRename/InlineRenameSession.cs @@ -247,7 +247,7 @@ private void InitializeOpenBuffers(SnapshotSpan triggerSpan) } this.UndoManager.CreateInitialState(this.ReplacementText, _triggerView.Selection, new SnapshotSpan(triggerSpan.Snapshot, startingSpan)); - _openTextBuffers[triggerSpan.Snapshot.TextBuffer].SetReferenceSpans(SpecializedCollections.SingletonEnumerable(startingSpan.ToTextSpan())); + _openTextBuffers[triggerSpan.Snapshot.TextBuffer].SetReferenceSpans([startingSpan.ToTextSpan()]); UpdateReferenceLocationsTask(); diff --git a/src/EditorFeatures/Core/RenameTracking/RenameTrackingTaggerProvider.RenameTrackingCodeAction.cs b/src/EditorFeatures/Core/RenameTracking/RenameTrackingTaggerProvider.RenameTrackingCodeAction.cs index 2d1aecd212cff..f43e0a530435c 100644 --- a/src/EditorFeatures/Core/RenameTracking/RenameTrackingTaggerProvider.RenameTrackingCodeAction.cs +++ b/src/EditorFeatures/Core/RenameTracking/RenameTrackingTaggerProvider.RenameTrackingCodeAction.cs @@ -81,8 +81,7 @@ protected override async Task> ComputePreviewOp var solutionSet = await _renameTrackingCommitter.RenameSymbolAsync(cancellationToken).ConfigureAwait(false); - return SpecializedCollections.SingletonEnumerable( - (CodeActionOperation)new ApplyChangesOperation(solutionSet.RenamedSolution)); + return [new ApplyChangesOperation(solutionSet.RenamedSolution)]; } private bool TryInitializeRenameTrackingCommitter(CancellationToken cancellationToken) diff --git a/src/EditorFeatures/Core/Shared/Extensions/ITextSnapshotExtensions.cs b/src/EditorFeatures/Core/Shared/Extensions/ITextSnapshotExtensions.cs index 1bad744ea46fc..5f77ff87d1177 100644 --- a/src/EditorFeatures/Core/Shared/Extensions/ITextSnapshotExtensions.cs +++ b/src/EditorFeatures/Core/Shared/Extensions/ITextSnapshotExtensions.cs @@ -44,7 +44,7 @@ public static void FormatAndApplyToBuffer( var formatter = document.GetRequiredLanguageService(); var options = textBuffer.GetSyntaxFormattingOptions(editorOptionsService, document.Project.Services, explicitFormat: false); - var result = formatter.GetFormattingResult(documentSyntax.Root, SpecializedCollections.SingletonEnumerable(span), options, rules, cancellationToken); + var result = formatter.GetFormattingResult(documentSyntax.Root, [span], options, rules, cancellationToken); var changes = result.GetTextChanges(cancellationToken); using (Logger.LogBlock(FunctionId.Formatting_ApplyResultToBuffer, cancellationToken)) diff --git a/src/EditorFeatures/Core/Tagging/AbstractAsynchronousTaggerProvider.TagSource.cs b/src/EditorFeatures/Core/Tagging/AbstractAsynchronousTaggerProvider.TagSource.cs index 7f19fe9ea29a5..9265be8baa8f4 100644 --- a/src/EditorFeatures/Core/Tagging/AbstractAsynchronousTaggerProvider.TagSource.cs +++ b/src/EditorFeatures/Core/Tagging/AbstractAsynchronousTaggerProvider.TagSource.cs @@ -390,8 +390,8 @@ private void RaiseTagsChanged(ITextBuffer buffer, DiffResult difference) return; } - OnTagsChangedForBuffer(SpecializedCollections.SingletonCollection( - new KeyValuePair(buffer, difference)), + OnTagsChangedForBuffer( + [new KeyValuePair(buffer, difference)], highPriority: false); } } diff --git a/src/EditorFeatures/Core/Tagging/AbstractAsynchronousTaggerProvider.cs b/src/EditorFeatures/Core/Tagging/AbstractAsynchronousTaggerProvider.cs index 1f37b5a69b2a2..08b0c89e4d93a 100644 --- a/src/EditorFeatures/Core/Tagging/AbstractAsynchronousTaggerProvider.cs +++ b/src/EditorFeatures/Core/Tagging/AbstractAsynchronousTaggerProvider.cs @@ -222,7 +222,7 @@ private void StoreTagSource(ITextView? textView, ITextBuffer subjectBuffer, TagS protected virtual IEnumerable GetSpansToTag(ITextView? textView, ITextBuffer subjectBuffer) { // For a standard tagger, the spans to tag is the span of the entire snapshot. - return SpecializedCollections.SingletonEnumerable(subjectBuffer.CurrentSnapshot.GetFullSpan()); + return [subjectBuffer.CurrentSnapshot.GetFullSpan()]; } /// From b1ad3a977c588ac6ac5e1b02312bbd17b73108c3 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:07:12 -0700 Subject: [PATCH 02/57] use collection expr --- .../Core.Wpf/Interactive/InteractiveWindowResetCommand.cs | 2 +- .../NavigableSymbolService.NavigableSymbol.cs | 2 +- src/EditorFeatures/Core.Wpf/Peek/DefinitionPeekableItem.cs | 2 +- src/EditorFeatures/Core.Wpf/Peek/ExternalFilePeekableItem.cs | 4 +--- ...bstractAsynchronousTaggerProvider.TagSource_ProduceTags.cs | 2 +- ...nousViewportTaggerProvider.SingleViewportTaggerProvider.cs | 2 +- 6 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/EditorFeatures/Core.Wpf/Interactive/InteractiveWindowResetCommand.cs b/src/EditorFeatures/Core.Wpf/Interactive/InteractiveWindowResetCommand.cs index 69825d6096027..f83ca947cb379 100644 --- a/src/EditorFeatures/Core.Wpf/Interactive/InteractiveWindowResetCommand.cs +++ b/src/EditorFeatures/Core.Wpf/Interactive/InteractiveWindowResetCommand.cs @@ -51,7 +51,7 @@ public IEnumerable DetailedDescription => null; public IEnumerable Names - => SpecializedCollections.SingletonEnumerable(CommandName); + => [CommandName]; public string CommandLine => "[" + NoConfigParameterName + "] [" + PlatformNames + "]"; diff --git a/src/EditorFeatures/Core.Wpf/NavigableSymbols/NavigableSymbolService.NavigableSymbol.cs b/src/EditorFeatures/Core.Wpf/NavigableSymbols/NavigableSymbolService.NavigableSymbol.cs index 25df413e8b7e0..5851e0d25fb14 100644 --- a/src/EditorFeatures/Core.Wpf/NavigableSymbols/NavigableSymbolService.NavigableSymbol.cs +++ b/src/EditorFeatures/Core.Wpf/NavigableSymbols/NavigableSymbolService.NavigableSymbol.cs @@ -42,7 +42,7 @@ public NavigableSymbol( public SnapshotSpan SymbolSpan { get; } public IEnumerable Relationships - => SpecializedCollections.SingletonEnumerable(PredefinedNavigableRelationships.Definition); + => [PredefinedNavigableRelationships.Definition]; public void Navigate(INavigableRelationship relationship) { diff --git a/src/EditorFeatures/Core.Wpf/Peek/DefinitionPeekableItem.cs b/src/EditorFeatures/Core.Wpf/Peek/DefinitionPeekableItem.cs index 229200804567e..c53ede7ead51a 100644 --- a/src/EditorFeatures/Core.Wpf/Peek/DefinitionPeekableItem.cs +++ b/src/EditorFeatures/Core.Wpf/Peek/DefinitionPeekableItem.cs @@ -41,7 +41,7 @@ public DefinitionPeekableItem( } public override IEnumerable Relationships - => SpecializedCollections.SingletonEnumerable(PredefinedPeekRelationships.Definitions); + => [PredefinedPeekRelationships.Definitions]; public override IPeekResultSource GetOrCreateResultSource(string relationshipName) => new ResultSource(this); diff --git a/src/EditorFeatures/Core.Wpf/Peek/ExternalFilePeekableItem.cs b/src/EditorFeatures/Core.Wpf/Peek/ExternalFilePeekableItem.cs index b05a5ee91ad62..5ea823535e7f0 100644 --- a/src/EditorFeatures/Core.Wpf/Peek/ExternalFilePeekableItem.cs +++ b/src/EditorFeatures/Core.Wpf/Peek/ExternalFilePeekableItem.cs @@ -27,9 +27,7 @@ public ExternalFilePeekableItem( } public override IEnumerable Relationships - { - get { return SpecializedCollections.SingletonEnumerable(_relationship); } - } + => [_relationship]; public override IPeekResultSource GetOrCreateResultSource(string relationshipName) => new ResultSource(this); diff --git a/src/EditorFeatures/Core/Tagging/AbstractAsynchronousTaggerProvider.TagSource_ProduceTags.cs b/src/EditorFeatures/Core/Tagging/AbstractAsynchronousTaggerProvider.TagSource_ProduceTags.cs index 3dabafc4cab6d..2d2c58b60cced 100644 --- a/src/EditorFeatures/Core/Tagging/AbstractAsynchronousTaggerProvider.TagSource_ProduceTags.cs +++ b/src/EditorFeatures/Core/Tagging/AbstractAsynchronousTaggerProvider.TagSource_ProduceTags.cs @@ -90,7 +90,7 @@ private void AccumulateTextChanges(TextContentChangedEventArgs contentChanged) var textChangeRange = new TextChangeRange(new TextSpan(c.OldSpan.Start, c.OldSpan.Length), c.NewLength); this.AccumulatedTextChanges = this.AccumulatedTextChanges == null ? textChangeRange - : this.AccumulatedTextChanges.Accumulate(SpecializedCollections.SingletonEnumerable(textChangeRange)); + : this.AccumulatedTextChanges.Accumulate([textChangeRange]); } break; diff --git a/src/EditorFeatures/Core/Tagging/AsynchronousViewportTaggerProvider.SingleViewportTaggerProvider.cs b/src/EditorFeatures/Core/Tagging/AsynchronousViewportTaggerProvider.SingleViewportTaggerProvider.cs index 95f1635b7e39c..a51d376bd7f02 100644 --- a/src/EditorFeatures/Core/Tagging/AsynchronousViewportTaggerProvider.SingleViewportTaggerProvider.cs +++ b/src/EditorFeatures/Core/Tagging/AsynchronousViewportTaggerProvider.SingleViewportTaggerProvider.cs @@ -80,7 +80,7 @@ protected override IEnumerable GetSpansToTag(ITextView? textView, // If we're the 'InView' tagger, tag what was visible. if (_viewPortToTag is ViewPortToTag.InView) - return SpecializedCollections.SingletonEnumerable(visibleSpan); + return [visibleSpan]; // For the above/below tagger, broaden the span to to the requested portion above/below what's visible, then // subtract out the visible range. From c2723ff4c633fa16ce52248f840e74b32ec98c5e Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:07:47 -0700 Subject: [PATCH 03/57] use collection expr --- .../AutomaticCompletion/AutomaticLineEnderCommandHandler.cs | 2 +- .../AutomaticLineEnderCommandHandler_Helpers.cs | 4 ++-- .../CSharp/Formatting/CSharpFormattingInteractionService.cs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/EditorFeatures/CSharp/AutomaticCompletion/AutomaticLineEnderCommandHandler.cs b/src/EditorFeatures/CSharp/AutomaticCompletion/AutomaticLineEnderCommandHandler.cs index b609ea8f86b6f..c0a809408dd79 100644 --- a/src/EditorFeatures/CSharp/AutomaticCompletion/AutomaticLineEnderCommandHandler.cs +++ b/src/EditorFeatures/CSharp/AutomaticCompletion/AutomaticLineEnderCommandHandler.cs @@ -105,7 +105,7 @@ protected override IList FormatBasedOnEndToken(ParsedDocument docume var formatter = document.LanguageServices.GetRequiredService(); return formatter.GetFormattingResult( root, - SpecializedCollections.SingletonCollection(CommonFormattingHelpers.GetFormattingSpan(root, span.Value)), + [CommonFormattingHelpers.GetFormattingSpan(root, span.Value)], options, rules: null, cancellationToken).GetTextChanges(cancellationToken); diff --git a/src/EditorFeatures/CSharp/AutomaticCompletion/AutomaticLineEnderCommandHandler_Helpers.cs b/src/EditorFeatures/CSharp/AutomaticCompletion/AutomaticLineEnderCommandHandler_Helpers.cs index 37655a312ed78..4f2b7ca71e26b 100644 --- a/src/EditorFeatures/CSharp/AutomaticCompletion/AutomaticLineEnderCommandHandler_Helpers.cs +++ b/src/EditorFeatures/CSharp/AutomaticCompletion/AutomaticLineEnderCommandHandler_Helpers.cs @@ -390,9 +390,9 @@ private static (SyntaxNode newNode, SyntaxNode oldNode) ModifyObjectCreationExpr // => // var l = new Bar() {}; // I am some comments var replacementContainerNode = objectCreationNodeContainer.ReplaceSyntax( - nodes: SpecializedCollections.SingletonCollection(baseObjectCreationExpressionNode), + nodes: [baseObjectCreationExpressionNode], (_, _) => objectCreationNodeWithCorrectInitializer.WithoutTrailingTrivia(), - tokens: SpecializedCollections.SingletonCollection(nextToken), + tokens: [nextToken], computeReplacementToken: (_, _) => SyntaxFactory.Token(SyntaxKind.SemicolonToken).WithTrailingTrivia(objectCreationNodeWithCorrectInitializer.GetTrailingTrivia()), trivia: [], diff --git a/src/EditorFeatures/CSharp/Formatting/CSharpFormattingInteractionService.cs b/src/EditorFeatures/CSharp/Formatting/CSharpFormattingInteractionService.cs index 4c0abffa1b6b8..bd67876b2110c 100644 --- a/src/EditorFeatures/CSharp/Formatting/CSharpFormattingInteractionService.cs +++ b/src/EditorFeatures/CSharp/Formatting/CSharpFormattingInteractionService.cs @@ -92,7 +92,7 @@ public Task> GetFormattingChangesAsync( var span = textSpan ?? new TextSpan(0, parsedDocument.Root.FullSpan.Length); var formattingSpan = CommonFormattingHelpers.GetFormattingSpan(parsedDocument.Root, span); - return Task.FromResult(Formatter.GetFormattedTextChanges(parsedDocument.Root, SpecializedCollections.SingletonEnumerable(formattingSpan), document.Project.Solution.Services, options, cancellationToken).ToImmutableArray()); + return Task.FromResult(Formatter.GetFormattedTextChanges(parsedDocument.Root, [formattingSpan], document.Project.Solution.Services, options, cancellationToken).ToImmutableArray()); } public Task> GetFormattingChangesOnPasteAsync(Document document, ITextBuffer textBuffer, TextSpan textSpan, CancellationToken cancellationToken) From 6eae9d34fc00e2263d8745a1316a306babe2b118 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:08:24 -0700 Subject: [PATCH 04/57] use collection expr --- .../Diagnostics/AbstractUserDiagnosticTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/EditorFeatures/DiagnosticsTestUtilities/Diagnostics/AbstractUserDiagnosticTest.cs b/src/EditorFeatures/DiagnosticsTestUtilities/Diagnostics/AbstractUserDiagnosticTest.cs index a7bad8a40a565..6128a5ceb1d2e 100644 --- a/src/EditorFeatures/DiagnosticsTestUtilities/Diagnostics/AbstractUserDiagnosticTest.cs +++ b/src/EditorFeatures/DiagnosticsTestUtilities/Diagnostics/AbstractUserDiagnosticTest.cs @@ -216,7 +216,7 @@ private static FixAllState GetFixAllState( if (scope == FixAllScope.Custom) { // Bulk fixing diagnostics in selected scope. - var diagnosticsToFix = ImmutableDictionary.CreateRange(SpecializedCollections.SingletonEnumerable(KeyValuePairUtil.Create(document, diagnostics.ToImmutableArray()))); + var diagnosticsToFix = ImmutableDictionary.CreateRange([KeyValuePairUtil.Create(document, diagnostics.ToImmutableArray())]); return FixAllState.Create(fixAllProvider, diagnosticsToFix, fixer, equivalenceKey, optionsProvider); } From 6f29ecc005416a21ebc818adc7a79d628e5ee8a1 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:08:43 -0700 Subject: [PATCH 05/57] use collection expr --- src/EditorFeatures/Test/CodeFixes/CodeFixServiceTests.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/EditorFeatures/Test/CodeFixes/CodeFixServiceTests.cs b/src/EditorFeatures/Test/CodeFixes/CodeFixServiceTests.cs index 6a61dc2a06b30..7cafd90ce14eb 100644 --- a/src/EditorFeatures/Test/CodeFixes/CodeFixServiceTests.cs +++ b/src/EditorFeatures/Test/CodeFixes/CodeFixServiceTests.cs @@ -411,10 +411,7 @@ private static void GetDocumentAndExtensionManager( } private static IEnumerable> CreateFixers() - { - return SpecializedCollections.SingletonEnumerable( - new Lazy(() => new MockFixer(), new CodeChangeProviderMetadata("Test", languages: LanguageNames.CSharp))); - } + => [new Lazy(() => new MockFixer(), new CodeChangeProviderMetadata("Test", languages: LanguageNames.CSharp))]; internal class MockFixer : CodeFixProvider { From 1d161f074e9e6f0860d6499e53c5b69e4d7694ef Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:09:21 -0700 Subject: [PATCH 06/57] use collection expr --- .../Test/MetadataAsSource/AbstractMetadataAsSourceTests.cs | 4 ++-- .../Test/MetadataAsSource/MetadataAsSourceTests.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/EditorFeatures/Test/MetadataAsSource/AbstractMetadataAsSourceTests.cs b/src/EditorFeatures/Test/MetadataAsSource/AbstractMetadataAsSourceTests.cs index ef3aa253d2d2f..65be22a0e3a3c 100644 --- a/src/EditorFeatures/Test/MetadataAsSource/AbstractMetadataAsSourceTests.cs +++ b/src/EditorFeatures/Test/MetadataAsSource/AbstractMetadataAsSourceTests.cs @@ -47,7 +47,7 @@ public virtual Task DisposeAsync() internal static async Task GenerateAndVerifySourceAsync( string metadataSource, string symbolName, string projectLanguage, string expected, bool signaturesOnly = true, bool includeXmlDocComments = false, string languageVersion = null, string metadataLanguageVersion = null, string metadataCommonReferences = null) { - using var context = TestContext.Create(projectLanguage, SpecializedCollections.SingletonEnumerable(metadataSource), includeXmlDocComments, languageVersion: languageVersion, metadataLanguageVersion: metadataLanguageVersion, metadataCommonReferences: metadataCommonReferences); + using var context = TestContext.Create(projectLanguage, [metadataSource], includeXmlDocComments, languageVersion: languageVersion, metadataLanguageVersion: metadataLanguageVersion, metadataCommonReferences: metadataCommonReferences); await context.GenerateAndVerifySourceAsync(symbolName, expected, signaturesOnly: signaturesOnly); } @@ -103,7 +103,7 @@ internal static async Task TestSymbolIdMatchesMetadataAsync(string projectLangua var metadataSource = @"[assembly: System.Reflection.AssemblyVersion(""2.0.0.0"")] public class C { }"; var symbolName = "C"; - using var context = TestContext.Create(projectLanguage, SpecializedCollections.SingletonEnumerable(metadataSource)); + using var context = TestContext.Create(projectLanguage, [metadataSource]); var metadataSymbol = await context.ResolveSymbolAsync(symbolName); var metadataSymbolId = metadataSymbol.GetSymbolKey(); var generatedFile = await context.GenerateSourceAsync(symbolName); diff --git a/src/EditorFeatures/Test/MetadataAsSource/MetadataAsSourceTests.cs b/src/EditorFeatures/Test/MetadataAsSource/MetadataAsSourceTests.cs index a73a79f37e118..97f9e1cd284ec 100644 --- a/src/EditorFeatures/Test/MetadataAsSource/MetadataAsSourceTests.cs +++ b/src/EditorFeatures/Test/MetadataAsSource/MetadataAsSourceTests.cs @@ -976,7 +976,7 @@ public async Task TestTypeInFileScopedNamespace1() var metadataSource = "namespace N { public class C {} }"; using var context = TestContext.Create( - LanguageNames.CSharp, SpecializedCollections.SingletonEnumerable(metadataSource), languageVersion: "10"); + LanguageNames.CSharp, [metadataSource], languageVersion: "10"); await context.GenerateAndVerifySourceAsync("N.C", $@"#region {FeaturesResources.Assembly} ReferencedAssembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null From 8ce65974ec096964d3e37477cbf2fe4b724077f0 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:10:55 -0700 Subject: [PATCH 07/57] use collection expr --- .../Test/MetadataAsSource/MetadataAsSourceTests.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/EditorFeatures/Test/MetadataAsSource/MetadataAsSourceTests.cs b/src/EditorFeatures/Test/MetadataAsSource/MetadataAsSourceTests.cs index 97f9e1cd284ec..d23e751aa91ce 100644 --- a/src/EditorFeatures/Test/MetadataAsSource/MetadataAsSourceTests.cs +++ b/src/EditorFeatures/Test/MetadataAsSource/MetadataAsSourceTests.cs @@ -998,7 +998,7 @@ public async Task TestTypeInFileScopedNamespace2() var metadataSource = "namespace N { public class C {} }"; using var context = TestContext.Create( - LanguageNames.CSharp, SpecializedCollections.SingletonEnumerable(metadataSource), languageVersion: "9"); + LanguageNames.CSharp, [metadataSource], languageVersion: "9"); await context.GenerateAndVerifySourceAsync("N.C", $@"#region {FeaturesResources.Assembly} ReferencedAssembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null @@ -1020,7 +1020,7 @@ public async Task TestTypeInFileScopedNamespace3() var metadataSource = "namespace N { public class C {} }"; using var context = TestContext.Create( - LanguageNames.CSharp, SpecializedCollections.SingletonEnumerable(metadataSource), languageVersion: "10"); + LanguageNames.CSharp, [metadataSource], languageVersion: "10"); await context.GenerateAndVerifySourceAsync("N.C", $@"#region {FeaturesResources.Assembly} ReferencedAssembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null @@ -1699,7 +1699,7 @@ public async Task TestReuseGenerateMemberOfGeneratedType() { var metadataSource = "public class C { public bool Is; }"; - using var context = TestContext.Create(LanguageNames.CSharp, SpecializedCollections.SingletonEnumerable(metadataSource)); + using var context = TestContext.Create(LanguageNames.CSharp, [metadataSource]); var a = await context.GenerateSourceAsync("C"); var b = await context.GenerateSourceAsync("C.Is"); TestContext.VerifyDocumentReused(a, b); From 66e4621df1bd057014d94e31d08c4a5b74e89e24 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:11:14 -0700 Subject: [PATCH 08/57] use collection expr --- .../MetadataAsSource/MetadataAsSourceTests.cs | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/EditorFeatures/Test/MetadataAsSource/MetadataAsSourceTests.cs b/src/EditorFeatures/Test/MetadataAsSource/MetadataAsSourceTests.cs index d23e751aa91ce..214c1ed2275cd 100644 --- a/src/EditorFeatures/Test/MetadataAsSource/MetadataAsSourceTests.cs +++ b/src/EditorFeatures/Test/MetadataAsSource/MetadataAsSourceTests.cs @@ -2693,7 +2693,7 @@ public static class ObjectExtensions using var context = TestContext.Create( LanguageNames.CSharp, - SpecializedCollections.SingletonEnumerable(metadata), + [metadata], includeXmlDocComments: false, sourceWithSymbolReference: sourceWithSymbolReference); var navigationSymbol = await context.GetNavigationSymbolAsync(); @@ -2735,7 +2735,7 @@ End Module using var context = TestContext.Create( LanguageNames.VisualBasic, - SpecializedCollections.SingletonEnumerable(metadata), + [metadata], includeXmlDocComments: false, sourceWithSymbolReference: sourceWithSymbolReference); var navigationSymbol = await context.GetNavigationSymbolAsync(); @@ -3199,7 +3199,7 @@ public class [|TestType|] where T : unmanaged using var context = TestContext.Create( LanguageNames.CSharp, - SpecializedCollections.SingletonEnumerable(metadata), + [metadata], includeXmlDocComments: false, languageVersion: "7.3", sourceWithSymbolReference: sourceWithSymbolReference); @@ -3239,7 +3239,7 @@ public class TestType using var context = TestContext.Create( LanguageNames.CSharp, - SpecializedCollections.SingletonEnumerable(metadata), + [metadata], includeXmlDocComments: false, languageVersion: "7.3", sourceWithSymbolReference: sourceWithSymbolReference); @@ -3268,7 +3268,7 @@ class C using var context = TestContext.Create( LanguageNames.CSharp, - SpecializedCollections.SingletonEnumerable(metadata), + [metadata], includeXmlDocComments: false, languageVersion: "7.3", sourceWithSymbolReference: sourceWithSymbolReference); @@ -4746,7 +4746,7 @@ public class [|TestType|] where T : notnull using var context = TestContext.Create( LanguageNames.CSharp, - SpecializedCollections.SingletonEnumerable(metadata), + [metadata], includeXmlDocComments: false, languageVersion: "8", sourceWithSymbolReference: sourceWithSymbolReference, @@ -4788,7 +4788,7 @@ public class TestType using var context = TestContext.Create( LanguageNames.CSharp, - SpecializedCollections.SingletonEnumerable(metadata), + [metadata], includeXmlDocComments: false, languageVersion: "8", sourceWithSymbolReference: sourceWithSymbolReference, @@ -4819,7 +4819,7 @@ class C using var context = TestContext.Create( LanguageNames.CSharp, - SpecializedCollections.SingletonEnumerable(metadata), + [metadata], includeXmlDocComments: false, languageVersion: "8", sourceWithSymbolReference: sourceWithSymbolReference, @@ -4877,7 +4877,7 @@ public class TestType using var context = TestContext.Create( LanguageNames.CSharp, - SpecializedCollections.SingletonEnumerable(metadata), + [metadata], includeXmlDocComments: false, languageVersion: "8", sourceWithSymbolReference: sourceWithSymbolReference, @@ -4932,7 +4932,7 @@ public class TestType using var context = TestContext.Create( LanguageNames.CSharp, - SpecializedCollections.SingletonEnumerable(metadata), + [metadata], includeXmlDocComments: false, languageVersion: "8", sourceWithSymbolReference: sourceWithSymbolReference, @@ -4995,7 +4995,7 @@ public class TestType using var context = TestContext.Create( LanguageNames.CSharp, - SpecializedCollections.SingletonEnumerable(metadata), + [metadata], includeXmlDocComments: false, languageVersion: "8", sourceWithSymbolReference: sourceWithSymbolReference, @@ -5045,7 +5045,7 @@ public class TestType using var context = TestContext.Create( LanguageNames.CSharp, - SpecializedCollections.SingletonEnumerable(metadata), + [metadata], includeXmlDocComments: false, languageVersion: "8", sourceWithSymbolReference: sourceWithSymbolReference, @@ -5096,7 +5096,7 @@ public class TestType using var context = TestContext.Create( LanguageNames.CSharp, - SpecializedCollections.SingletonEnumerable(metadata), + [metadata], includeXmlDocComments: false, languageVersion: "8", sourceWithSymbolReference: sourceWithSymbolReference, @@ -5144,7 +5144,7 @@ public class TestType using var context = TestContext.Create( LanguageNames.CSharp, - SpecializedCollections.SingletonEnumerable(metadata), + [metadata], includeXmlDocComments: false, languageVersion: "8", sourceWithSymbolReference: sourceWithSymbolReference, @@ -5192,7 +5192,7 @@ public class TestType using var context = TestContext.Create( LanguageNames.CSharp, - SpecializedCollections.SingletonEnumerable(metadata), + [metadata], includeXmlDocComments: false, languageVersion: "8", sourceWithSymbolReference: sourceWithSymbolReference, @@ -5238,7 +5238,7 @@ public class TestType using var context = TestContext.Create( LanguageNames.CSharp, - SpecializedCollections.SingletonEnumerable(metadata), + [metadata], includeXmlDocComments: false, languageVersion: "8", sourceWithSymbolReference: sourceWithSymbolReference, @@ -5284,7 +5284,7 @@ public class TestType using var context = TestContext.Create( LanguageNames.CSharp, - SpecializedCollections.SingletonEnumerable(metadata), + [metadata], includeXmlDocComments: false, languageVersion: "8", sourceWithSymbolReference: sourceWithSymbolReference, @@ -5330,7 +5330,7 @@ public class TestType using var context = TestContext.Create( LanguageNames.CSharp, - SpecializedCollections.SingletonEnumerable(metadata), + [metadata], includeXmlDocComments: false, languageVersion: "8", sourceWithSymbolReference: sourceWithSymbolReference, @@ -5374,7 +5374,7 @@ public class TestType using var context = TestContext.Create( LanguageNames.CSharp, - SpecializedCollections.SingletonEnumerable(metadata), + [metadata], includeXmlDocComments: false, languageVersion: "8", sourceWithSymbolReference: sourceWithSymbolReference, @@ -5438,7 +5438,7 @@ public class TestType using var context = TestContext.Create( LanguageNames.CSharp, - SpecializedCollections.SingletonEnumerable(metadata), + [metadata], includeXmlDocComments: false, languageVersion: "8", sourceWithSymbolReference: sourceWithSymbolReference, @@ -5512,7 +5512,7 @@ public class Nested using var context = TestContext.Create( LanguageNames.CSharp, - SpecializedCollections.SingletonEnumerable(metadata), + [metadata], includeXmlDocComments: false, languageVersion: "8", sourceWithSymbolReference: sourceWithSymbolReference, @@ -5556,7 +5556,7 @@ public class TestType using var context = TestContext.Create( LanguageNames.CSharp, - SpecializedCollections.SingletonEnumerable(metadata), + [metadata], includeXmlDocComments: false, languageVersion: "8", sourceWithSymbolReference: sourceWithSymbolReference, From 287d75505143907deaf00321b6c71e47df6b129f Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:12:34 -0700 Subject: [PATCH 09/57] use collection expr --- .../Test/RenameTracking/RenameTrackingTestState.cs | 2 +- .../GoToAdjacentMember/AbstractGoToAdjacentMemberTests.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/EditorFeatures/Test/RenameTracking/RenameTrackingTestState.cs b/src/EditorFeatures/Test/RenameTracking/RenameTrackingTestState.cs index 8211597d100e1..299725f22611d 100644 --- a/src/EditorFeatures/Test/RenameTracking/RenameTrackingTestState.cs +++ b/src/EditorFeatures/Test/RenameTracking/RenameTrackingTestState.cs @@ -112,7 +112,7 @@ public RenameTrackingTestState( { _codeRefactoringProvider = new RenameTrackingCodeRefactoringProvider( _historyRegistry, - SpecializedCollections.SingletonEnumerable(_mockRefactorNotifyService)); + [_mockRefactorNotifyService]); } else { diff --git a/src/EditorFeatures/TestUtilities/GoToAdjacentMember/AbstractGoToAdjacentMemberTests.cs b/src/EditorFeatures/TestUtilities/GoToAdjacentMember/AbstractGoToAdjacentMemberTests.cs index 8184100af8e92..60af72e28cb9f 100644 --- a/src/EditorFeatures/TestUtilities/GoToAdjacentMember/AbstractGoToAdjacentMemberTests.cs +++ b/src/EditorFeatures/TestUtilities/GoToAdjacentMember/AbstractGoToAdjacentMemberTests.cs @@ -26,7 +26,7 @@ protected async Task AssertNavigatedAsync(string code, bool next, SourceCodeKind { var kinds = sourceCodeKind != null ? SpecializedCollections.SingletonEnumerable(sourceCodeKind.Value) - : new[] { SourceCodeKind.Regular, SourceCodeKind.Script }; + : [SourceCodeKind.Regular, SourceCodeKind.Script]; foreach (var kind in kinds) { From 61bbeafd7b3e54a46377b9edc358c777f3e72e1d Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:13:09 -0700 Subject: [PATCH 10/57] use collection expr --- .../SymbolReference.SymbolReferenceCodeAction.cs | 7 +------ .../Portable/ChangeSignature/ChangeSignatureCodeAction.cs | 4 +--- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/Features/Core/Portable/AddImport/CodeActions/SymbolReference.SymbolReferenceCodeAction.cs b/src/Features/Core/Portable/AddImport/CodeActions/SymbolReference.SymbolReferenceCodeAction.cs index c9b9e26deef5d..49b2c38c311b3 100644 --- a/src/Features/Core/Portable/AddImport/CodeActions/SymbolReference.SymbolReferenceCodeAction.cs +++ b/src/Features/Core/Portable/AddImport/CodeActions/SymbolReference.SymbolReferenceCodeAction.cs @@ -33,12 +33,7 @@ protected SymbolReferenceCodeAction( protected override async Task> ComputePreviewOperationsAsync(CancellationToken cancellationToken) { var operation = await GetChangeSolutionOperationAsync(isPreview: true, cancellationToken).ConfigureAwait(false); - if (operation is null) - { - return []; - } - - return SpecializedCollections.SingletonEnumerable(operation); + return operation is null ? [] : [operation]; } protected override async Task> ComputeOperationsAsync( diff --git a/src/Features/Core/Portable/ChangeSignature/ChangeSignatureCodeAction.cs b/src/Features/Core/Portable/ChangeSignature/ChangeSignatureCodeAction.cs index b4aa13a190617..75f19be87a1cd 100644 --- a/src/Features/Core/Portable/ChangeSignature/ChangeSignatureCodeAction.cs +++ b/src/Features/Core/Portable/ChangeSignature/ChangeSignatureCodeAction.cs @@ -38,9 +38,7 @@ protected override async Task> ComputeOperation var changeSignatureResult = await _changeSignatureService.ChangeSignatureWithContextAsync(_context, changeSignatureOptions, cancellationToken).ConfigureAwait(false); if (changeSignatureResult.Succeeded) - { - return SpecializedCollections.SingletonEnumerable(new ChangeSignatureCodeActionOperation(changeSignatureResult.UpdatedSolution, changeSignatureResult.ConfirmationMessage)); - } + return [new ChangeSignatureCodeActionOperation(changeSignatureResult.UpdatedSolution, changeSignatureResult.ConfirmationMessage)]; } return []; From c37bf61bea56bd277e9b1b647f833f6fc626d6d4 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:13:37 -0700 Subject: [PATCH 11/57] use collection expr --- .../Portable/CodeFixes/Configuration/ConfigurationUpdater.cs | 2 +- .../AbstractSuppressionCodeFixProvider.PragmaBatchFixHelpers.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Features/Core/Portable/CodeFixes/Configuration/ConfigurationUpdater.cs b/src/Features/Core/Portable/CodeFixes/Configuration/ConfigurationUpdater.cs index 3422e33b99dc9..2dfef354517ad 100644 --- a/src/Features/Core/Portable/CodeFixes/Configuration/ConfigurationUpdater.cs +++ b/src/Features/Core/Portable/CodeFixes/Configuration/ConfigurationUpdater.cs @@ -203,7 +203,7 @@ public static Task ConfigureCodeStyleOptionAsync( Project project, CancellationToken cancellationToken) => ConfigureCodeStyleOptionsAsync( - SpecializedCollections.SingletonEnumerable((optionName, optionValue, isPerLanguage)), + [(optionName, optionValue, isPerLanguage)], diagnostic.Severity.ToEditorConfigString(), diagnostic, project, configurationKind: ConfigurationKind.OptionValue, cancellationToken); diff --git a/src/Features/Core/Portable/CodeFixes/Suppression/AbstractSuppressionCodeFixProvider.PragmaBatchFixHelpers.cs b/src/Features/Core/Portable/CodeFixes/Suppression/AbstractSuppressionCodeFixProvider.PragmaBatchFixHelpers.cs index 25a8fcd24a3f3..81bd3002bced4 100644 --- a/src/Features/Core/Portable/CodeFixes/Suppression/AbstractSuppressionCodeFixProvider.PragmaBatchFixHelpers.cs +++ b/src/Features/Core/Portable/CodeFixes/Suppression/AbstractSuppressionCodeFixProvider.PragmaBatchFixHelpers.cs @@ -86,7 +86,7 @@ private static async Task BatchPragmaFixesAsync( properties: diagnostic.Properties, isSuppressed: diagnostic.IsSuppressed); - var newSuppressionFixes = await suppressionFixProvider.GetFixesAsync(currentDocument, currentDiagnosticSpan, SpecializedCollections.SingletonEnumerable(diagnostic), fallbackOptions, cancellationToken).ConfigureAwait(false); + var newSuppressionFixes = await suppressionFixProvider.GetFixesAsync(currentDocument, currentDiagnosticSpan, [diagnostic], fallbackOptions, cancellationToken).ConfigureAwait(false); var newSuppressionFix = newSuppressionFixes.SingleOrDefault(); if (newSuppressionFix != null) { From 59721995ff29854f475dbaa8f704c5b4aaa51582 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:14:00 -0700 Subject: [PATCH 12/57] use collection expr --- ...ressionCodeFixProvider.PragmaWarningBatchFixAllProvider.cs | 2 +- ...nCodeFixProvider.RemoveSuppressionCodeAction.BatchFixer.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Features/Core/Portable/CodeFixes/Suppression/AbstractSuppressionCodeFixProvider.PragmaWarningBatchFixAllProvider.cs b/src/Features/Core/Portable/CodeFixes/Suppression/AbstractSuppressionCodeFixProvider.PragmaWarningBatchFixAllProvider.cs index 33bf3f7e1b06e..bce19c8db6a56 100644 --- a/src/Features/Core/Portable/CodeFixes/Suppression/AbstractSuppressionCodeFixProvider.PragmaWarningBatchFixAllProvider.cs +++ b/src/Features/Core/Portable/CodeFixes/Suppression/AbstractSuppressionCodeFixProvider.PragmaWarningBatchFixAllProvider.cs @@ -36,7 +36,7 @@ protected override async Task AddDocumentFixesAsync( { var span = diagnostic.Location.SourceSpan; var pragmaSuppressions = await _suppressionFixProvider.GetPragmaSuppressionsAsync( - document, span, SpecializedCollections.SingletonEnumerable(diagnostic), fixAllState.CodeActionOptionsProvider, cancellationToken).ConfigureAwait(false); + document, span, [diagnostic], fixAllState.CodeActionOptionsProvider, cancellationToken).ConfigureAwait(false); var pragmaSuppression = pragmaSuppressions.SingleOrDefault(); if (pragmaSuppression != null) { diff --git a/src/Features/Core/Portable/CodeFixes/Suppression/AbstractSuppressionCodeFixProvider.RemoveSuppressionCodeAction.BatchFixer.cs b/src/Features/Core/Portable/CodeFixes/Suppression/AbstractSuppressionCodeFixProvider.RemoveSuppressionCodeAction.BatchFixer.cs index ec90e430ddf57..c03dc33e08ad9 100644 --- a/src/Features/Core/Portable/CodeFixes/Suppression/AbstractSuppressionCodeFixProvider.RemoveSuppressionCodeAction.BatchFixer.cs +++ b/src/Features/Core/Portable/CodeFixes/Suppression/AbstractSuppressionCodeFixProvider.RemoveSuppressionCodeAction.BatchFixer.cs @@ -44,7 +44,7 @@ protected override async Task AddDocumentFixesAsync( { var span = diagnostic.Location.SourceSpan; var removeSuppressionFixes = await _suppressionFixProvider.GetFixesAsync( - document, span, SpecializedCollections.SingletonEnumerable(diagnostic), fixAllState.CodeActionOptionsProvider, cancellationToken).ConfigureAwait(false); + document, span, [diagnostic], fixAllState.CodeActionOptionsProvider, cancellationToken).ConfigureAwait(false); var removeSuppressionFix = removeSuppressionFixes.SingleOrDefault(); if (removeSuppressionFix != null) { @@ -89,7 +89,7 @@ protected override async Task AddProjectFixesAsync( foreach (var diagnostic in diagnostics.Where(d => !d.Location.IsInSource && d.IsSuppressed)) { var removeSuppressionFixes = await _suppressionFixProvider.GetFixesAsync( - project, SpecializedCollections.SingletonEnumerable(diagnostic), fixAllState.CodeActionOptionsProvider, cancellationToken).ConfigureAwait(false); + project, [diagnostic], fixAllState.CodeActionOptionsProvider, cancellationToken).ConfigureAwait(false); if (removeSuppressionFixes.SingleOrDefault()?.Action is RemoveSuppressionCodeAction removeSuppressionCodeAction) { if (fixAllState.IsFixMultiple) From 5910bf71c6b8033b8dda85d548cca8642eb71aaa Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:14:15 -0700 Subject: [PATCH 13/57] use collection expr --- .../AbstractDocumentationCommentFormattingService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Features/Core/Portable/DocumentationComments/AbstractDocumentationCommentFormattingService.cs b/src/Features/Core/Portable/DocumentationComments/AbstractDocumentationCommentFormattingService.cs index 3b64e398908ca..f380ef167bbbb 100644 --- a/src/Features/Core/Portable/DocumentationComments/AbstractDocumentationCommentFormattingService.cs +++ b/src/Features/Core/Portable/DocumentationComments/AbstractDocumentationCommentFormattingService.cs @@ -490,7 +490,7 @@ private static void AppendTextFromAttribute(FormatterState state, XAttribute att ? attribute.Value : null; var navigationHint = navigationTarget; - state.AppendParts(SpecializedCollections.SingletonEnumerable(new TaggedText(displayKind, text, style, navigationTarget, navigationHint))); + state.AppendParts([new TaggedText(displayKind, text, style, navigationTarget, navigationHint)]); } } From 42b6e42679a64aefadce83ae6e82f36ca4caaacd Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:14:53 -0700 Subject: [PATCH 14/57] use collection expr --- .../AbstractDocumentationCommentFormattingService.cs | 6 ++---- ...stractGenerateVariableService.GenerateLocalCodeAction.cs | 6 +----- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/Features/Core/Portable/DocumentationComments/AbstractDocumentationCommentFormattingService.cs b/src/Features/Core/Portable/DocumentationComments/AbstractDocumentationCommentFormattingService.cs index f380ef167bbbb..71d796686baf0 100644 --- a/src/Features/Core/Portable/DocumentationComments/AbstractDocumentationCommentFormattingService.cs +++ b/src/Features/Core/Portable/DocumentationComments/AbstractDocumentationCommentFormattingService.cs @@ -514,8 +514,7 @@ internal static IEnumerable CrefToSymbolDisplayParts( } // if any of that fails fall back to just displaying the raw text - return SpecializedCollections.SingletonEnumerable( - new SymbolDisplayPart(kind, symbol: null, text: TrimCrefPrefix(crefValue))); + return [new SymbolDisplayPart(kind, symbol: null, text: TrimCrefPrefix(crefValue))]; } internal static IEnumerable TypeParameterRefToSymbolDisplayParts( @@ -535,8 +534,7 @@ internal static IEnumerable TypeParameterRefToSymbolDisplayPa } // if any of that fails fall back to just displaying the raw text - return SpecializedCollections.SingletonEnumerable( - new SymbolDisplayPart(SymbolDisplayPartKind.TypeParameterName, symbol: null, text: TrimCrefPrefix(crefValue))); + return [new SymbolDisplayPart(SymbolDisplayPartKind.TypeParameterName, symbol: null, text: TrimCrefPrefix(crefValue))]; } private static string TrimCrefPrefix(string value) diff --git a/src/Features/Core/Portable/GenerateMember/GenerateVariable/AbstractGenerateVariableService.GenerateLocalCodeAction.cs b/src/Features/Core/Portable/GenerateMember/GenerateVariable/AbstractGenerateVariableService.GenerateLocalCodeAction.cs index 8c04c0fa758e8..89c3b25fa84a7 100644 --- a/src/Features/Core/Portable/GenerateMember/GenerateVariable/AbstractGenerateVariableService.GenerateLocalCodeAction.cs +++ b/src/Features/Core/Portable/GenerateMember/GenerateVariable/AbstractGenerateVariableService.GenerateLocalCodeAction.cs @@ -67,11 +67,7 @@ private async Task GetNewRootAsync(CancellationToken cancellationTok var context = new CodeGenerationContext(beforeThisLocation: _state.IdentifierToken.GetLocation()); var info = await _document.GetCodeGenerationInfoAsync(context, _fallbackOptions, cancellationToken).ConfigureAwait(false); - return info.Service.AddStatements( - root, - SpecializedCollections.SingletonEnumerable(localStatement), - info, - cancellationToken: cancellationToken); + return info.Service.AddStatements(root, [localStatement], info, cancellationToken); } } } From 87355c217719dced5ca7e8444805ded49495786e Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:15:15 -0700 Subject: [PATCH 15/57] use collection expr --- .../ImplementAbstractClass/ImplementAbstractClassData.cs | 2 +- .../IntroduceParameter/IntroduceParameterDocumentRewriter.cs | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Features/Core/Portable/ImplementAbstractClass/ImplementAbstractClassData.cs b/src/Features/Core/Portable/ImplementAbstractClass/ImplementAbstractClassData.cs index c07f15bf3c071..0a01da68140f6 100644 --- a/src/Features/Core/Portable/ImplementAbstractClass/ImplementAbstractClassData.cs +++ b/src/Features/Core/Portable/ImplementAbstractClass/ImplementAbstractClassData.cs @@ -55,7 +55,7 @@ internal sealed class ImplementAbstractClassData( return null; var unimplementedMembers = classType.GetAllUnimplementedMembers( - SpecializedCollections.SingletonEnumerable(abstractClassType), + [abstractClassType], includeMembersRequiringExplicitImplementation: false, cancellationToken); diff --git a/src/Features/Core/Portable/IntroduceParameter/IntroduceParameterDocumentRewriter.cs b/src/Features/Core/Portable/IntroduceParameter/IntroduceParameterDocumentRewriter.cs index e238ff6f75729..5ac5ef14103ec 100644 --- a/src/Features/Core/Portable/IntroduceParameter/IntroduceParameterDocumentRewriter.cs +++ b/src/Features/Core/Portable/IntroduceParameter/IntroduceParameterDocumentRewriter.cs @@ -668,9 +668,7 @@ private async Task UpdateExpressionInOriginalFunctionAsync(SyntaxEditor editor, private async Task> FindMatchesAsync(CancellationToken cancellationToken) { if (!_allOccurrences) - { - return SpecializedCollections.SingletonEnumerable(_expression); - } + return [_expression]; var syntaxFacts = _originalDocument.GetRequiredLanguageService(); var originalSemanticModel = await _originalDocument.GetRequiredSemanticModelAsync(cancellationToken).ConfigureAwait(false); From a5fc822275bb1444ddce9a4532aac7e691cf4f2e Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:15:27 -0700 Subject: [PATCH 16/57] use collection expr --- .../InvertIf/AbstractInvertIfCodeRefactoringProvider.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Features/Core/Portable/InvertIf/AbstractInvertIfCodeRefactoringProvider.cs b/src/Features/Core/Portable/InvertIf/AbstractInvertIfCodeRefactoringProvider.cs index 4a8b3713e4066..690543cab2fb8 100644 --- a/src/Features/Core/Portable/InvertIf/AbstractInvertIfCodeRefactoringProvider.cs +++ b/src/Features/Core/Portable/InvertIf/AbstractInvertIfCodeRefactoringProvider.cs @@ -524,8 +524,7 @@ private SyntaxNode GetRootWithInvertIfStatement( text, ifNode: ifNode, condition: negatedExpression, - trueStatement: AsEmbeddedStatement( - SpecializedCollections.SingletonEnumerable(newIfBody), original: ifBody)); + trueStatement: AsEmbeddedStatement([newIfBody], original: ifBody)); var statementsBeforeIf = statements.Take(index); From 9981fba8216318c09b3ac4dfd4386c3d0e8092f4 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:17:15 -0700 Subject: [PATCH 17/57] use collection expr --- .../InvertIf/AbstractInvertIfCodeRefactoringProvider.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Features/Core/Portable/InvertIf/AbstractInvertIfCodeRefactoringProvider.cs b/src/Features/Core/Portable/InvertIf/AbstractInvertIfCodeRefactoringProvider.cs index 690543cab2fb8..09a60fe9f2cc8 100644 --- a/src/Features/Core/Portable/InvertIf/AbstractInvertIfCodeRefactoringProvider.cs +++ b/src/Features/Core/Portable/InvertIf/AbstractInvertIfCodeRefactoringProvider.cs @@ -550,8 +550,7 @@ private SyntaxNode GetRootWithInvertIfStatement( text, ifNode: ifNode, condition: negatedExpression, - trueStatement: AsEmbeddedStatement( - SpecializedCollections.SingletonEnumerable(newIfBody), ifBody)); + trueStatement: AsEmbeddedStatement([newIfBody], ifBody)); var statementsBeforeIf = statements.Take(index); From 36f595a3c495b0c81d071a2a8fbdda743559a161 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:17:37 -0700 Subject: [PATCH 18/57] use collection expr --- .../MetadataAsSource/AbstractMetadataAsSourceService.cs | 2 +- .../Organizing/Organizers/AbstractSyntaxNodeOrganizer.cs | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Features/Core/Portable/MetadataAsSource/AbstractMetadataAsSourceService.cs b/src/Features/Core/Portable/MetadataAsSource/AbstractMetadataAsSourceService.cs index e9e1226a3f58b..874bd38c45b91 100644 --- a/src/Features/Core/Portable/MetadataAsSource/AbstractMetadataAsSourceService.cs +++ b/src/Features/Core/Portable/MetadataAsSource/AbstractMetadataAsSourceService.cs @@ -71,7 +71,7 @@ public async Task AddSourceToAsync( var formattedDoc = await Formatter.FormatAsync( docWithAssemblyInfo, - SpecializedCollections.SingletonEnumerable(node.FullSpan), + [node.FullSpan], options.CleanupOptions.FormattingOptions, GetFormattingRules(docWithAssemblyInfo), cancellationToken).ConfigureAwait(false); diff --git a/src/Features/Core/Portable/Organizing/Organizers/AbstractSyntaxNodeOrganizer.cs b/src/Features/Core/Portable/Organizing/Organizers/AbstractSyntaxNodeOrganizer.cs index 86151b89ca495..97d341e1bfb25 100644 --- a/src/Features/Core/Portable/Organizing/Organizers/AbstractSyntaxNodeOrganizer.cs +++ b/src/Features/Core/Portable/Organizing/Organizers/AbstractSyntaxNodeOrganizer.cs @@ -14,10 +14,7 @@ namespace Microsoft.CodeAnalysis.Organizing.Organizers; internal abstract class AbstractSyntaxNodeOrganizer : ISyntaxOrganizer where TSyntaxNode : SyntaxNode { - public IEnumerable SyntaxNodeTypes - { - get { return SpecializedCollections.SingletonEnumerable(typeof(TSyntaxNode)); } - } + public IEnumerable SyntaxNodeTypes => [typeof(TSyntaxNode)]; public SyntaxNode OrganizeNode(SemanticModel semanticModel, SyntaxNode node, CancellationToken cancellationToken) => Organize((TSyntaxNode)node, cancellationToken); From 755963d3516368ff60dd3964ae233896a91eba4c Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:18:03 -0700 Subject: [PATCH 19/57] use collection expr --- .../SnippetProviders/AbstractMainMethodSnippetProvider.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Features/Core/Portable/Snippets/SnippetProviders/AbstractMainMethodSnippetProvider.cs b/src/Features/Core/Portable/Snippets/SnippetProviders/AbstractMainMethodSnippetProvider.cs index d43f02b48dd13..7d00594dc0db7 100644 --- a/src/Features/Core/Portable/Snippets/SnippetProviders/AbstractMainMethodSnippetProvider.cs +++ b/src/Features/Core/Portable/Snippets/SnippetProviders/AbstractMainMethodSnippetProvider.cs @@ -27,9 +27,9 @@ protected sealed override Task GenerateSnippetTextChangeAsync(Docume var generator = SyntaxGenerator.GetGenerator(document); var method = generator.MethodDeclaration( name: WellKnownMemberNames.EntryPointMethodName, - parameters: SpecializedCollections.SingletonEnumerable(generator.ParameterDeclaration( + parameters: [generator.ParameterDeclaration( name: "args", - type: generator.ArrayTypeExpression(generator.TypeExpression(SpecialType.System_String)))), + type: generator.ArrayTypeExpression(generator.TypeExpression(SpecialType.System_String)))], returnType: GenerateReturnType(generator), modifiers: DeclarationModifiers.Static, statements: GenerateInnerStatements(generator)); From b7d13555a1ecad88a0b477f70e0d208f6d6e837b Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:18:41 -0700 Subject: [PATCH 20/57] use collection expr --- .../AbstractCurlyBraceOrBracketCompletionService.cs | 2 +- .../CSharpTest/Diagnostics/Suppression/SuppressionTests.cs | 2 +- src/Features/CSharpTest/ExtractClass/ExtractClassTests.cs | 2 +- .../Core/Portable/Workspace/MiscellaneousFileUtilities.cs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Features/CSharp/Portable/BraceCompletion/AbstractCurlyBraceOrBracketCompletionService.cs b/src/Features/CSharp/Portable/BraceCompletion/AbstractCurlyBraceOrBracketCompletionService.cs index cadacf5d61fcd..31318ba8b70fd 100644 --- a/src/Features/CSharp/Portable/BraceCompletion/AbstractCurlyBraceOrBracketCompletionService.cs +++ b/src/Features/CSharp/Portable/BraceCompletion/AbstractCurlyBraceOrBracketCompletionService.cs @@ -117,7 +117,7 @@ private static bool ContainsOnlyWhitespace(SourceText text, int openingPosition, // Handling syntax tree directly to avoid parsing in potentially UI blocking code-path var closingToken = FindClosingBraceToken(document.Root, closingPoint); var annotatedNewline = SyntaxFactory.EndOfLine(options.FormattingOptions.NewLine).WithAdditionalAnnotations(s_closingBraceNewlineAnnotation); - var newClosingToken = closingToken.WithPrependedLeadingTrivia(SpecializedCollections.SingletonEnumerable(annotatedNewline)); + var newClosingToken = closingToken.WithPrependedLeadingTrivia(annotatedNewline); var rootToFormat = document.Root.ReplaceToken(closingToken, newClosingToken); annotatedNewline = rootToFormat.GetAnnotatedTrivia(s_closingBraceNewlineAnnotation).Single(); diff --git a/src/Features/CSharpTest/Diagnostics/Suppression/SuppressionTests.cs b/src/Features/CSharpTest/Diagnostics/Suppression/SuppressionTests.cs index e49fb03985192..c8663e1a0f825 100644 --- a/src/Features/CSharpTest/Diagnostics/Suppression/SuppressionTests.cs +++ b/src/Features/CSharpTest/Diagnostics/Suppression/SuppressionTests.cs @@ -457,7 +457,7 @@ void Method() diagnosticService, SpecializedCollections.EmptyEnumerable>(), SpecializedCollections.EmptyEnumerable>(), - SpecializedCollections.SingletonEnumerable(suppressionProviderFactory)); + [suppressionProviderFactory]); var document = GetDocumentAndSelectSpan(workspace, out var span); var diagnostics = await diagnosticService.GetDiagnosticsForSpanAsync(document, span, CancellationToken.None); Assert.Equal(2, diagnostics.Where(d => d.Id == "CS0219").Count()); diff --git a/src/Features/CSharpTest/ExtractClass/ExtractClassTests.cs b/src/Features/CSharpTest/ExtractClass/ExtractClassTests.cs index dcbb359753ee7..38825daa3ee98 100644 --- a/src/Features/CSharpTest/ExtractClass/ExtractClassTests.cs +++ b/src/Features/CSharpTest/ExtractClass/ExtractClassTests.cs @@ -45,7 +45,7 @@ protected override IEnumerable GetCodeRefactoringProvid FileName = FileName }; - return SpecializedCollections.SingletonEnumerable(new CSharpExtractClassCodeRefactoringProvider(service)); + return [new CSharpExtractClassCodeRefactoringProvider(service)]; } protected override Task CreateWorkspaceImplAsync() diff --git a/src/Features/Core/Portable/Workspace/MiscellaneousFileUtilities.cs b/src/Features/Core/Portable/Workspace/MiscellaneousFileUtilities.cs index dab7ec7322399..a675497c8f77c 100644 --- a/src/Features/Core/Portable/Workspace/MiscellaneousFileUtilities.cs +++ b/src/Features/Core/Portable/Workspace/MiscellaneousFileUtilities.cs @@ -71,7 +71,7 @@ internal static ProjectInfo CreateMiscellaneousProjectInfoForDocument( hasAllInformation: sourceCodeKind == SourceCodeKind.Script), compilationOptions: compilationOptions, parseOptions: parseOptions, - documents: SpecializedCollections.SingletonEnumerable(documentInfo), + documents: [documentInfo], metadataReferences: metadataReferences); return projectInfo; From 0e6c150fcbcf7d7c729d76fc9bb4f763c191c6ab Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:19:16 -0700 Subject: [PATCH 21/57] use collection expr --- .../AbstractCurlyBraceOrBracketCompletionService.cs | 2 +- .../Portable/BraceCompletion/BracketBraceCompletionService.cs | 2 +- .../Portable/BraceCompletion/CurlyBraceCompletionService.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Features/CSharp/Portable/BraceCompletion/AbstractCurlyBraceOrBracketCompletionService.cs b/src/Features/CSharp/Portable/BraceCompletion/AbstractCurlyBraceOrBracketCompletionService.cs index 31318ba8b70fd..415c50da62bb5 100644 --- a/src/Features/CSharp/Portable/BraceCompletion/AbstractCurlyBraceOrBracketCompletionService.cs +++ b/src/Features/CSharp/Portable/BraceCompletion/AbstractCurlyBraceOrBracketCompletionService.cs @@ -245,7 +245,7 @@ static ImmutableArray GetMergedChanges(TextChange? newLineEdit, Immu var annotatedRoot = GetSyntaxRootWithAnnotatedClosingBrace(document.Root, closingPoint); var result = Formatter.GetFormattingResult( - annotatedRoot, SpecializedCollections.SingletonEnumerable(spanToFormat), document.SolutionServices, options.FormattingOptions, rules, cancellationToken); + annotatedRoot, [spanToFormat], document.SolutionServices, options.FormattingOptions, rules, cancellationToken); if (result == null) { diff --git a/src/Features/CSharp/Portable/BraceCompletion/BracketBraceCompletionService.cs b/src/Features/CSharp/Portable/BraceCompletion/BracketBraceCompletionService.cs index 35e12b8a3042d..db36243d8bd22 100644 --- a/src/Features/CSharp/Portable/BraceCompletion/BracketBraceCompletionService.cs +++ b/src/Features/CSharp/Portable/BraceCompletion/BracketBraceCompletionService.cs @@ -74,7 +74,7 @@ public override void AddAlignTokensOperations(List list, S // For list patterns we format brackets as though they are a block, so ensure the close bracket // is aligned with the open bracket AddAlignIndentationOfTokensToBaseTokenOperation(list, node, bracketPair.openBracket, - SpecializedCollections.SingletonEnumerable(bracketPair.closeBracket), AlignTokensOption.AlignIndentationOfTokensToFirstTokenOfBaseTokenLine); + [bracketPair.closeBracket], AlignTokensOption.AlignIndentationOfTokensToFirstTokenOfBaseTokenLine); } } } diff --git a/src/Features/CSharp/Portable/BraceCompletion/CurlyBraceCompletionService.cs b/src/Features/CSharp/Portable/BraceCompletion/CurlyBraceCompletionService.cs index 6551e0b13d9bd..98ab13f19a3f9 100644 --- a/src/Features/CSharp/Portable/BraceCompletion/CurlyBraceCompletionService.cs +++ b/src/Features/CSharp/Portable/BraceCompletion/CurlyBraceCompletionService.cs @@ -260,7 +260,7 @@ public override void AddAlignTokensOperations(List list, S // If the user has set block style indentation and we're in a valid brace pair // then make sure we align the close brace to the open brace. AddAlignIndentationOfTokensToBaseTokenOperation(list, node, bracePair.openBrace, - SpecializedCollections.SingletonEnumerable(bracePair.closeBrace), AlignTokensOption.AlignIndentationOfTokensToFirstTokenOfBaseTokenLine); + [bracePair.closeBrace], AlignTokensOption.AlignIndentationOfTokensToFirstTokenOfBaseTokenLine); } } } From 8efbd4f62c8f81962c29f908aad7aac5cf181e20 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:19:38 -0700 Subject: [PATCH 22/57] use collection expr --- .../CompletionProviders/NamedParameterCompletionProvider.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Features/CSharp/Portable/Completion/CompletionProviders/NamedParameterCompletionProvider.cs b/src/Features/CSharp/Portable/Completion/CompletionProviders/NamedParameterCompletionProvider.cs index 77f957b583757..baa51b17bc688 100644 --- a/src/Features/CSharp/Portable/Completion/CompletionProviders/NamedParameterCompletionProvider.cs +++ b/src/Features/CSharp/Portable/Completion/CompletionProviders/NamedParameterCompletionProvider.cs @@ -265,8 +265,7 @@ private static ISet GetExistingNamedParameters(BaseArgumentListSyntax ar } else if (expressionType.IsDelegateType()) { - var delegateType = expressionType; - return SpecializedCollections.SingletonEnumerable(delegateType.DelegateInvokeMethod!.Parameters); + return [expressionType.DelegateInvokeMethod!.Parameters]; } } From 2205cc3d85c84cb740f11e859b9c5b3c0aa09314 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:19:54 -0700 Subject: [PATCH 23/57] use collection expr --- .../CSharpConvertForEachToForCodeRefactoringProvider.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Features/CSharp/Portable/ConvertForEachToFor/CSharpConvertForEachToForCodeRefactoringProvider.cs b/src/Features/CSharp/Portable/ConvertForEachToFor/CSharpConvertForEachToForCodeRefactoringProvider.cs index a6f7e8c9a272d..8b9bed742f338 100644 --- a/src/Features/CSharp/Portable/ConvertForEachToFor/CSharpConvertForEachToForCodeRefactoringProvider.cs +++ b/src/Features/CSharp/Portable/ConvertForEachToFor/CSharpConvertForEachToForCodeRefactoringProvider.cs @@ -144,7 +144,7 @@ private StatementSyntax GetForLoopBody( return bodyBlock.InsertNodesBefore( bodyBlock.Statements[0], - SpecializedCollections.SingletonEnumerable(variableStatement)); + [variableStatement]); } } From 30c77565dba485d5575217339ec03f9983b19252 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:20:21 -0700 Subject: [PATCH 24/57] use collection expr --- .../Portable/DecompiledSource/CSharpDecompiledSourceService.cs | 2 +- src/Features/CSharp/Portable/EditAndContinue/BreakpointSpans.cs | 2 +- .../EditAndContinue/DeclarationBody/CSharpLambdaBody.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Features/CSharp/Portable/DecompiledSource/CSharpDecompiledSourceService.cs b/src/Features/CSharp/Portable/DecompiledSource/CSharpDecompiledSourceService.cs index 9ecb17847e198..6b4a2e9bd14db 100644 --- a/src/Features/CSharp/Portable/DecompiledSource/CSharpDecompiledSourceService.cs +++ b/src/Features/CSharp/Portable/DecompiledSource/CSharpDecompiledSourceService.cs @@ -61,7 +61,7 @@ public static async Task FormatDocumentAsync(Document document, Syntax // Apply formatting rules var formattedDoc = await Formatter.FormatAsync( document, - SpecializedCollections.SingletonEnumerable(node.FullSpan), + [node.FullSpan], options, CSharpDecompiledSourceFormattingRule.Instance.Concat(Formatter.GetDefaultFormattingRules(document)), cancellationToken).ConfigureAwait(false); diff --git a/src/Features/CSharp/Portable/EditAndContinue/BreakpointSpans.cs b/src/Features/CSharp/Portable/EditAndContinue/BreakpointSpans.cs index 1b92ad61e2447..b00b9fabf2d77 100644 --- a/src/Features/CSharp/Portable/EditAndContinue/BreakpointSpans.cs +++ b/src/Features/CSharp/Portable/EditAndContinue/BreakpointSpans.cs @@ -472,7 +472,7 @@ internal static TextSpan CreateSpanForImplicitConstructorInitializer(Constructor => CreateSpan(constructor.Modifiers, constructor.Identifier, constructor.ParameterList.CloseParenToken); internal static IEnumerable GetActiveTokensForImplicitConstructorInitializer(ConstructorDeclarationSyntax constructor) - => constructor.Modifiers.Concat(SpecializedCollections.SingletonEnumerable(constructor.Identifier)).Concat(constructor.ParameterList.DescendantTokens()); + => constructor.Modifiers.Concat([constructor.Identifier]).Concat(constructor.ParameterList.DescendantTokens()); internal static TextSpan CreateSpanForExplicitConstructorInitializer(ConstructorInitializerSyntax constructorInitializer) => CreateSpan(constructorInitializer.ThisOrBaseKeyword, constructorInitializer.ArgumentList.CloseParenToken); diff --git a/src/Features/CSharp/Portable/EditAndContinue/DeclarationBody/CSharpLambdaBody.cs b/src/Features/CSharp/Portable/EditAndContinue/DeclarationBody/CSharpLambdaBody.cs index 9b8377c27cd4d..a08875d79f112 100644 --- a/src/Features/CSharp/Portable/EditAndContinue/DeclarationBody/CSharpLambdaBody.cs +++ b/src/Features/CSharp/Portable/EditAndContinue/DeclarationBody/CSharpLambdaBody.cs @@ -55,7 +55,7 @@ public override bool TryMatchActiveStatement(DeclarationBody newBody, SyntaxNode => LambdaUtilities.TryGetCorrespondingLambdaBody(node, newLambda) is { } newNode ? new CSharpLambdaBody(newNode) : null; public override IEnumerable GetExpressionsAndStatements() - => SpecializedCollections.SingletonEnumerable(node); + => [node]; public override SyntaxNode GetLambda() => LambdaUtilities.GetLambda(node); From 8c81f6efe9fe673ce71eafa9ac0d4ff96649f9b2 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:30:42 -0700 Subject: [PATCH 25/57] use collection expr --- .../CSharpMethodExtractor.CSharpCodeGenerator.cs | 4 ++-- .../CSharp/Portable/ExtractMethod/CSharpMethodExtractor.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.CSharpCodeGenerator.cs b/src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.CSharpCodeGenerator.cs index eeee5ca192274..0e54600c081c6 100644 --- a/src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.CSharpCodeGenerator.cs +++ b/src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.CSharpCodeGenerator.cs @@ -673,14 +673,14 @@ private static TDeclarationNode TweakNewLinesInMethod(TDeclara return method.ReplaceToken( body.OpenBraceToken, body.OpenBraceToken.WithAppendedTrailingTrivia( - SpecializedCollections.SingletonEnumerable(SyntaxFactory.ElasticCarriageReturnLineFeed))); + SyntaxFactory.ElasticCarriageReturnLineFeed)); } else if (expressionBody != null) { return method.ReplaceToken( expressionBody.ArrowToken, expressionBody.ArrowToken.WithPrependedLeadingTrivia( - SpecializedCollections.SingletonEnumerable(SyntaxFactory.ElasticCarriageReturnLineFeed))); + SyntaxFactory.ElasticCarriageReturnLineFeed)); } else { diff --git a/src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.cs b/src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.cs index 0db1910e9e56d..3c7586b532fca 100644 --- a/src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.cs +++ b/src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.cs @@ -181,12 +181,12 @@ protected override SyntaxNode ParseTypeName(string name) { var originalMethodDefinition = methodDefinition; var newLine = Options.LineFormattingOptions.NewLine; - methodDefinition = methodDefinition.WithPrependedLeadingTrivia(SpecializedCollections.SingletonEnumerable(SyntaxFactory.EndOfLine(newLine))); + methodDefinition = methodDefinition.WithPrependedLeadingTrivia(SyntaxFactory.EndOfLine(newLine)); if (!originalMethodDefinition.FindTokenOnLeftOfPosition(originalMethodDefinition.SpanStart).TrailingTrivia.Any(SyntaxKind.EndOfLineTrivia)) { // Add a second new line since there were no line endings in the original form - methodDefinition = methodDefinition.WithPrependedLeadingTrivia(SpecializedCollections.SingletonEnumerable(SyntaxFactory.EndOfLine(newLine))); + methodDefinition = methodDefinition.WithPrependedLeadingTrivia(SyntaxFactory.EndOfLine(newLine)); } // Generating the new document and associated variables. From 964b07c5b13ae82ce6d3122bf8fcc5eebfc6e22b Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:31:15 -0700 Subject: [PATCH 26/57] use collection expr --- .../ExtractMethod/CSharpMethodExtractor.TriviaResult.cs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.TriviaResult.cs b/src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.TriviaResult.cs index c476422c16404..1408b5122f9d0 100644 --- a/src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.TriviaResult.cs +++ b/src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.TriviaResult.cs @@ -102,9 +102,7 @@ private IEnumerable TriviaResolver( if (tokenPair.PreviousToken == body.OpenBraceToken && tokenPair.NextToken == body.CloseBraceToken) { - return (location == TriviaLocation.AfterBeginningOfSpan) - ? SpecializedCollections.SingletonEnumerable(SyntaxFactory.ElasticMarker) - : []; + return location == TriviaLocation.AfterBeginningOfSpan ? [SyntaxFactory.ElasticMarker] : []; } } else @@ -112,9 +110,7 @@ private IEnumerable TriviaResolver( if (tokenPair.PreviousToken == expressionBody.ArrowToken && tokenPair.NextToken.GetPreviousToken() == semicolonToken) { - return (location == TriviaLocation.AfterBeginningOfSpan) - ? SpecializedCollections.SingletonEnumerable(SyntaxFactory.ElasticMarker) - : []; + return location == TriviaLocation.AfterBeginningOfSpan ? [SyntaxFactory.ElasticMarker] : []; } } From 4a81e6ce5a0a7d023a46c92aa5ea9f00c34158db Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:31:37 -0700 Subject: [PATCH 27/57] use collection expr --- .../ImplementInterface/CSharpImplementInterfaceService.cs | 2 +- .../AbstractOrdinaryMethodSignatureHelpProvider.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Features/CSharp/Portable/ImplementInterface/CSharpImplementInterfaceService.cs b/src/Features/CSharp/Portable/ImplementInterface/CSharpImplementInterfaceService.cs index 2bb6df09a4620..5e8e826c29438 100644 --- a/src/Features/CSharp/Portable/ImplementInterface/CSharpImplementInterfaceService.cs +++ b/src/Features/CSharp/Portable/ImplementInterface/CSharpImplementInterfaceService.cs @@ -59,7 +59,7 @@ SyntaxKind.RecordDeclaration or { classOrStructDecl = interfaceNode.Parent.Parent.Parent as TypeDeclarationSyntax; classOrStructType = model.GetDeclaredSymbol(classOrStructDecl, cancellationToken) as INamedTypeSymbol; - interfaceTypes = SpecializedCollections.SingletonEnumerable(interfaceType); + interfaceTypes = [interfaceType]; return interfaceTypes != null && classOrStructType != null; } diff --git a/src/Features/CSharp/Portable/SignatureHelp/AbstractOrdinaryMethodSignatureHelpProvider.cs b/src/Features/CSharp/Portable/SignatureHelp/AbstractOrdinaryMethodSignatureHelpProvider.cs index e1ac88896801d..3149432cb7d3e 100644 --- a/src/Features/CSharp/Portable/SignatureHelp/AbstractOrdinaryMethodSignatureHelpProvider.cs +++ b/src/Features/CSharp/Portable/SignatureHelp/AbstractOrdinaryMethodSignatureHelpProvider.cs @@ -86,5 +86,5 @@ private static IList GetMethodGroupPreambleParts( } private static IList GetMethodGroupPostambleParts() - => SpecializedCollections.SingletonList(Punctuation(SyntaxKind.CloseParenToken)); + => [Punctuation(SyntaxKind.CloseParenToken)]; } From 61782b6eaf38c99addefd5bf571275e209ae6502 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:32:25 -0700 Subject: [PATCH 28/57] use collection expr --- .../SignatureHelp/AttributeSignatureHelpProvider.cs | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/Features/CSharp/Portable/SignatureHelp/AttributeSignatureHelpProvider.cs b/src/Features/CSharp/Portable/SignatureHelp/AttributeSignatureHelpProvider.cs index ceac2f1a40932..cbae266b5700f 100644 --- a/src/Features/CSharp/Portable/SignatureHelp/AttributeSignatureHelpProvider.cs +++ b/src/Features/CSharp/Portable/SignatureHelp/AttributeSignatureHelpProvider.cs @@ -217,17 +217,9 @@ private static IList GetPreambleParts( SemanticModel semanticModel, int position) { - var result = new List(); - - result.AddRange(method.ContainingType.ToMinimalDisplayParts(semanticModel, position)); - result.Add(Punctuation(SyntaxKind.OpenParenToken)); - - return result; + return [.. method.ContainingType.ToMinimalDisplayParts(semanticModel, position), Punctuation(SyntaxKind.OpenParenToken)]; } private static IList GetPostambleParts() - { - return SpecializedCollections.SingletonList( - Punctuation(SyntaxKind.CloseParenToken)); - } + => [Punctuation(SyntaxKind.CloseParenToken)]; } From 3c2320f7199ec2ea7d9f2a1914651194a402549a Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:33:08 -0700 Subject: [PATCH 29/57] use collection expr --- .../ConstructorInitializerSignatureHelpProvider.cs | 12 ++---------- .../ElementAccessExpressionSignatureHelpProvider.cs | 5 +---- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/src/Features/CSharp/Portable/SignatureHelp/ConstructorInitializerSignatureHelpProvider.cs b/src/Features/CSharp/Portable/SignatureHelp/ConstructorInitializerSignatureHelpProvider.cs index 6e3da4f3cb31c..db1b912ad47e0 100644 --- a/src/Features/CSharp/Portable/SignatureHelp/ConstructorInitializerSignatureHelpProvider.cs +++ b/src/Features/CSharp/Portable/SignatureHelp/ConstructorInitializerSignatureHelpProvider.cs @@ -155,17 +155,9 @@ private static IList GetPreambleParts( SemanticModel semanticModel, int position) { - var result = new List(); - - result.AddRange(method.ContainingType.ToMinimalDisplayParts(semanticModel, position)); - result.Add(Punctuation(SyntaxKind.OpenParenToken)); - - return result; + return [.. method.ContainingType.ToMinimalDisplayParts(semanticModel, position), Punctuation(SyntaxKind.OpenParenToken)]; } private static IList GetPostambleParts() - { - return SpecializedCollections.SingletonList( - Punctuation(SyntaxKind.CloseParenToken)); - } + => [Punctuation(SyntaxKind.CloseParenToken)]; } diff --git a/src/Features/CSharp/Portable/SignatureHelp/ElementAccessExpressionSignatureHelpProvider.cs b/src/Features/CSharp/Portable/SignatureHelp/ElementAccessExpressionSignatureHelpProvider.cs index 9bfd87398bf72..273a01b267485 100644 --- a/src/Features/CSharp/Portable/SignatureHelp/ElementAccessExpressionSignatureHelpProvider.cs +++ b/src/Features/CSharp/Portable/SignatureHelp/ElementAccessExpressionSignatureHelpProvider.cs @@ -276,10 +276,7 @@ private static IList GetPreambleParts( } private static IList GetPostambleParts() - { - return SpecializedCollections.SingletonList( - Punctuation(SyntaxKind.CloseBracketToken)); - } + => [Punctuation(SyntaxKind.CloseBracketToken)]; private static class CompleteElementAccessExpression { From e96968abe5c222454b4029a37db2ece9abe2a3a2 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:33:53 -0700 Subject: [PATCH 30/57] use collection expr --- .../GenericNameSignatureHelpProvider_NamedType.cs | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/Features/CSharp/Portable/SignatureHelp/GenericNameSignatureHelpProvider_NamedType.cs b/src/Features/CSharp/Portable/SignatureHelp/GenericNameSignatureHelpProvider_NamedType.cs index 95db63b5b30c9..1ad90f6cc2134 100644 --- a/src/Features/CSharp/Portable/SignatureHelp/GenericNameSignatureHelpProvider_NamedType.cs +++ b/src/Features/CSharp/Portable/SignatureHelp/GenericNameSignatureHelpProvider_NamedType.cs @@ -14,17 +14,9 @@ private static IList GetPreambleParts( SemanticModel semanticModel, int position) { - var result = new List(); - - result.AddRange(namedType.ToMinimalDisplayParts(semanticModel, position, MinimallyQualifiedWithoutTypeParametersFormat)); - result.Add(Punctuation(SyntaxKind.LessThanToken)); - - return result; + return [.. namedType.ToMinimalDisplayParts(semanticModel, position, MinimallyQualifiedWithoutTypeParametersFormat), Punctuation(SyntaxKind.LessThanToken)]; } private static IList GetPostambleParts() - { - return SpecializedCollections.SingletonList( - Punctuation(SyntaxKind.GreaterThanToken)); - } + => [Punctuation(SyntaxKind.GreaterThanToken)]; } From 73174828d8b0c2c1f504341ecb0f0114c1be628b Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:34:15 -0700 Subject: [PATCH 31/57] use collection expr --- ...ureHelpProviderBase_DelegateAndFunctionPointerInvoke.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Features/CSharp/Portable/SignatureHelp/InvocationExpressionSignatureHelpProviderBase_DelegateAndFunctionPointerInvoke.cs b/src/Features/CSharp/Portable/SignatureHelp/InvocationExpressionSignatureHelpProviderBase_DelegateAndFunctionPointerInvoke.cs index faef82d3e0eb4..07a9c809660fc 100644 --- a/src/Features/CSharp/Portable/SignatureHelp/InvocationExpressionSignatureHelpProviderBase_DelegateAndFunctionPointerInvoke.cs +++ b/src/Features/CSharp/Portable/SignatureHelp/InvocationExpressionSignatureHelpProviderBase_DelegateAndFunctionPointerInvoke.cs @@ -53,7 +53,7 @@ private static IList GetDelegateOrFunctionPointerInvokeItems( // Since we're returning a single item, we can selected it as the "best one". selectedItem = 0; - return SpecializedCollections.SingletonList(item); + return [item]; } private static IList GetDelegateOrFunctionPointerInvokePreambleParts(IMethodSymbol invokeMethod, SemanticModel semanticModel, int position) @@ -96,8 +96,5 @@ private static IList GetDelegateOrFunctionPointerI } private static IList GetDelegateOrFunctionPointerInvokePostambleParts() - { - return SpecializedCollections.SingletonList( - Punctuation(SyntaxKind.CloseParenToken)); - } + => [Punctuation(SyntaxKind.CloseParenToken)]; } From 0d49c33fb845c5c0ae3b7ec55bc04ac9c62cee94 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:34:58 -0700 Subject: [PATCH 32/57] use collection expr --- ...pressionSignatureHelpProvider_DelegateType.cs | 16 ++++++---------- ...ExpressionSignatureHelpProvider_NormalType.cs | 5 +---- ...ryConstructorBaseTypeSignatureHelpProvider.cs | 4 +--- 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/src/Features/CSharp/Portable/SignatureHelp/ObjectCreationExpressionSignatureHelpProvider_DelegateType.cs b/src/Features/CSharp/Portable/SignatureHelp/ObjectCreationExpressionSignatureHelpProvider_DelegateType.cs index 8edc55b68a139..c2a05bd5c24ea 100644 --- a/src/Features/CSharp/Portable/SignatureHelp/ObjectCreationExpressionSignatureHelpProvider_DelegateType.cs +++ b/src/Features/CSharp/Portable/SignatureHelp/ObjectCreationExpressionSignatureHelpProvider_DelegateType.cs @@ -70,17 +70,13 @@ private static IList GetDelegateTypeParameters(IMe parts.Add(Space()); parts.Add(new SymbolDisplayPart(SymbolDisplayPartKind.ParameterName, null, TargetName)); - return SpecializedCollections.SingletonList( - new SignatureHelpSymbolParameter( - TargetName, - isOptional: false, - documentationFactory: null, - displayParts: parts)); + return [new SignatureHelpSymbolParameter( + TargetName, + isOptional: false, + documentationFactory: null, + displayParts: parts)]; } private static IList GetDelegateTypePostambleParts() - { - return SpecializedCollections.SingletonList( - Punctuation(SyntaxKind.CloseParenToken)); - } + => [Punctuation(SyntaxKind.CloseParenToken)]; } diff --git a/src/Features/CSharp/Portable/SignatureHelp/ObjectCreationExpressionSignatureHelpProvider_NormalType.cs b/src/Features/CSharp/Portable/SignatureHelp/ObjectCreationExpressionSignatureHelpProvider_NormalType.cs index a966e3ea8ac79..69f3fb51b7bfe 100644 --- a/src/Features/CSharp/Portable/SignatureHelp/ObjectCreationExpressionSignatureHelpProvider_NormalType.cs +++ b/src/Features/CSharp/Portable/SignatureHelp/ObjectCreationExpressionSignatureHelpProvider_NormalType.cs @@ -51,8 +51,5 @@ private static IList GetNormalTypePreambleParts( } private static IList GetNormalTypePostambleParts() - { - return SpecializedCollections.SingletonList( - Punctuation(SyntaxKind.CloseParenToken)); - } + => [Punctuation(SyntaxKind.CloseParenToken)]; } diff --git a/src/Features/CSharp/Portable/SignatureHelp/PrimaryConstructorBaseTypeSignatureHelpProvider.cs b/src/Features/CSharp/Portable/SignatureHelp/PrimaryConstructorBaseTypeSignatureHelpProvider.cs index 906b176d878c7..d12404451b2f2 100644 --- a/src/Features/CSharp/Portable/SignatureHelp/PrimaryConstructorBaseTypeSignatureHelpProvider.cs +++ b/src/Features/CSharp/Portable/SignatureHelp/PrimaryConstructorBaseTypeSignatureHelpProvider.cs @@ -151,8 +151,6 @@ static IList GetPreambleParts( } static IList GetPostambleParts() - { - return SpecializedCollections.SingletonList(Punctuation(SyntaxKind.CloseParenToken)); - } + => [Punctuation(SyntaxKind.CloseParenToken)]; } } From 990b6489cbf7167c2f5cb931aba9faceb7210ce6 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:36:02 -0700 Subject: [PATCH 33/57] use collection expr --- .../Diagnostics/AbstractSuppressionAllCodeTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Features/DiagnosticsTestUtilities/Diagnostics/AbstractSuppressionAllCodeTests.cs b/src/Features/DiagnosticsTestUtilities/Diagnostics/AbstractSuppressionAllCodeTests.cs index a606dbdd9fbe8..84304048a6662 100644 --- a/src/Features/DiagnosticsTestUtilities/Diagnostics/AbstractSuppressionAllCodeTests.cs +++ b/src/Features/DiagnosticsTestUtilities/Diagnostics/AbstractSuppressionAllCodeTests.cs @@ -88,7 +88,7 @@ protected async Task TestPragmaOrAttributeAsync( continue; } - var fixes = fixer.GetFixesAsync(document, diagnostic.Location.SourceSpan, SpecializedCollections.SingletonEnumerable(diagnostic), CodeActionOptions.DefaultProvider, CancellationToken.None).GetAwaiter().GetResult(); + var fixes = fixer.GetFixesAsync(document, diagnostic.Location.SourceSpan, [diagnostic], CodeActionOptions.DefaultProvider, CancellationToken.None).GetAwaiter().GetResult(); if (fixes == null || fixes.Count() <= 0) { continue; From 54488ecd0c1ee2f34ccf230a06c531211dc361f7 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:36:50 -0700 Subject: [PATCH 34/57] use collection expr --- .../Diagnostics/AbstractUserDiagnosticTest_NoEditor.cs | 2 +- .../Testing/TestDiscoverer.cs | 2 +- .../EngineV2/DiagnosticIncrementalAnalyzer.StateSet.cs | 2 +- .../EngineV2/DiagnosticIncrementalAnalyzer_GetDiagnostics.cs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Features/DiagnosticsTestUtilities/Diagnostics/AbstractUserDiagnosticTest_NoEditor.cs b/src/Features/DiagnosticsTestUtilities/Diagnostics/AbstractUserDiagnosticTest_NoEditor.cs index 8248844d15a95..d19e283a4238c 100644 --- a/src/Features/DiagnosticsTestUtilities/Diagnostics/AbstractUserDiagnosticTest_NoEditor.cs +++ b/src/Features/DiagnosticsTestUtilities/Diagnostics/AbstractUserDiagnosticTest_NoEditor.cs @@ -216,7 +216,7 @@ private static FixAllState GetFixAllState( if (scope == FixAllScope.Custom) { // Bulk fixing diagnostics in selected scope. - var diagnosticsToFix = ImmutableDictionary.CreateRange(SpecializedCollections.SingletonEnumerable(KeyValuePairUtil.Create(document, diagnostics.ToImmutableArray()))); + var diagnosticsToFix = ImmutableDictionary.CreateRange([KeyValuePairUtil.Create(document, diagnostics.ToImmutableArray())]); return FixAllState.Create(fixAllProvider, diagnosticsToFix, fixer, equivalenceKey, optionsProvider); } diff --git a/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/Testing/TestDiscoverer.cs b/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/Testing/TestDiscoverer.cs index 62bfe8514d51c..8ecd99cba7114 100644 --- a/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/Testing/TestDiscoverer.cs +++ b/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/Testing/TestDiscoverer.cs @@ -57,7 +57,7 @@ public async Task> DiscoverTestsAsync( var stopwatch = SharedStopwatch.StartNew(); // The async APIs for vs test are broken (current impl ends up just hanging), so we must use the sync API instead. - var discoveryTask = Task.Run(() => vsTestConsoleWrapper.DiscoverTests(SpecializedCollections.SingletonEnumerable(projectOutputPath), discoverySettings: runSettings, discoveryHandler), cancellationToken); + var discoveryTask = Task.Run(() => vsTestConsoleWrapper.DiscoverTests([projectOutputPath], discoverySettings: runSettings, discoveryHandler), cancellationToken); cancellationToken.Register(() => vsTestConsoleWrapper.CancelDiscovery()); await discoveryTask; diff --git a/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.StateSet.cs b/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.StateSet.cs index 1d14029d88371..9a2f24933bc04 100644 --- a/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.StateSet.cs +++ b/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.StateSet.cs @@ -51,7 +51,7 @@ public IEnumerable GetProjectsWithDiagnostics() return []; // we do have diagnostics - return SpecializedCollections.SingletonEnumerable(documentId.ProjectId); + return [documentId.ProjectId]; } return new HashSet( diff --git a/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_GetDiagnostics.cs b/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_GetDiagnostics.cs index e90818da57dd1..cb1dc8c68d0b9 100644 --- a/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_GetDiagnostics.cs +++ b/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_GetDiagnostics.cs @@ -79,7 +79,7 @@ public async Task> GetDiagnosticsAsync(Cancellati return GetDiagnosticData(); } - var documentIds = (DocumentId != null) ? SpecializedCollections.SingletonEnumerable(DocumentId) : project.DocumentIds; + var documentIds = DocumentId != null ? [DocumentId] : project.DocumentIds; // return diagnostics specific to one project or document var includeProjectNonLocalResult = DocumentId == null; From 96730eb93ada114303f122663d9487630fd3551e Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:37:17 -0700 Subject: [PATCH 35/57] use collection expr --- .../Handler/Formatting/AbstractFormatDocumentHandlerBase.cs | 2 +- .../DidChangeConfigurationNotificationHandlerTest.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Features/LanguageServer/Protocol/Handler/Formatting/AbstractFormatDocumentHandlerBase.cs b/src/Features/LanguageServer/Protocol/Handler/Formatting/AbstractFormatDocumentHandlerBase.cs index d91d1c14d3732..806e79597b426 100644 --- a/src/Features/LanguageServer/Protocol/Handler/Formatting/AbstractFormatDocumentHandlerBase.cs +++ b/src/Features/LanguageServer/Protocol/Handler/Formatting/AbstractFormatDocumentHandlerBase.cs @@ -42,7 +42,7 @@ internal abstract class AbstractFormatDocumentHandlerBase(); edits.AddRange(textChanges.Select(change => ProtocolConversions.TextChangeToTextEdit(change, text))); diff --git a/src/Features/LanguageServer/ProtocolUnitTests/Configuration/DidChangeConfigurationNotificationHandlerTest.cs b/src/Features/LanguageServer/ProtocolUnitTests/Configuration/DidChangeConfigurationNotificationHandlerTest.cs index 5baca59a8dffb..728291fc02f5c 100644 --- a/src/Features/LanguageServer/ProtocolUnitTests/Configuration/DidChangeConfigurationNotificationHandlerTest.cs +++ b/src/Features/LanguageServer/ProtocolUnitTests/Configuration/DidChangeConfigurationNotificationHandlerTest.cs @@ -157,7 +157,7 @@ private static void VerifyValuesInServer(EditorTestWorkspace workspace, List option is IPerLanguageValuedOption ? 2 : 1), expectedValues.Count); var optionsAndLanguageToVerify = supportedOptions.SelectManyAsArray(option => option is IPerLanguageValuedOption ? DidChangeConfigurationNotificationHandler.SupportedLanguages.SelectAsArray(lang => (option, lang)) - : SpecializedCollections.SingletonEnumerable((option, string.Empty))); + : [(option, string.Empty)]); for (var i = 0; i < expectedValues.Count; i++) { From 89cd3ed77ef6f03355bd9e675740432f1b79ca2e Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:37:32 -0700 Subject: [PATCH 36/57] use collection expr --- src/Features/Lsif/Generator/Graph/Edge.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Features/Lsif/Generator/Graph/Edge.cs b/src/Features/Lsif/Generator/Graph/Edge.cs index 57d05b9ad1caa..1a10b36ecf2dd 100644 --- a/src/Features/Lsif/Generator/Graph/Edge.cs +++ b/src/Features/Lsif/Generator/Graph/Edge.cs @@ -25,7 +25,7 @@ internal class Edge : Element [JsonProperty("inVs", NullValueHandling = NullValueHandling.Ignore)] public Id[]? InVertices { get; } - public IEnumerable> GetInVerticies() => InVertices ?? SpecializedCollections.SingletonEnumerable(InVertex!.Value); + public IEnumerable> GetInVerticies() => InVertices ?? [InVertex!.Value]; public Edge(string label, Id outVertex, Id inVertex, IdFactory idFactory) : base(type: "edge", label: label, idFactory) From d011c76c36616dd38b568d72d354796b85494946 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:37:56 -0700 Subject: [PATCH 37/57] use collection expr --- .../Core/Def/CallHierarchy/CallHierarchyProvider.cs | 2 +- .../Core/Def/CodeLens/RemoteCodeLensReferencesService.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/VisualStudio/Core/Def/CallHierarchy/CallHierarchyProvider.cs b/src/VisualStudio/Core/Def/CallHierarchy/CallHierarchyProvider.cs index d9887f9c4ff35..0be27dc93912f 100644 --- a/src/VisualStudio/Core/Def/CallHierarchy/CallHierarchyProvider.cs +++ b/src/VisualStudio/Core/Def/CallHierarchy/CallHierarchyProvider.cs @@ -144,7 +144,7 @@ SymbolKind.Event or if (symbol.Kind == SymbolKind.Field) { - return SpecializedCollections.SingletonEnumerable(new FieldReferenceFinder(symbol, project.Id, AsyncListener, this)); + return [new FieldReferenceFinder(symbol, project.Id, AsyncListener, this)]; } return null; diff --git a/src/VisualStudio/Core/Def/CodeLens/RemoteCodeLensReferencesService.cs b/src/VisualStudio/Core/Def/CodeLens/RemoteCodeLensReferencesService.cs index 3f95f78763006..333a63a045f85 100644 --- a/src/VisualStudio/Core/Def/CodeLens/RemoteCodeLensReferencesService.cs +++ b/src/VisualStudio/Core/Def/CodeLens/RemoteCodeLensReferencesService.cs @@ -160,7 +160,7 @@ private async Task> FixUpDescriptors } var span = new TextSpan(descriptor.SpanStart, descriptor.SpanLength); - var results = await spanMapper.MapSpansAsync(document, SpecializedCollections.SingletonEnumerable(span), cancellationToken).ConfigureAwait(false); + var results = await spanMapper.MapSpansAsync(document, [span], cancellationToken).ConfigureAwait(false); // external component violated contracts. the mapper should preserve input order/count. // since we gave in 1 span, it should return 1 span back From 219b4e4600833e76f3b5588d760b7e96bcfea199 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:38:51 -0700 Subject: [PATCH 38/57] use collection expr --- .../Def/FindReferences/Entries/AbstractDocumentSpanEntry.cs | 2 +- .../AbstractLanguageService`2.IVsLanguageTextOps.cs | 2 +- .../Core/Def/ProjectSystem/VisualStudioWorkspaceImpl.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/VisualStudio/Core/Def/FindReferences/Entries/AbstractDocumentSpanEntry.cs b/src/VisualStudio/Core/Def/FindReferences/Entries/AbstractDocumentSpanEntry.cs index a9a35ae3f98d8..09c5bfd66e9d7 100644 --- a/src/VisualStudio/Core/Def/FindReferences/Entries/AbstractDocumentSpanEntry.cs +++ b/src/VisualStudio/Core/Def/FindReferences/Entries/AbstractDocumentSpanEntry.cs @@ -81,7 +81,7 @@ await documentNavigationService.TryNavigateToSpanAsync( } var results = await service.MapSpansAsync( - documentSpan.Document, SpecializedCollections.SingletonEnumerable(documentSpan.SourceSpan), cancellationToken).ConfigureAwait(false); + documentSpan.Document, [documentSpan.SourceSpan], cancellationToken).ConfigureAwait(false); if (results.IsDefaultOrEmpty) { diff --git a/src/VisualStudio/Core/Def/LanguageService/AbstractLanguageService`2.IVsLanguageTextOps.cs b/src/VisualStudio/Core/Def/LanguageService/AbstractLanguageService`2.IVsLanguageTextOps.cs index c77fb462cebe8..e097e22eeee74 100644 --- a/src/VisualStudio/Core/Def/LanguageService/AbstractLanguageService`2.IVsLanguageTextOps.cs +++ b/src/VisualStudio/Core/Def/LanguageService/AbstractLanguageService`2.IVsLanguageTextOps.cs @@ -70,7 +70,7 @@ private int FormatWorker(IVsTextLayer textLayer, TextSpan[] selections, Cancella // use formatting that return text changes rather than tree rewrite which is more expensive var formatter = document.GetRequiredLanguageService(); - var originalChanges = formatter.GetFormattingResult(root, SpecializedCollections.SingletonEnumerable(adjustedSpan), formattingOptions, rules, cancellationToken) + var originalChanges = formatter.GetFormattingResult(root, [adjustedSpan], formattingOptions, rules, cancellationToken) .GetTextChanges(cancellationToken); var originalSpan = RoslynTextSpan.FromBounds(start, end); diff --git a/src/VisualStudio/Core/Def/ProjectSystem/VisualStudioWorkspaceImpl.cs b/src/VisualStudio/Core/Def/ProjectSystem/VisualStudioWorkspaceImpl.cs index 554f0864b6dec..6eeae1a960122 100644 --- a/src/VisualStudio/Core/Def/ProjectSystem/VisualStudioWorkspaceImpl.cs +++ b/src/VisualStudio/Core/Def/ProjectSystem/VisualStudioWorkspaceImpl.cs @@ -787,7 +787,7 @@ private void AddDocumentCore(DocumentInfo info, SourceText initialText, TextDocu if (IsWebsite(project)) { - AddDocumentToFolder(project, info.Id, SpecializedCollections.SingletonEnumerable(AppCodeFolderName), info.Name, documentKind, initialText, info.FilePath); + AddDocumentToFolder(project, info.Id, [AppCodeFolderName], info.Name, documentKind, initialText, info.FilePath); } else if (folders.Any()) { From 1a929ebe4b0e31eda682f6f958788e987b3f866b Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:39:18 -0700 Subject: [PATCH 39/57] use collection expr --- .../Core/Def/Workspace/VisualStudioDocumentNavigationService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/VisualStudio/Core/Def/Workspace/VisualStudioDocumentNavigationService.cs b/src/VisualStudio/Core/Def/Workspace/VisualStudioDocumentNavigationService.cs index a403eb5bb9b69..cf4694301ceee 100644 --- a/src/VisualStudio/Core/Def/Workspace/VisualStudioDocumentNavigationService.cs +++ b/src/VisualStudio/Core/Def/Workspace/VisualStudioDocumentNavigationService.cs @@ -313,7 +313,7 @@ async static Task OpenDocumentAsync( ISpanMappingService spanMappingService, Document generatedDocument, TextSpan textSpan, CancellationToken cancellationToken) { var results = await spanMappingService.MapSpansAsync( - generatedDocument, SpecializedCollections.SingletonEnumerable(textSpan), cancellationToken).ConfigureAwait(false); + generatedDocument, [textSpan], cancellationToken).ConfigureAwait(false); if (!results.IsDefaultOrEmpty) { From 72c99d5bf58289c3cf06dc497ad52453cf58093f Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:40:21 -0700 Subject: [PATCH 40/57] use collection expr --- .../Core/Impl/CodeModel/Collections/BasesCollection.cs | 2 +- src/Workspaces/Core/Portable/CodeActions/CodeAction.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/VisualStudio/Core/Impl/CodeModel/Collections/BasesCollection.cs b/src/VisualStudio/Core/Impl/CodeModel/Collections/BasesCollection.cs index 956967a64650b..1f9c1865cc642 100644 --- a/src/VisualStudio/Core/Impl/CodeModel/Collections/BasesCollection.cs +++ b/src/VisualStudio/Core/Impl/CodeModel/Collections/BasesCollection.cs @@ -80,7 +80,7 @@ private IEnumerable GetBaseTypes() } else { - return SpecializedCollections.SingletonEnumerable(symbol.BaseType); + return [symbol.BaseType]; } } diff --git a/src/Workspaces/Core/Portable/CodeActions/CodeAction.cs b/src/Workspaces/Core/Portable/CodeActions/CodeAction.cs index 360bc91b95a4a..28a3af953bf7f 100644 --- a/src/Workspaces/Core/Portable/CodeActions/CodeAction.cs +++ b/src/Workspaces/Core/Portable/CodeActions/CodeAction.cs @@ -284,7 +284,7 @@ protected virtual async Task> ComputeOperations var changedSolution = await GetChangedSolutionAsync(CodeAnalysisProgress.None, cancellationToken).ConfigureAwait(false); return changedSolution == null ? [] - : SpecializedCollections.SingletonEnumerable(new ApplyChangesOperation(changedSolution)); + : [new ApplyChangesOperation(changedSolution)]; } #pragma warning disable RS0030 // Do not use banned APIs From 089586709eef77c035c5ee37f5992bbe9c5392d4 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:40:41 -0700 Subject: [PATCH 41/57] use collection expr --- .../Portable/CodeRefactorings/FixAllOccurences/FixAllState.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Workspaces/Core/Portable/CodeRefactorings/FixAllOccurences/FixAllState.cs b/src/Workspaces/Core/Portable/CodeRefactorings/FixAllOccurences/FixAllState.cs index eb9a523195ec9..f587f2af918d6 100644 --- a/src/Workspaces/Core/Portable/CodeRefactorings/FixAllOccurences/FixAllState.cs +++ b/src/Workspaces/Core/Portable/CodeRefactorings/FixAllOccurences/FixAllState.cs @@ -110,7 +110,7 @@ internal async Task Date: Fri, 5 Apr 2024 17:41:13 -0700 Subject: [PATCH 42/57] use collection expr --- src/Workspaces/Core/Portable/Editing/ImportAdder.cs | 2 +- src/Workspaces/Core/Portable/Formatting/Formatter.cs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Workspaces/Core/Portable/Editing/ImportAdder.cs b/src/Workspaces/Core/Portable/Editing/ImportAdder.cs index fce9cd2e5a8ae..c7c09b3f4a6da 100644 --- a/src/Workspaces/Core/Portable/Editing/ImportAdder.cs +++ b/src/Workspaces/Core/Portable/Editing/ImportAdder.cs @@ -20,7 +20,7 @@ public static class ImportAdder private static async ValueTask> GetSpansAsync(Document document, CancellationToken cancellationToken) { var root = await document.GetRequiredSyntaxRootAsync(cancellationToken).ConfigureAwait(false); - return SpecializedCollections.SingletonEnumerable(root.FullSpan); + return [root.FullSpan]; } private static async ValueTask> GetSpansAsync(Document document, SyntaxAnnotation annotation, CancellationToken cancellationToken) diff --git a/src/Workspaces/Core/Portable/Formatting/Formatter.cs b/src/Workspaces/Core/Portable/Formatting/Formatter.cs index 77ce8d64b870a..7c179f84329db 100644 --- a/src/Workspaces/Core/Portable/Formatting/Formatter.cs +++ b/src/Workspaces/Core/Portable/Formatting/Formatter.cs @@ -64,11 +64,11 @@ internal static Task FormatAsync(Document document, SyntaxFormattingOp /// The formatted document. public static Task FormatAsync(Document document, TextSpan span, OptionSet? options = null, CancellationToken cancellationToken = default) #pragma warning disable RS0030 // Do not used banned APIs - => FormatAsync(document, SpecializedCollections.SingletonEnumerable(span), options, cancellationToken); + => FormatAsync(document, [span], options, cancellationToken); #pragma warning restore internal static Task FormatAsync(Document document, TextSpan span, SyntaxFormattingOptions options, CancellationToken cancellationToken) - => FormatAsync(document, SpecializedCollections.SingletonEnumerable(span), options, rules: null, cancellationToken); + => FormatAsync(document, [span], options, rules: null, cancellationToken); /// /// Formats the whitespace in areas of a document corresponding to multiple non-overlapping spans. @@ -187,10 +187,10 @@ internal static SyntaxNode Format(SyntaxNode node, SyntaxAnnotation annotation, /// An optional cancellation token. /// The formatted tree's root node. public static SyntaxNode Format(SyntaxNode node, Workspace workspace, OptionSet? options = null, CancellationToken cancellationToken = default) - => Format(node, SpecializedCollections.SingletonEnumerable(node.FullSpan), workspace, options, rules: null, cancellationToken); + => Format(node, [node.FullSpan], workspace, options, rules: null, cancellationToken); internal static SyntaxNode Format(SyntaxNode node, SolutionServices services, SyntaxFormattingOptions options, CancellationToken cancellationToken) - => Format(node, SpecializedCollections.SingletonEnumerable(node.FullSpan), services, options, rules: null, cancellationToken); + => Format(node, [node.FullSpan], services, options, rules: null, cancellationToken); /// /// Formats the whitespace in areas of a syntax tree identified by a span. From 495611f9cd1cad29a548a28f460a5f9d75ae6a8c Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:42:42 -0700 Subject: [PATCH 43/57] use collection expr --- .../Core/Portable/Formatting/Formatter.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Workspaces/Core/Portable/Formatting/Formatter.cs b/src/Workspaces/Core/Portable/Formatting/Formatter.cs index 7c179f84329db..6803e4697a6df 100644 --- a/src/Workspaces/Core/Portable/Formatting/Formatter.cs +++ b/src/Workspaces/Core/Portable/Formatting/Formatter.cs @@ -202,10 +202,10 @@ internal static SyntaxNode Format(SyntaxNode node, SolutionServices services, Sy /// An optional cancellation token. /// The formatted tree's root node. public static SyntaxNode Format(SyntaxNode node, TextSpan span, Workspace workspace, OptionSet? options = null, CancellationToken cancellationToken = default) - => Format(node, SpecializedCollections.SingletonEnumerable(span), workspace, options, rules: null, cancellationToken: cancellationToken); + => Format(node, [span], workspace, options, rules: null, cancellationToken: cancellationToken); internal static SyntaxNode Format(SyntaxNode node, TextSpan span, SolutionServices services, SyntaxFormattingOptions options, CancellationToken cancellationToken) - => Format(node, SpecializedCollections.SingletonEnumerable(span), services, options, rules: null, cancellationToken: cancellationToken); + => Format(node, [span], services, options, rules: null, cancellationToken: cancellationToken); /// /// Formats the whitespace in areas of a syntax tree identified by multiple non-overlapping spans. @@ -247,7 +247,7 @@ internal static SyntaxNode Format(SyntaxNode node, IEnumerable? spans, return null; } - spans ??= SpecializedCollections.SingletonEnumerable(node.FullSpan); + spans ??= [node.FullSpan]; var formattingOptions = GetFormattingOptions(workspace, options, node.Language); return languageFormatter.GetFormattingResult(node, spans, formattingOptions, rules, cancellationToken); } @@ -267,10 +267,10 @@ internal static IFormattingResult GetFormattingResult(SyntaxNode node, IEnumerab /// An optional cancellation token. /// The changes necessary to format the tree. public static IList GetFormattedTextChanges(SyntaxNode node, Workspace workspace, OptionSet? options = null, CancellationToken cancellationToken = default) - => GetFormattedTextChanges(node, SpecializedCollections.SingletonEnumerable(node.FullSpan), workspace, options, rules: null, cancellationToken: cancellationToken); + => GetFormattedTextChanges(node, [node.FullSpan], workspace, options, rules: null, cancellationToken: cancellationToken); internal static IList GetFormattedTextChanges(SyntaxNode node, SolutionServices services, SyntaxFormattingOptions options, CancellationToken cancellationToken) - => GetFormattedTextChanges(node, SpecializedCollections.SingletonEnumerable(node.FullSpan), services, options, rules: null, cancellationToken: cancellationToken); + => GetFormattedTextChanges(node, [node.FullSpan], services, options, rules: null, cancellationToken: cancellationToken); /// /// Determines the changes necessary to format the whitespace of a syntax tree. @@ -282,10 +282,10 @@ internal static IList GetFormattedTextChanges(SyntaxNode node, Solut /// An optional cancellation token. /// The changes necessary to format the tree. public static IList GetFormattedTextChanges(SyntaxNode node, TextSpan span, Workspace workspace, OptionSet? options = null, CancellationToken cancellationToken = default) - => GetFormattedTextChanges(node, SpecializedCollections.SingletonEnumerable(span), workspace, options, rules: null, cancellationToken); + => GetFormattedTextChanges(node, [span], workspace, options, rules: null, cancellationToken); internal static IList GetFormattedTextChanges(SyntaxNode node, TextSpan span, SolutionServices services, SyntaxFormattingOptions options, CancellationToken cancellationToken = default) - => GetFormattedTextChanges(node, SpecializedCollections.SingletonEnumerable(span), services, options, rules: null, cancellationToken); + => GetFormattedTextChanges(node, [span], services, options, rules: null, cancellationToken); /// /// Determines the changes necessary to format the whitespace of a syntax tree. From 538a13db097093b9608d3ccc572e3898c2a6548c Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:43:49 -0700 Subject: [PATCH 44/57] use collection expr --- .../AbstractFixAllSpanMappingService.cs | 6 ++---- src/Workspaces/Core/Portable/Rename/TokenRenameInfo.cs | 2 +- .../Shared/Extensions/IFindReferencesResultExtensions.cs | 2 +- .../Portable/Shared/Extensions/SyntaxGeneratorExtensions.cs | 4 +--- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/Workspaces/Core/Portable/LanguageServices/FixAllSpanMappingService/AbstractFixAllSpanMappingService.cs b/src/Workspaces/Core/Portable/LanguageServices/FixAllSpanMappingService/AbstractFixAllSpanMappingService.cs index 402e8c5dd9526..570016ae58692 100644 --- a/src/Workspaces/Core/Portable/LanguageServices/FixAllSpanMappingService/AbstractFixAllSpanMappingService.cs +++ b/src/Workspaces/Core/Portable/LanguageServices/FixAllSpanMappingService/AbstractFixAllSpanMappingService.cs @@ -37,8 +37,7 @@ private async Task>> GetF if (fixAllInContainingMember) { - return ImmutableDictionary.CreateRange(SpecializedCollections.SingletonEnumerable( - KeyValuePairUtil.Create(document, ImmutableArray.Create(decl.FullSpan)))); + return ImmutableDictionary.CreateRange([KeyValuePairUtil.Create(document, ImmutableArray.Create(decl.FullSpan))]); } else { @@ -64,8 +63,7 @@ private async Task>> GetF } else { - return ImmutableDictionary.CreateRange(SpecializedCollections.SingletonEnumerable( - KeyValuePairUtil.Create(document, ImmutableArray.Create(decl.FullSpan)))); + return ImmutableDictionary.CreateRange([KeyValuePairUtil.Create(document, ImmutableArray.Create(decl.FullSpan))]); } } } diff --git a/src/Workspaces/Core/Portable/Rename/TokenRenameInfo.cs b/src/Workspaces/Core/Portable/Rename/TokenRenameInfo.cs index 8c3a375c9f1fc..378a54d1a679a 100644 --- a/src/Workspaces/Core/Portable/Rename/TokenRenameInfo.cs +++ b/src/Workspaces/Core/Portable/Rename/TokenRenameInfo.cs @@ -29,7 +29,7 @@ public static TokenRenameInfo CreateSingleSymbolTokenInfo(ISymbol symbol) ( hasSymbols: true, isMemberGroup: false, - symbols: SpecializedCollections.SingletonEnumerable(symbol) + symbols: [symbol] ); } diff --git a/src/Workspaces/Core/Portable/Shared/Extensions/IFindReferencesResultExtensions.cs b/src/Workspaces/Core/Portable/Shared/Extensions/IFindReferencesResultExtensions.cs index 1865d376c4268..0fd2e6819501a 100644 --- a/src/Workspaces/Core/Portable/Shared/Extensions/IFindReferencesResultExtensions.cs +++ b/src/Workspaces/Core/Portable/Shared/Extensions/IFindReferencesResultExtensions.cs @@ -20,7 +20,7 @@ public static IEnumerable GetDefinitionLocationsToShow( this ISymbol definition) { return definition.IsKind(SymbolKind.Namespace) - ? SpecializedCollections.SingletonEnumerable(definition.Locations.First()) + ? [definition.Locations.First()] : definition.Locations; } diff --git a/src/Workspaces/Core/Portable/Shared/Extensions/SyntaxGeneratorExtensions.cs b/src/Workspaces/Core/Portable/Shared/Extensions/SyntaxGeneratorExtensions.cs index bdb16d4351df7..b415cbcbe9421 100644 --- a/src/Workspaces/Core/Portable/Shared/Extensions/SyntaxGeneratorExtensions.cs +++ b/src/Workspaces/Core/Portable/Shared/Extensions/SyntaxGeneratorExtensions.cs @@ -191,9 +191,7 @@ public static SyntaxNode CreateNullCheckAndThrowStatement( var throwStatement = factory.CreateThrowArgumentNullExceptionStatement(semanticModel.Compilation, parameter); // generates: if (s is null) { throw new ArgumentNullException(nameof(s)); } - return factory.IfStatement( - condition, - SpecializedCollections.SingletonEnumerable(throwStatement)); + return factory.IfStatement(condition, [throwStatement]); } public static SyntaxNode CreateThrowArgumentNullExceptionStatement(this SyntaxGenerator factory, Compilation compilation, IParameterSymbol parameter) From 9bed21c0843421df1bb2aeb1cab383a3e36dcd5f Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:43:59 -0700 Subject: [PATCH 45/57] use collection expr --- src/Workspaces/Core/Portable/Simplification/Simplifier.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Workspaces/Core/Portable/Simplification/Simplifier.cs b/src/Workspaces/Core/Portable/Simplification/Simplifier.cs index b6011d041fb00..be5b44f48f8b2 100644 --- a/src/Workspaces/Core/Portable/Simplification/Simplifier.cs +++ b/src/Workspaces/Core/Portable/Simplification/Simplifier.cs @@ -208,12 +208,12 @@ public static Task ReduceAsync(Document document, TextSpan span, Optio } #pragma warning disable RS0030 // Do not used banned APIs - return ReduceAsync(document, SpecializedCollections.SingletonEnumerable(span), optionSet, cancellationToken); + return ReduceAsync(document, [span], optionSet, cancellationToken); } #pragma warning restore internal static Task ReduceAsync(Document document, TextSpan span, SimplifierOptions options, CancellationToken cancellationToken) - => ReduceAsync(document, SpecializedCollections.SingletonEnumerable(span), options, cancellationToken); + => ReduceAsync(document, [span], options, cancellationToken); /// /// Reduce the sub-trees annotated with found within the specified spans. From 458e8bed02c15a8eb84f5539e93cb211e840daf9 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:45:22 -0700 Subject: [PATCH 46/57] use collection expr --- .../GenericNameSignatureHelpProvider_NamedType.cs | 1 - .../ProjectSystemProject.BatchingDocumentCollection.cs | 2 +- .../Core/Portable/Workspace/Solution/Solution.cs | 9 +++------ 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/Features/CSharp/Portable/SignatureHelp/GenericNameSignatureHelpProvider_NamedType.cs b/src/Features/CSharp/Portable/SignatureHelp/GenericNameSignatureHelpProvider_NamedType.cs index 1ad90f6cc2134..d3546f93092f4 100644 --- a/src/Features/CSharp/Portable/SignatureHelp/GenericNameSignatureHelpProvider_NamedType.cs +++ b/src/Features/CSharp/Portable/SignatureHelp/GenericNameSignatureHelpProvider_NamedType.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System.Collections.Generic; -using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.CSharp.SignatureHelp; diff --git a/src/Workspaces/Core/Portable/Workspace/ProjectSystem/ProjectSystemProject.BatchingDocumentCollection.cs b/src/Workspaces/Core/Portable/Workspace/ProjectSystem/ProjectSystemProject.BatchingDocumentCollection.cs index 929d5f854e0ae..04ba30d41afd4 100644 --- a/src/Workspaces/Core/Portable/Workspace/ProjectSystem/ProjectSystemProject.BatchingDocumentCollection.cs +++ b/src/Workspaces/Core/Portable/Workspace/ProjectSystem/ProjectSystemProject.BatchingDocumentCollection.cs @@ -425,7 +425,7 @@ await _project._projectSystemProjectFactory.ApplyBatchChangeToWorkspaceAsync(sol solutionChanges.UpdateSolutionForDocumentAction( _documentTextLoaderChangedAction(solutionChanges.Solution, documentId, textLoader), _documentChangedWorkspaceKind, - SpecializedCollections.SingletonEnumerable(documentId)); + [documentId]); } } }).ConfigureAwait(false); diff --git a/src/Workspaces/Core/Portable/Workspace/Solution/Solution.cs b/src/Workspaces/Core/Portable/Workspace/Solution/Solution.cs index 776a667fc0f65..101ebc241a08e 100644 --- a/src/Workspaces/Core/Portable/Workspace/Solution/Solution.cs +++ b/src/Workspaces/Core/Portable/Workspace/Solution/Solution.cs @@ -535,8 +535,7 @@ public Solution WithProjectDocumentsOrder(ProjectId projectId, ImmutableList @@ -627,8 +626,7 @@ public Solution WithProjectReferences(ProjectId projectId, IEnumerable @@ -708,8 +706,7 @@ public Solution WithProjectMetadataReferences(ProjectId projectId, IEnumerable From 4196ca53d5184c6917771e6d9f99f4d6db8573ff Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:46:02 -0700 Subject: [PATCH 47/57] use collection expr --- .../VirtualChars/CSharpVirtualCharServiceTests.cs | 2 +- .../CSharpTest/Formatting/CSharpFormattingTestBase.cs | 4 ++-- src/Workspaces/Core/Portable/Workspace/Solution/Solution.cs | 3 +-- .../Core/Portable/Workspace/Solution/SolutionState.cs | 3 +-- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Workspaces/CSharpTest/EmbeddedLanguages/VirtualChars/CSharpVirtualCharServiceTests.cs b/src/Workspaces/CSharpTest/EmbeddedLanguages/VirtualChars/CSharpVirtualCharServiceTests.cs index 14658ef41a415..997cc864868ec 100644 --- a/src/Workspaces/CSharpTest/EmbeddedLanguages/VirtualChars/CSharpVirtualCharServiceTests.cs +++ b/src/Workspaces/CSharpTest/EmbeddedLanguages/VirtualChars/CSharpVirtualCharServiceTests.cs @@ -29,7 +29,7 @@ public class CSharpVirtualCharServiceTests if (expression is LiteralExpressionSyntax literal) { - return SpecializedCollections.SingletonEnumerable(literal.Token); + return [literal.Token]; } else if (expression is InterpolatedStringExpressionSyntax interpolation) { diff --git a/src/Workspaces/CSharpTest/Formatting/CSharpFormattingTestBase.cs b/src/Workspaces/CSharpTest/Formatting/CSharpFormattingTestBase.cs index 26639254771cd..80a275a4a52f7 100644 --- a/src/Workspaces/CSharpTest/Formatting/CSharpFormattingTestBase.cs +++ b/src/Workspaces/CSharpTest/Formatting/CSharpFormattingTestBase.cs @@ -30,7 +30,7 @@ private protected Task AssertNoFormattingChangesAsync( bool testWithTransformation = true, ParseOptions parseOptions = null) { - return AssertFormatAsync(code, code, SpecializedCollections.SingletonEnumerable(new TextSpan(0, code.Length)), debugMode, changedOptionSet, testWithTransformation, parseOptions); + return AssertFormatAsync(code, code, [new TextSpan(0, code.Length)], debugMode, changedOptionSet, testWithTransformation, parseOptions); } private protected Task AssertFormatAsync( @@ -41,7 +41,7 @@ private protected Task AssertFormatAsync( bool testWithTransformation = true, ParseOptions parseOptions = null) { - return AssertFormatAsync(expected, code, SpecializedCollections.SingletonEnumerable(new TextSpan(0, code.Length)), debugMode, changedOptionSet, testWithTransformation, parseOptions); + return AssertFormatAsync(expected, code, [new TextSpan(0, code.Length)], debugMode, changedOptionSet, testWithTransformation, parseOptions); } private protected Task AssertFormatAsync( diff --git a/src/Workspaces/Core/Portable/Workspace/Solution/Solution.cs b/src/Workspaces/Core/Portable/Workspace/Solution/Solution.cs index 101ebc241a08e..468b90b7090f9 100644 --- a/src/Workspaces/Core/Portable/Workspace/Solution/Solution.cs +++ b/src/Workspaces/Core/Portable/Workspace/Solution/Solution.cs @@ -788,8 +788,7 @@ public Solution WithProjectAnalyzerReferences(ProjectId projectId, IEnumerable diff --git a/src/Workspaces/Core/Portable/Workspace/Solution/SolutionState.cs b/src/Workspaces/Core/Portable/Workspace/Solution/SolutionState.cs index e8edb8f0569cd..33d860e218213 100644 --- a/src/Workspaces/Core/Portable/Workspace/Solution/SolutionState.cs +++ b/src/Workspaces/Core/Portable/Workspace/Solution/SolutionState.cs @@ -311,8 +311,7 @@ private SolutionState AddProject(ProjectState projectState) if (projectReference.ProjectId == projectId) { newDependencyGraph = newDependencyGraph.WithAdditionalProjectReferences( - newState.Key, - SpecializedCollections.SingletonReadOnlyList(projectReference)); + newState.Key, [projectReference]); break; } From 06ba49a02d76ee8e8888d99423fb618778e0c454 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:47:30 -0700 Subject: [PATCH 48/57] use collection expr --- .../Formatting/CSharpSyntaxFormattingService.cs | 4 ++-- .../Rename/CSharpRenameRewriterLanguageService.cs | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Workspaces/CSharp/Portable/Formatting/CSharpSyntaxFormattingService.cs b/src/Workspaces/CSharp/Portable/Formatting/CSharpSyntaxFormattingService.cs index 8d1e1979279e4..c45a418d8c073 100644 --- a/src/Workspaces/CSharp/Portable/Formatting/CSharpSyntaxFormattingService.cs +++ b/src/Workspaces/CSharp/Portable/Formatting/CSharpSyntaxFormattingService.cs @@ -282,7 +282,7 @@ private static IEnumerable GetTypingRules(SyntaxToken to return []; } - return SpecializedCollections.SingletonEnumerable(TypingFormattingRule.Instance); + return [TypingFormattingRule.Instance]; } private static bool IsEndToken(SyntaxToken endToken) @@ -331,7 +331,7 @@ public ImmutableArray GetFormattingChangesOnPaste(ParsedDocument doc var rules = new List() { new PasteFormattingRule() }; rules.AddRange(service.GetDefaultFormattingRules()); - var result = service.GetFormattingResult(document.Root, SpecializedCollections.SingletonEnumerable(formattingSpan), options, rules, cancellationToken); + var result = service.GetFormattingResult(document.Root, [formattingSpan], options, rules, cancellationToken); return result.GetTextChanges(cancellationToken).ToImmutableArray(); } diff --git a/src/Workspaces/CSharp/Portable/Rename/CSharpRenameRewriterLanguageService.cs b/src/Workspaces/CSharp/Portable/Rename/CSharpRenameRewriterLanguageService.cs index d863a5e46e193..c3b3bdfc853cd 100644 --- a/src/Workspaces/CSharp/Portable/Rename/CSharpRenameRewriterLanguageService.cs +++ b/src/Workspaces/CSharp/Portable/Rename/CSharpRenameRewriterLanguageService.cs @@ -478,15 +478,15 @@ private async Task RenameAndAnnotateAsync(SyntaxToken token, Syntax } else { - symbols = SpecializedCollections.SingletonEnumerable(symbolInfo.Symbol); + symbols = [symbolInfo.Symbol]; } var renameDeclarationLocations = - ConflictResolver.CreateDeclarationLocationAnnotationsAsync( - _solution, - symbols, - _cancellationToken) - .WaitAndGetResult_CanCallOnBackground(_cancellationToken); + ConflictResolver.CreateDeclarationLocationAnnotationsAsync( + _solution, + symbols, + _cancellationToken) + .WaitAndGetResult_CanCallOnBackground(_cancellationToken); var renameAnnotation = new RenameActionAnnotation( identifierToken.Span, @@ -810,7 +810,7 @@ public override async Task> ComputeDeclarationConflicts if (renamedSymbol.ContainingSymbol is INamedTypeSymbol { TypeKind: not TypeKind.Enum } containingNamedType && containingNamedType.Name == renamedSymbol.Name) { - AddSymbolSourceSpans(conflicts, SpecializedCollections.SingletonEnumerable(containingNamedType), reverseMappedLocations); + AddSymbolSourceSpans(conflicts, [containingNamedType], reverseMappedLocations); } if (renamedSymbol.Kind is SymbolKind.Parameter or From ef22741238962ebf5aaa1ac33ae6d8dfdaeb0b5c Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:47:59 -0700 Subject: [PATCH 49/57] use collection expr --- .../Core/LanguageServices/AddImports/IAddImportsService.cs | 2 +- .../AbstractTypeInferenceService.AbstractTypeInferrer.cs | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/LanguageServices/AddImports/IAddImportsService.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/LanguageServices/AddImports/IAddImportsService.cs index 73dd939ef2389..9de5f16f87215 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/LanguageServices/AddImports/IAddImportsService.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/LanguageServices/AddImports/IAddImportsService.cs @@ -47,6 +47,6 @@ public static SyntaxNode AddImport( CancellationToken cancellationToken) { return service.AddImports(compilation, root, contextLocation, - SpecializedCollections.SingletonEnumerable(newImport), generator, options, cancellationToken); + [newImport], generator, options, cancellationToken); } } diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/LanguageServices/TypeInferenceService/AbstractTypeInferenceService.AbstractTypeInferrer.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/LanguageServices/TypeInferenceService/AbstractTypeInferenceService.AbstractTypeInferrer.cs index a0663b98835ea..5edc8d00e79e4 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/LanguageServices/TypeInferenceService/AbstractTypeInferenceService.AbstractTypeInferrer.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/LanguageServices/TypeInferenceService/AbstractTypeInferenceService.AbstractTypeInferrer.cs @@ -84,9 +84,7 @@ protected IEnumerable CreateResult(SpecialType type, Nullable => CreateResult(Compilation.GetSpecialType(type).WithNullableAnnotation(nullableAnnotation)); protected static IEnumerable CreateResult(ITypeSymbol type) - => type == null - ? SpecializedCollections.EmptyCollection() - : SpecializedCollections.SingletonEnumerable(new TypeInferenceInfo(type)); + => type == null ? [] : [new TypeInferenceInfo(type)]; protected static IEnumerable ExpandParamsParameter(IParameterSymbol parameterSymbol) { From 5e2cfcbe53578ce6d2b121e315ca2ea77d64d148 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:48:10 -0700 Subject: [PATCH 50/57] use collection expr --- .../AbstractTypeInferenceService.AbstractTypeInferrer.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/LanguageServices/TypeInferenceService/AbstractTypeInferenceService.AbstractTypeInferrer.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/LanguageServices/TypeInferenceService/AbstractTypeInferenceService.AbstractTypeInferrer.cs index 5edc8d00e79e4..4dc1aa16c05c2 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/LanguageServices/TypeInferenceService/AbstractTypeInferenceService.AbstractTypeInferrer.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/LanguageServices/TypeInferenceService/AbstractTypeInferenceService.AbstractTypeInferrer.cs @@ -112,9 +112,7 @@ protected static IEnumerable GetCollectionElementType(INamedT var elementType = parameters.ElementAtOrDefault(0); if (elementType != null) - { - return SpecializedCollections.SingletonCollection(new TypeInferenceInfo(elementType)); - } + return [new TypeInferenceInfo(elementType)]; } return []; From 380a52ad6550d78039338c1f408ad69b0340a3bf Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:48:36 -0700 Subject: [PATCH 51/57] use collection expr --- .../CSharpTypeInferenceService.TypeInferrer.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/LanguageServices/CSharpTypeInferenceService.TypeInferrer.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/LanguageServices/CSharpTypeInferenceService.TypeInferrer.cs index d9327ee6b5fe4..a0fc54ca52c32 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/LanguageServices/CSharpTypeInferenceService.TypeInferrer.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/LanguageServices/CSharpTypeInferenceService.TypeInferrer.cs @@ -114,9 +114,7 @@ private IEnumerable GetTypesSimple(SyntaxNode node) } if (IsUsableTypeFunc(typeInferenceInfo)) - { - return SpecializedCollections.SingletonEnumerable(typeInferenceInfo); - } + return [typeInferenceInfo]; } } @@ -1609,8 +1607,7 @@ private IEnumerable InferTypeInAnonymousFunctionExpression(An if (invoke != null) { var isAsync = anonymousFunction.AsyncKeyword.Kind() != SyntaxKind.None; - return SpecializedCollections.SingletonEnumerable( - new TypeInferenceInfo(UnwrapTaskLike(invoke.ReturnType, isAsync))); + return [new TypeInferenceInfo(UnwrapTaskLike(invoke.ReturnType, isAsync))]; } } From ad9ec29f484f4bd6b586b2e31529f540dfb35b20 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:49:08 -0700 Subject: [PATCH 52/57] use collection expr --- .../CSharpTypeInferenceService.TypeInferrer.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/LanguageServices/CSharpTypeInferenceService.TypeInferrer.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/LanguageServices/CSharpTypeInferenceService.TypeInferrer.cs index a0fc54ca52c32..a44bd6b9e8deb 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/LanguageServices/CSharpTypeInferenceService.TypeInferrer.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/LanguageServices/CSharpTypeInferenceService.TypeInferrer.cs @@ -1976,7 +1976,7 @@ private IEnumerable InferTypeInYieldStatement(YieldStatementS // We don't care what the type is, as long as it has 1 type argument. This will work for IEnumerable, IEnumerator, // IAsyncEnumerable, IAsyncEnumerator and it's also good for error recovery in case there is a missing using. return memberType is INamedTypeSymbol namedType && namedType.TypeArguments.Length == 1 - ? SpecializedCollections.SingletonEnumerable(new TypeInferenceInfo(namedType.TypeArguments[0])) + ? [new TypeInferenceInfo(namedType.TypeArguments[0])] : []; } @@ -2028,7 +2028,7 @@ private IEnumerable InferTypeInMethodLikeDeclaration(SyntaxNo var isAsync = symbol is IMethodSymbol methodSymbol && methodSymbol.IsAsync; return type != null - ? SpecializedCollections.SingletonEnumerable(new TypeInferenceInfo(UnwrapTaskLike(type, isAsync))) + ? [new TypeInferenceInfo(UnwrapTaskLike(type, isAsync))] : []; } @@ -2239,8 +2239,8 @@ declExpr.Designation is ParenthesizedVariableDesignationSyntax parenthesizedVari return inferredFutureUsage.Length > 0 ? inferredFutureUsage[0].InferredType : Compilation.ObjectType; }); - return SpecializedCollections.SingletonEnumerable(new TypeInferenceInfo( - Compilation.CreateTupleTypeSymbol(elementTypes, elementNames))); + return [new TypeInferenceInfo( + Compilation.CreateTupleTypeSymbol(elementTypes, elementNames))]; } return GetTypes(declExpr.Type); @@ -2355,7 +2355,7 @@ private IEnumerable InferTypeInWhenClause(WhenClauseSyntax wh if (previousToken.HasValue && previousToken.Value != whenClause.WhenKeyword) return []; - return SpecializedCollections.SingletonEnumerable(new TypeInferenceInfo(Compilation.GetSpecialType(SpecialType.System_Boolean))); + return [new TypeInferenceInfo(Compilation.GetSpecialType(SpecialType.System_Boolean))]; } private IEnumerable InferTypeInWhileStatement(WhileStatementSyntax whileStatement, SyntaxToken? previousToken = null) From c0de600dcfb05a4ca504385ae0fb8914dc0e07dc Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:50:05 -0700 Subject: [PATCH 53/57] fix --- src/Workspaces/Core/Portable/Workspace/Solution/Solution.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Workspaces/Core/Portable/Workspace/Solution/Solution.cs b/src/Workspaces/Core/Portable/Workspace/Solution/Solution.cs index 468b90b7090f9..d02f38d923434 100644 --- a/src/Workspaces/Core/Portable/Workspace/Solution/Solution.cs +++ b/src/Workspaces/Core/Portable/Workspace/Solution/Solution.cs @@ -788,7 +788,7 @@ public Solution WithProjectAnalyzerReferences(ProjectId projectId, IEnumerable From 9c22aab0ecd96b129d862947ddff8d0b8760a7a6 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:54:35 -0700 Subject: [PATCH 54/57] use collection expr --- .../TestUtilities/Threading/WpfFactDiscoverer.cs | 4 ++-- src/Workspaces/CoreTest/CodeCleanup/CodeCleanupTests.cs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/EditorFeatures/TestUtilities/Threading/WpfFactDiscoverer.cs b/src/EditorFeatures/TestUtilities/Threading/WpfFactDiscoverer.cs index dedb5480df120..e5498a5402cba 100644 --- a/src/EditorFeatures/TestUtilities/Threading/WpfFactDiscoverer.cs +++ b/src/EditorFeatures/TestUtilities/Threading/WpfFactDiscoverer.cs @@ -32,13 +32,13 @@ public WpfTheoryDiscoverer(IMessageSink diagnosticMessageSink) : base(diagnostic protected override IEnumerable CreateTestCasesForDataRow(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo theoryAttribute, object[] dataRow) { var testCase = new WpfTestCase(_diagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), discoveryOptions.MethodDisplayOptionsOrDefault(), testMethod, dataRow); - return SpecializedCollections.SingletonEnumerable(testCase); + return [testCase]; } protected override IEnumerable CreateTestCasesForTheory(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo theoryAttribute) { var testCase = new WpfTheoryTestCase(_diagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), discoveryOptions.MethodDisplayOptionsOrDefault(), testMethod); - return SpecializedCollections.SingletonEnumerable(testCase); + return [testCase]; } } } diff --git a/src/Workspaces/CoreTest/CodeCleanup/CodeCleanupTests.cs b/src/Workspaces/CoreTest/CodeCleanup/CodeCleanupTests.cs index 743a62fa403c2..4a7a5b5ecaf18 100644 --- a/src/Workspaces/CoreTest/CodeCleanup/CodeCleanupTests.cs +++ b/src/Workspaces/CoreTest/CodeCleanup/CodeCleanupTests.cs @@ -180,7 +180,7 @@ public void EntireRangeWithTransformation_RemoveClass() var root = await document.GetSyntaxRootAsync(cancellationToken); root = root.RemoveCSharpMember(0); - expectedResult = SpecializedCollections.SingletonEnumerable(root.FullSpan); + expectedResult = [root.FullSpan]; return document.WithSyntaxRoot(root); } @@ -202,7 +202,7 @@ public void EntireRangeWithTransformation_AddMember() var classWithMember = @class.AddCSharpMember(CreateCSharpMethod(), 0); root = root.ReplaceNode(@class, classWithMember); - expectedResult = SpecializedCollections.SingletonEnumerable(root.FullSpan); + expectedResult = [root.FullSpan]; return document.WithSyntaxRoot(root); } @@ -224,7 +224,7 @@ public void RangeWithTransformation_AddMember() var classWithMember = @class.AddCSharpMember(CreateCSharpMethod(), 0); root = root.ReplaceNode(@class, classWithMember); - expectedResult = SpecializedCollections.SingletonEnumerable(root.GetMember(0).GetMember(0).GetCodeCleanupSpan()); + expectedResult = [root.GetMember(0).GetMember(0).GetCodeCleanupSpan()]; return document.WithSyntaxRoot(root); } @@ -246,7 +246,7 @@ public void RangeWithTransformation_RemoveMember() var classWithMember = @class.RemoveCSharpMember(0); root = root.ReplaceNode(@class, classWithMember); - expectedResult = SpecializedCollections.SingletonEnumerable(root.GetMember(0).GetMember(0).GetCodeCleanupSpan()); + expectedResult = [root.GetMember(0).GetMember(0).GetCodeCleanupSpan()]; return document.WithSyntaxRoot(root); } From b6d33c935f4213dbc9c79ba3eae5f3421120fcb8 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:55:12 -0700 Subject: [PATCH 55/57] use collection expr --- .../FixAllOccurrences/FixAllContext.DiagnosticProvider.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Workspaces/Core/Portable/CodeFixes/FixAllOccurrences/FixAllContext.DiagnosticProvider.cs b/src/Workspaces/Core/Portable/CodeFixes/FixAllOccurrences/FixAllContext.DiagnosticProvider.cs index dc9da72490607..2c7b4ed56d743 100644 --- a/src/Workspaces/Core/Portable/CodeFixes/FixAllOccurrences/FixAllContext.DiagnosticProvider.cs +++ b/src/Workspaces/Core/Portable/CodeFixes/FixAllOccurrences/FixAllContext.DiagnosticProvider.cs @@ -78,8 +78,7 @@ internal static async Task>(); From 1c8e45ac074e5d7ed76832d801da6c892a227892 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 17:55:41 -0700 Subject: [PATCH 56/57] use collection expr --- .../ITypeSymbolExtensions.TypeSyntaxGeneratorVisitor.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/Extensions/ITypeSymbolExtensions.TypeSyntaxGeneratorVisitor.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/Extensions/ITypeSymbolExtensions.TypeSyntaxGeneratorVisitor.cs index 9dc82540b27a0..5629bbcf2e7d0 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/Extensions/ITypeSymbolExtensions.TypeSyntaxGeneratorVisitor.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/Extensions/ITypeSymbolExtensions.TypeSyntaxGeneratorVisitor.cs @@ -162,9 +162,9 @@ static FunctionPointerUnmanagedCallingConventionSyntax GetConventionForString(st } var parameters = symbol.Signature.Parameters.Select(p => (p.Type, RefKindModifiers: CSharpSyntaxGeneratorInternal.GetParameterModifiers(p.RefKind))) - .Concat(SpecializedCollections.SingletonEnumerable(( + .Concat([( Type: symbol.Signature.ReturnType, - RefKindModifiers: CSharpSyntaxGeneratorInternal.GetParameterModifiers(symbol.Signature.RefKind, forFunctionPointerReturnParameter: true)))) + RefKindModifiers: CSharpSyntaxGeneratorInternal.GetParameterModifiers(symbol.Signature.RefKind, forFunctionPointerReturnParameter: true))]) .SelectAsArray(t => SyntaxFactory.FunctionPointerParameter(t.Type.GenerateTypeSyntax()).WithModifiers(t.RefKindModifiers)); return AddInformationTo( From 2a1720dfc0cd7161165c35797ecd37a6cde65101 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 5 Apr 2024 19:09:21 -0700 Subject: [PATCH 57/57] Revert --- .../CSharpUpdateExpressionSyntaxHelper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Analyzers/CSharp/Analyzers/UseCollectionInitializer/CSharpUpdateExpressionSyntaxHelper.cs b/src/Analyzers/CSharp/Analyzers/UseCollectionInitializer/CSharpUpdateExpressionSyntaxHelper.cs index 96b629b7390a8..79de454fef8ff 100644 --- a/src/Analyzers/CSharp/Analyzers/UseCollectionInitializer/CSharpUpdateExpressionSyntaxHelper.cs +++ b/src/Analyzers/CSharp/Analyzers/UseCollectionInitializer/CSharpUpdateExpressionSyntaxHelper.cs @@ -40,5 +40,5 @@ public void GetPartsOfIfStatement( } private static IEnumerable ExtractEmbeddedStatements(StatementSyntax embeddedStatement) - => embeddedStatement is BlockSyntax block ? block.Statements : [embeddedStatement]; + => embeddedStatement is BlockSyntax block ? block.Statements : SpecializedCollections.SingletonEnumerable(embeddedStatement); }